Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Calvin Secrest](https://uploads.teamtreehouse.com/production/profile-photos/4043962/micro_meta2.jpg)
Calvin Secrest
24,815 PointsWorst case scenarios?
So I understand how O(n) – linear time is having algorithm time grows proportionally the same the data set size grows. For example inserting into a list can be worst case scenario because every data item must be compared to inserted value. Yet, I am conflicting how worst case scenario can occur in Binary search or logarithm time and even further with Quadratic time, Cubic time, etc.. Sorry if I didn't explain myself clearly!
Thanks in advance
1 Answer
![reggaeshark](https://secure.gravatar.com/avatar/049006acca927246e0cc6b58deeb7c97?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
reggaeshark
8,542 PointsBinary search example
input - 9 sorted numbers between 1 to 1000 eg. [22(0), 443(1), 457(2), 482(3), 500(middle), 698(5), 811(6), 977(7), 979(8)]
- searching for position of 500
- 1) look in the middle => found 500 on first try
=> position of element found on first try best case scenario for binary search
searching for position of 977 1) look in the middle => 500 2) look at position 6 => 811 3) look at position 7 => 977
=> position of element found on third try worst case scenario for binary search (base 2 log) log(10) = 3.16 ~ 3, big(O) calculation of worst case