Save
algorithms
lecture 2
Save
Share
Learn
Content
Leaderboard
Learn
Created by
Mohammed
Visit profile
Cards (14)
Iterative algorithms
Expressing algorithms using loops
View source
Tools to reason about iterative algorithms
Loop invariants
Loop control variables
Order-of-growth
("big O")
notation
View source
Total correctness
For all inputs, the algorithm produces the desired result
View source
Partial correctness
If the algorithm terminates, it produces the desired result
View source
Total correctness =
partial correctness
+
termination
View source
Worst-case time analysis ⇒ termination
View source
Loop invariant
A property that holds
before
and
after
each execution of the loop
View source
Steps in using loop
invariants
1. Establish
invariant
before loop
2. Maintain
invariant
in loop body
3. Use invariant after loop
View source
Loop control variable
A variable that is initialized before the
loop
, used in the
loop
condition, and modified in the loop body
View source
Good practice for loop control variables:
View source
Input
size
The aspect of the input that determines the algorithm's
complexity
View source
Fundamental step
The basic operation the algorithm performs, whose number of executions determines the algorithm's complexity
View source
Worst case
The input that gives the maximum number of steps for the algorithm
View source
Order-of-growth notation (
Big-O
)
A simplified view of a
cost function
, restricting attention to the term that grows fastest for large inputs and ignoring
constant
factors
View source