Sie sind auf Seite 1von 4

Q4)

One can model a maze by having a vertex for a starting point, a finishing point, dead ends, and all the points in the maze where more than one path can be taken, and then connecting the vertices according to the paths in the maze. a- Construct such a graph for the following maze.

b- Which traversalDFS or BFSwould you use if you found yourself in a Maze and why?

a. Write a pseudo code for a divide-and-conquer algorithm for finding The Position of the largest element in an array of n numbers. b. What will be your algorithms output for arrays with several elements of the largest value? c. Set up and solve a recurrence relation for the number of key comparisons made by your algorithm.

Q5)
Find the order of growth for solutions of the following recurrences. T (n) = 4T (n/2) + n, T (1) = 1

Q6)
Apply quick sort to sort the list E, X, A, M, P, L, E in alphabetical order. Trace of the recursive calls made. For the partitioning procedure. a. Prove that if the scanning indices stop while pointing to the same element, i.e., i = j, the value they are pointing to must be equal to p. b. Prove that when the scanning indices stop, j cannot point to an element more than one position to the left of the one pointed to by i. c. Why is it worth stopping the scans after encountering an element equal to the pivot? d. Is quick sort a stable sorting algorithm

Consider the following algorithm. Algorithm Secret (A [0..n 1]) //Input: An array A[0..n 1] of n real numbers minval A[0]; maxval A[0] for i 1 to n 1 do if A[i] < minval minval A[i] if A[i] > maxval maxval A[i] return maxval minval a. What does this algorithm compute? b. What is its basic operation? c. How many times is the basic operation executed? d. What is the efficiency class of this algorithm? e. Suggest an improvement or a better algorithm altogether and indicate Its efficiency class. If you cannot do it, try to prove that, in fact, it
Cant be done

Q1
18 Mark s

Form the below Graph(G) Answer the following Questions 11 12 18 11 6 34 67 78 58 2 1 78 3 8 5 14 67 23 22 4 56 7 15 80 9

o o o o

Draw DFS and compute Cost Draw BFS and compute Cost Find the Mini-Spanning Tree(MST) Using Kruskal Method(compute Cost)( Find mini-spanning Tree(MST) Using Prime Method start at(9)(compute Cost)

Q2
12 Marks

algorithm(A[0..n-1],K) l=0 int m r=n-1 while l<=r do m=(l+r)/2 if k=A[m] return m else if k<A[m] r=m-1 else l=m+1 return -1

a) b) c)

What is the largest number of key comparisons made by this algorithm? (5 marks) What is the input and output of this algorithm? (2 marks) Analyze the time efficiency of this Algorithm and find Recurrence?(5 marks)

Das könnte Ihnen auch gefallen