Binary search is asymptotically better than linear search
Asymptotic Algorithm Analysis
Complexity Analysis: Growth of Functions
31
CSCI2100C Data Structures
How to Count Basic Operations in Recursion?
Complexity Analysis: Growth of Functions
32
if left = right
if arr[left]= searchnum
return left
else
return
‐
1
middle
(left + right)/2
if
arr[middle] = searchnum
return middle
elseif
arr[middle] < searchnum
return
BinarySearch
(arr, searchnum, middle+1, right)
else
return
BinarySearch
(arr, searchnum, left, middle
‐
1)
1
2
3
4
5
6
7
8
9
10
11
12
13
BinarySearch(arr, searchnum, left, right)
𝑂ሺ
1
ሻ
𝑂ሺ
1
ሻ
𝑂ሺ
1
ሻ
𝑂ሺ
1
ሻ
𝑂ሺ
1
ሻ
𝑂ሺ
1
ሻ
𝑂ሺ
1
ሻ
𝑂ሺ
1
ሻ
𝑂ሺ
1
ሻ
𝑂ሺ
?
ሻ
𝑂ሺ
?
ሻ
CSCI2100C Data Structures
Worst case analysis of algorithms
Counting the # of basic operations in the
worst case
Big-Oh & Big-Omega notation
Big-Oh & Big-Omega rules (i)-(v)
Asymptotical algorithm comparison
Summary
Complexity Analysis: Growth of Functions
33
CSCI2100C Data Structures
Reading this week
Chapter 3, textbook
Next week
Complexity Analysis: Growth of Functions
with recursions
Recommended Reading
Complexity Analysis: Growth of Functions
34

You've reached the end of your free preview.
Want to read all 6 pages?
- Spring '19
- Big O notation, Analysis of algorithms, Computational complexity theory