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.
Assume we use a sorting algorithm that performs n2 instructions in the worst case.
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 n2 + lg n in total.
The 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?
First, your algorithm should read in from the user a list of n+1 numbers, a0, a1, a2,...,an (these are called coefficients).
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 a0 + a1x+a2x2 ...+anxn.
There is no instruction that computes powers of numbers. As part of your algorithm you will need to compute the product xn; that is, you cannot assume that you can use xn in pseudocode.
Analyze the worst-case and best-case running time of your algorithm (the order of magnitude, or theta-notation is enough).
SelectionSort get a1,...an set unsortedEnd = n while (unsortedEnd > 1) find the position of the largest element among a1, a2,..,aunsortedEnd assign this position to p swap ap with aunsortedEnd unsortedEnd = unsortedEnd - 1 print "The list in sorted order is" a1, a2,..,an
6 1 5 3 2 6your algorithm should print
The 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).
4 3 1 2 5 7 6the median is 4. For the list
5 4 3 8 6 7 1 2the 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).
* ** *** **** ***** ****** ******* ******** ********* ********** ********** ********* ******** ******* ****** ***** **** *** ** * 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 print
abcwhile
print newline print "a" print newline print "b" print newline print "c"will print
a b c