Invitation: Chapter 3 Flashcards

1
Q

When doing a sequential search, what are the best, worst, and average cases?

A

Best=1
Worst=n
Average=n/2

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

How does binary search work?

A

We look in the middle, decide which way to go, look in the middle of that part, decide which way to go within the part, and keep repeating this pattern until we have found what we are looking for

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

What is the worst case in a binary search? What is the average case?

A

worst case=lg n

average case=(also) lg n(although exact value is smaller than in the worst case)

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

Pattern Matching: what is the best case?

2 cases

A

1: what we are looking for is the first pattern on the list.
2: the first pattern of what we are looking for appears nowhere on the list

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

Pattern Matching: what is the worst case?

2 cases

A

1: the pattern we are looking for appears continuously throughout the whole list, but never completely
2: the pattern appears absolutely everywhere on the list

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

explain selection sort algorithm

A

We have a list of numbers, and draw a vertical line at the far end of the list. The left side of this line represents the unsorted numbers. The right side represents the sorted numbers. Take the largest number on the unsorted side and switch it with the right-most number. Then move the vertical line one to the left. Repeat this process until there are no more numbers on the unsorted side.

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

What are the best, worst, and average cases of the selection sort algorithm?

A

There are none, since there is only one result:

((1/2)n^2)-(1/2)n

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