

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


You have two hours to complete this exam. ****DO ANY TWO OF THE THREE PROBLEMS. (Try to do all three if you can.)****
Give upper and lower bounds on the number of comparisons to solve the following problems:
INPUT: An array A=[a 1 ...aN] of real numbers. N = even integer. The array is NOT sorted. OUTPUT: An element a 1 contained in A that is greater than the MEDIAN, where the median is the biggest element in the bottom half. EXAMPLE: A = [1, 5, 3, 6]; MEDIAN = 3; RETURN 5 or 6.
Use the decision tree model of computation. (Each comparison counts 1 step.) Make your bounds as tight as you can make them, but no tighter.
DEFINITION: A celebrity is someone whom everyone knows, but who knows no one (else). THE PROBLEM: You are to determine if a party of N persons, N >= 2, has a celebrity by asking questions of the form "Do you know that person over there?" STEPS: Each question counts one step. All other computations are free. ASSUME: Each person (including the celebrity, if any) answers every (such) question asked of him, and answers it honestly. YOUR MISSION: Give upper and lower bounds on the number of steps (questions) to determine if a party has a celebrity. Make your bounds as tight as you can make them, but no tighter. HINT: Each answer to a question fills one entry of the MxN matrix [aij] defined by: aij = 1 if i knows j, 0 if i does not know j, -1 if i=j
In this problem, f:Z+->Z+^ is a given function. (see I below). An algorithm: Consider the following algorithm for computing "FOO [a 1 ...aN]": INPUT: An array [a 1 ...aN] of reals; N contained in Z+^ (positive integers) OUTPUT: [a 1 ...aN] a permutation of the input. BEGIN: 1 If Nthen sort input & return; else 2 2.1 Do FOO [a 1 ...af(N)] [Foo of top f(N) elements.] 2.2 Do FOO [aN-f(N)+1...aN] [Foo of bottom f(N) elements.] 2.3 Do FOO [a 1 ...af(N)] [Foo of top f(N) elements.] END
CS170, Midterm, Spring 1993
CS170 Spring 1993 Midterm Professor M. Blum 1
For which of the following choices of f does FOO sort the input array? PROVE YOUR ANSWERS A) f(N) = N-1 B) f(N) = ceiling(2/3 N) C) f(N) = ceiling((N+1)/2)
Analyze the running times of A, B, C (from part I). Let S(N) = number of steps FOO takes on input [a 1 ...aN].
CS170, Midterm, Spring 1993
Problem #3 (A Sorting Problem) 2