Week 1: Search Problem, Linear Search, Binary Search Flashcards

1
Q

What is the “Search Problem”?

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

What are some examples of the search problem?

A

Finding a phone number of a person in a phonebook (S = phonebook, x = name of a person)

Printing a transcript of a person (S = student records, x = student ID)

Validating variable name (S = variables in a program, x = variable name)

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

The solution of a problem has two parts, what are they?

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

What is an algorithm?

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

How many different ways (algorithms) are there to solve a problem?

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

What is the SDLC? What are its parts?

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

What is a good practice for solving algorithms?

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

What is the algorithm for linear search?

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

How does one proove the correctness of an algorithm?

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

What is the correctness of linear search?

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

What is binary search?

A

Searching a sorted array by checking whether or not the middle element is the found element and then repeating with the LHS or RHS of the middle depending on whether the middle number was GT or LT the number we want to find.

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

What is the algorithm for binary search?

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

What is the correctness of binary search?

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

In linear search, when would the algorithm return -1?

A

When i = n. When the while/for loop has iterated over the entire array until the index of i has reached the length of the array (out of bounds)

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

What are the inputs/outputs for linear search?

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

What two tests are done for linear search?

A

i = n

A[i] != x

17
Q

What are the inputs/outputs of binary search?

A
18
Q

What is the order of events in the binary search algorithm?

A
19
Q

When does binary search return -1?

A
20
Q

In binary search, what happens if:

A[mid] > x

A
21
Q

In binary search, what happens when:

A[mid] < x

A