Chapter 1 : Binary Search, Big O Flashcards
What is Big O Notation?
big O notation tells you how fast an algorithm is.
Are binary search algorithms input sorted?
binary search inputs are sorted
what’s a stupid /simple search?
stupid search is when you start from the beginning to the end
what is the process of binary search?
with binary search, you guess the middle number and eliminate half the remaining numbers every time.
what is that the O(n) of binary search?
O(log n)
why is big O called big O?
it’s called Big O because you put a big O infront of the number of operations
what’s another name for O(log n)?
O(log n) is also known as log time. ex. Binary search
what is an example of algorithm with a Big O of O(n* log n)
O(n* log n) ex.quick short
Suppose you have a sorted list of 128 names and you’re searching through it using binary search. What’s the maximum number of steps it would take?
7 steps
Suppose you have a sorted list of 256 names, and you’re searching
through it using binary search. What’s the maximum number of
steps it would take?
8 steps
You have a name, and you want to find the person’s phone number in the phone book. What’s the big O
O(log n).
You have a phone number, and you want to find the person’s name in the phone book. (Hint: You’ll have to search through the whole book!) What’s the big O
O(n)
You want to read the numbers of just the As in a phone book? What’s the big O
O(n).
You may think, “I’m only doing this for 1 out of 26 characters, so the run time should be O(n/26).” A simple rule to remember is, ignore numbers that are added, subtracted, multiplied, or divided. None of these are correct Big O run times: O(n + 26), O(n - 26), O(n * 26), O(n / 26). They’re all the same as
O(n)! Why? If you’re curious, flip to “Big O notation revisited,” in chapter 4, and read up on constants in Big O notation (a constant is just a number; 26 was the constant in this question).