Unformatted text preview: data
– E.g. At the start of each iteration of the “outer” for loop of line 18,
E.g.
8,
the subarray A[1..j1] consists of the elements originally in A[1..j1]
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, randomaccess 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 floatingpoint 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
 Winter '12
 bob
 Analysis of algorithms, LG, Best, worst and average case, NCKU IIM

Click to edit the document details