Introduction to algorithms - Binary search Flashcards

1
Q

What is an algorithm?

A

A set of instructions for accomplishing a task.

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

What is binary search?

A

An algorithm that takes a sorted list as input and returns the position of the target element (or null if not found).

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

How does binary search work?

A

It guesses the middle element and eliminates half the remaining numbers each time.

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

For a list of size n, how many steps does binary search take?

A

log₂ n steps in the worst case.

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

What does ‘linear time’ mean?

A

The maximum number of operations is the same as the size of the list (n).

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

What type of time complexity does binary search have?

A

Logarithmic time (or log time) - O(log n).

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

How do the run times of binary search and simple search grow differently?

A

Binary search takes a little more time, but simple search takes a lot more time as input size increases.

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

What does Big O notation tell you?

A

How fast an algorithm is by measuring the growth in number of operations as input size increases.

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

What is the Big O notation for simple search?

A

O(n) - linear time.

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

What is the Big O notation for binary search?

A

O(log n) - logarithmic time.

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

What does Big O establish about an algorithm?

A

The worst-case run time.

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

Name the five common Big O run times from fastest to slowest.

A
  • O(log n)
  • O(n)
  • O(n * log n)
  • O(n²)
  • O(n!)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is factorial time O(n!)?

A

Run time where the number of operations is n factorial, like the traveling salesperson problem.

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