CMPT 225 Lecture Notes - Lecture 4: Sorting Algorithm, Insertion Sort, Binary Search Algorithm

51 views2 pages

Document Summary

How performance varies for different input of same size based on organization of the data. May be asked what an array should look like to be best/avg/worst case for an algorithm. Although useful, can be difficult to determine exact num of operations by an algorithm. Is instruction executed most times in an algorithm. Number of times this is executed is usually proportional to the running time of the algorithm. If array isn"t sorted, use linear search (it"s the only way to do it) - start with first item, compare each item to target, if find, return true, else never find, return false. Linear search barometer instruction: equality checking (comparisons) arr[i] == x. Best case: 1, item looking for is first item in array make comparison arr[i] == x once. Worst case: length of the array, or not in the array. Both cases: have to go through entire thing.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents