{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

J 1 subarray 1 but in sorted order but correctness of

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: data – E.g. At the start of each iteration of the “outer” for loop of line 1-8, E.g. 8, the subarray A[1..j-1] consists of the elements originally in A[1..j-1] subarray 1] but in sorted order. but • Correctness of algorithm: – Using loop invariant – Similar to the math induction • Initialization, maintenance, termination maintenance termination NCKU IIM NCKU 資料結構 Chapter 2 資料結構 6 2.2 Analyzing algorithms 2.2 Analyzing an algorithm: Analyzing predicting the resources that the algorithm requires. • Resources: memory, communication, bandwidth, logic memory, gate, time. time • Assumptions: one processor, random-access machine one access RAM (how real computers are designed) (how – Instructions are executed one after another (NO concurrent Instructions operations) operations) – Use common instructions (assume each one takes a constant Us amount of time): Arithmetic (+,-,*,/,mod,floor,ceiling,shift right/left), amount ,*,/,mod,floor,ceiling,shift data movement (load,store,copy), control (if..else,case) data – Uses integer and floating-point types – Never mind precisions – Limit on the word size: inputs of size n, assume integers are Li assume represented by clg n bits (lg n means log2 n) clg NCKU IIM NCKU 資料結構 Chapter 2 資料結構 7 Analyzing Running Time How to analyze an algorithm’s running time? • Time taken by an algorithm depends on the input Time input • The input size...
View Full Document

{[ snackBarMessage ]}