Chapter 1 : Binary Search, Big O Flashcards

1
Q

What is Big O Notation?

A

big O notation tells you how fast an algorithm is.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Are binary search algorithms input sorted?

A

binary search inputs are sorted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what’s a stupid /simple search?

A

stupid search is when you start from the beginning to the end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is the process of binary search?

A

with binary search, you guess the middle number and eliminate half the remaining numbers every time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is that the O(n) of binary search?

A

O(log n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

why is big O called big O?

A

it’s called Big O because you put a big O infront of the number of operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what’s another name for O(log n)?

A

O(log n) is also known as log time. ex. Binary search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is an example of algorithm with a Big O of O(n* log n)

A

O(n* log n) ex.quick short

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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?

A

7 steps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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?

A

8 steps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

You have a name, and you want to find the person’s phone number in the phone book. What’s the big O

A

O(log n).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

You want to read the numbers of just the As in a phone book? What’s the big O

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
A