You are on page 1of 3

National University of Computer and Emerging Sciences

Lahore Campus
MT 217: Discrete Structures

Final Exam, Spring 2011 Max. Time: 3 hours

May 17, 2011 Max. Points: 100

Question No. 1 (10 + 5 +5 = 20 points)

(a) Three men with different nationalities and with different jobs live in consecutive houses on a
street. They have different favorite drinks and their house colors are different too. Given the
following clues, who lives in the blue house and what is the profession of the Pakistani?

The Bangladeshi does not drink water. The Indian is a doctor. Tea is drunk in the green house.
The engineer lives in the house on the extreme left. Green house is located on the extreme right.
Water is drunk in the middle house. The businessman lives in the red house.

(b) Write the quantification “There exists a unique x such that P(x)” using universal and existential
quantifications and logical operators.

(c) Prove that at least one of the real numbers a1, a2 , …, an is greater than or equal to the average of
these numbers. What kind of proof did you use?

_______________________________

Question No. 2 (5 + 8 + 2 + 5 = 20 points)

Consider the following function RecursiveSort which sorts n numbers recursively.

RecursiveSort (A , n) // A is an array containing n numbers


{
if (n == 1) return; // Requires zero steps to return

RecursiveSort(A , n-1); //To sort n numbers, first sort n-1 numbers

for (i=n-1; i>0; i--) //Each check is one step


{
if ( A[i+1] < A[i] ) //One Step
{
temp = A[i+1]; //One Step
A[i+1] = A[i]; //One Step
A[i] = temp; //One Step
}
}
}
Intuitively the function first sorts n-1 numbers to sort n numbers and to sort n-1 numbers, it first sorts n-2
numbers and so on. The function keeps calling itself recursively until the size of the input array A is equal
to 1, i.e, A only contains a single element which is already sorted.

(a) Write a recurrence relation for the function RecursiveSort.

(b) Solve the recurrence relation in part (a).What is the Big-O complexity of your solution?

(c) Prove the correctness of your solution for part (b) using induction. (Note that your solution to part
(b) is a function of n which tells how many steps the algorithm takes to sort n numbers)

_______________________________

Question No. 3 (10 + 10= 20 points)

For a change the government decides to start high-speed bullet trains among some of the cities of
Pakistan. For that a new rail track is needed. The following figure shows the cities to be connected using
the new bullet train track and the distances (in kilometers) among them.

60 Swabi
180
Peshawar

250 Rawalpindi

500 200 300

Sargodha 320
Gujranwala

200
60 70

Lahore
Faisalabad
110

a) Find an optimal network of rail tracks connecting every city in the figure above such that the total
length of the tracks on that network is the minimum.Which method will you use?

b) Which route should be taken to travel between Peshawar and Lahore such that the total distance
on that route is the minimum.Which method will you use?

_______________________________

Question No. 4 ( = 20 points)


_______________________________

Question No. 5 ( = 20 points)

THE END

You might also like