Chapter 4: Quicksort Flashcards

1
Q

Write out the code for the earlier sum function.

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

Write a recursive function to count the number of items in a list.

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

Find the maximum number in a list.

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

Remember binary search from chapter 1? It’s a divide-and-conquer algorithm, too. Can you come up with the base case and recursive case for binary search?

A

The base case for binary search is an array with one item. If the item you’re looking for matches the item in the array, you found it! Otherwise, it isn’t in the array. In the recursive case for binary search, you split the array in half, throw away one half, and call binary search on the other half.

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

Printing the value of each element in an array. What’s the big O

A

O(n)

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

Doubling the value of each element in an array. Big O?

A

O(n)

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

Doubling the value of just the first element in an array. Big O?

A

O(1)

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

Creating a multiplication table with all the elements in the array. So if your array is [2, 3, 7, 8, 10], you first multiply every element by 2, then multiply every element by 3, then by 7, and so on.

A

O(n^2)

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