Work individually, and call me if you need help. You are encouraged to discuss ideas and techniques broadly with other class members, but not specifics. Discussions should be limited to questions that can be asked and answered without using any written medium (e.g. pencil and paper or email). You should at no point look at the screen of your colleagues.

- Draw the tree structure that describes binary search on a list with 16 elements. What is the number of comparisons in the worst case?
- Assume we are using binary search to search for a target that
is smaller than all elements in a (sorted) list. What happens to the
variable
`start`throughout the algorithm? What values does it take? What about the variable`end`? - You know by now that binary search is more efficient than
sequential search (that is, if count only the search part, ignoring
reading the input). However, in order for binary search to work, the
input list must be sorted. In this problem you will explore the
tradeoff between using sequential search on an unsorted list, as
opposed to sorting the list and then using binary search.
Assume we use a sorting algorithm that performs

`n`instructions in the worst case.^{2}If we search only once, it is clear that is better to use sequential search which is order of

`n`, than sort the list then use binary search, which is order of`n`in total.^{2}+ lg nThe question is, what happens if we perform more than one search. Note that, in order to use binary search, we only need to sort the input once. Thus, as we perform more searches

**on the same list**, the second approach may become faster. This is because we only need to sort the list once; thus, after the first binary search (which has to sort the list), the subsequent ones will use only`lg n`in the worst case.If the list size is

`n=100,000`, about how many searches must be done before the second alternative (sorting plus binary search) is better? - In this problem you will develop an algorithm that evaluates a
polynomial at a point. A polynomial is a generalization of a linear
function
`ax+b`, but now the degree of`x`can be arbitrary:`P(x) = a`. In this problem we will assume_{0}+ a_{1}x+a_{2}x^{2}...+a_{n}x^{n}`n = 50`.First, your algorithm should read in from the user a list of

`n+1`numbers,`a`(these are called coefficients)._{0}, a_{1}, a_{2},...,a_{n}Then it should ask the user for a value

`x`. Given the values of the coefficients and`x`, your algorithm should compute and print the value`a`._{0}+ a_{1}x+a_{2}x^{2}...+a_{n}x^{n}There is no instruction that computes powers of numbers. As part of your algorithm you will need to compute the product

`x`; that is, you cannot assume that you can use^{n}`x`in pseudocode.^{n}Analyze the worst-case and best-case running time of your algorithm (the order of magnitude, or theta-notation is enough).

- Consider the following algorithm for sorting: pick the largest
element of the list and place it in the last position; then repeat on
the remaining elements. This is referred to as
`SelectionSort`. The algorithm, at a high level of abstraction, is given bellow:SelectionSort get a

_{1},...a_{n}set unsortedEnd = n while (unsortedEnd > 1) find the position of the largest element among a_{1}, a_{2},..,a_{unsortedEnd}assign this position to p swap a_{p}with a_{unsortedEnd}unsortedEnd = unsortedEnd - 1 print "The list in sorted order is" a_{1}, a_{2},..,a_{n}- Show how the algorithm works if the input list is
`3,1,2,5,4` - Describe in words what happens in the first iteration of the repeat loop (one sentence).
- Describe in words what happens in the second iteration of the repeat loop (one sentence).
- How many times is the repeat loop executed for a list of size
`n`? - For each of the 4 steps within the repeat loop, write down how many
instructions they take in the first iteration of the loop,for a list of size
`n`. - Same, for the second iteration of the loop.
- Same, for the last iteration of the loop.
- By adding up the numbers that you got above, find out the total running
time (number of instructions) of
`SelectionSort`, as a function of`n`, for a list of size`n`.

- Show how the algorithm works if the input list is
- Write an algorithm that reads a number
`n`and a list of`n-1`distinct integers from the user in the range`1,2,...,n`and figures out what is the missing number. For instance, if the user types in6 1 5 3 2 6

your algorithm should printThe missing number is 4

Analyze the worst-case and best-case running time of your algorithm (the order of magnitude, or theta-notation is enough).

- Write an algorithm that reads a number
`n`and a list of`n`numbers from a user and computes and prints the median element(s) in the list (the median is an element which has an equal number of elements smaller and larger than it). For instance for the list4 3 1 2 5 7 6

the median is 4. For the list5 4 3 8 6 7 1 2

the medians are 4 and 5.You can use any of the algorithms studied in class as a black box, without writing the code for them.

Analyze the worst-case and best-case running time of your algorithm (the order of magnitude, or theta-notation is enough).

- Write an algorithm that asks the user for a number
`n`, and prints the following pattern on the screen. The example below is for n=10, that is, the longest line has 10 stars.* ** *** **** ***** ****** ******* ******** ********* ********** ********** ********* ******** ******* ****** ***** **** *** ** * Goodbye.

Assume that subsequent`print`instructions all print on the same line. To start a new line, you will need to issus a special instruction, which we'll call`print newline`. For example:print "a" print "b" print "c"

will printabc

whileprint newline print "a" print newline print "b" print newline print "c"

will printa b c