# CS21: Quiz 5 Study Guide

### In addition to the concepts below, you should also know the concepts from Quiz 1, Quiz 2, Quiz 3, and Quiz 4.

#### You should understand the following terms:

• Swapping two values in a list
• Searching algorithms: linear and binary search
• Sorting algorithms (describe/recognize selection sort, insertion sort, bubble sort, merge sort)
• Complexity (Big-O notation) of searching and sorting algorithms
• String comparisons ("alice" < "zelda")

#### Practice problems:

1. True/False questions:
• Linear search requires a number of steps proportional to the size of the list being searched (T/F)
• The python in operator performs a binary search (T/F)
• Binary search is an NlogN algorithm (T/F)
• The number of times N can be divided by 2 is log base-two of N (T/F)
2. Approximately how many iterations will binary search need to find a value in a list of 1 million items?
3. Place these algorithm classes in order from best to worst: N, logN, N*N, NlogN
4. What is log(1024,2) in python? What about log(2048,2)?
5. How many steps are required for each of the following: N, logN, N*N, NlogN?
```#############################################
for i in range(n):
for j in range(n):
print i, j
#############################################
while n > 1:
print n
n = n/2
#############################################
for i in range(n):
for j in range(10):
print i, j
#############################################
```
6. Show the index values for low, high, and mid for each step in searching the list L for the value x using binary search.
```x = 99
L = [-20, -12, -4, 1, 7, 44, 45, 46, 58, 67, 99, 145]     low   mid   high
0    1   2  3  4   5   6   7   8   9  10   11      ----------------

```

7. Given the following assignments:
```   ls = ["fish", "squirrel", "cat", "dog", "monkey", "pony"]
s = "a,b,c,d,e"
```
What are the value and type of the following expressions:
```  (1) ls[3]
(2) ls[3] > "apple"
(3) ls[3][1]
(4) 'b' < 'f'
(5) len(ls[5])
(6) range(len(ls))
(7) range(len(ls[0]))
(8) s.split(",")

```