CS2223     Name________  
Midterm Exam
Date: April 11, 1997
All documentation permitted
1. (30 points) The median  of a set of n  numbers is the largest number. For example, the median of (8, 18, 6) is 8. Provide an  upper-bound on the complexity of finding the median of a list of n numbers.

2. (35 points) An unusual sorting algorithm proceeds by first calling a procedure C which counts the number of keys less than each key.  What is the exact (do not use O or Q notation) number of times that elements of array Count are incremented by C. That is, what is the exact number of times that statements c or m  are executed.

       procedure C (T : LIST);
            var Count : array [1..n] of integer;
                   i,j : 1..n;
            begin
              for i := 1 to n do {
                      Count[i] := 0; }
               for i := n downto 2 do {
                     for j := i-1 downto 1 do {
                        if T [i]< T [j] then
                            Count[j] := Count[j] + 1	c
                              else
                            Count[i] := Count[i] + 1 }}	m
             end;  {C}

3. (35 points) Given a connected graph G =(N,A) in which the edges all have distinct lengths, prove or give a counterexample to the following
  
  Conjecture: Among all paths in G  of one edge, the shortest such path must belong to a minimum spanning tree.

CS2223
Solutions to Midterm Exam

1. We can use any sorting algorithm with time complexity in  to sort the list, and then select the median in time in O(1).

2. 

3. The conjecture is true. A shortest path of one edge is a shortest edge, and Kruskal’s algorithm assures us that a shortest edge always belongs to a minimum spanning tree.