80 likes | 198 Views
CSE 3358 Note Set 5. Data Structures and Algorithms. Google Chrome. http://www.google.com/googlebooks/chrome/#. Complexity of Binary Search. int binarySearch ( int arr [], int arrSize , int key) { int lo = 0, mid, hi = arrSize – 1; while (lo <= hi) { mid = (lo + hi) / 2;
E N D
CSE 3358 Note Set 5 Data Structures and Algorithms
Google Chrome http://www.google.com/googlebooks/chrome/#
Complexity of Binary Search intbinarySearch(intarr[], intarrSize, int key) { int lo = 0, mid, hi = arrSize – 1; while (lo <= hi) { mid = (lo + hi) / 2; if (key < arr[mid]) hi = mid – 1; else if (arr[mid] < key) lo = mid + 1; else return mid; } return -1; }
Big - O • How do I know that T(n) = n2 + 100n + log10 n + 1000is O(n2)?
Issues with Big - O • Consider: • T(n) = O(n2). • When might this be essentially useless information?
Big - Ω Definition: The function f(n) is Ω(g(n)) if there exist positive numbers c and N such that f(n) >= c*g(n) for all n >= N. Interconnection with Big-O: f(n) ЄΩ(g(n)) iffg(n) Є O(f(n)).
Big - Θ Definition: f(n) is Θ(g(n)) if there exist positive numbers c1, c2, and N such that c1*g(n) <= f(n) <= c2*g(n) for all n >= N. Sometimes called “tight bounds”. Interconnection with Big-O and Big - Ω: f(n) ЄΘ(g(n)) ifff(n) O(g(n)).