80 likes | 203 Vues
This note explores the complexities of binary search and the definitions of Big O, Big Ω, and Big Θ notations in algorithm analysis. It provides a breakdown of the binary search algorithm, illustrating its efficiency with a time complexity of O(log n). Additionally, it discusses the significance of understanding these notations for performance evaluation and their interrelations, underscoring when certain complexities might be deemed impractical. The theoretical underpinnings are crucial for students and practitioners deepening their knowledge of data structures and algorithms.
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)).