JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD MCA 2021 DATA STRUCTURES AND ALGORITHMS Previous Question Paper (July/August - 2021 - R17)
Answer any five questions. All questions carry equal marks.
Main
Rearrange following numbers using Quick sort: 10, 6, 3, 7, 17, 26, 56, 32, 72.
Answer
To sort the array [10, 6, 3, 7, 17, 26, 56, 32, 72] using Quick Sort, we select the last element as the pivot.
- Initial array: [10, 6, 3, 7, 17, 26, 56, 32, 72]. Pivot = 72. All elements are smaller than 72, so 72 remains at the end.
- Sub-array [10, 6, 3, 7, 17, 26, 56, 32]. Pivot = 32. Elements smaller than 32 are [10, 6, 3, 7, 17, 26], elements larger are [56]. Array becomes [10, 6, 3, 7, 17, 26, 32, 56, 72].
- Sub-array [10, 6, 3, 7, 17, 26]. Pivot = 26. Elements smaller are [10, 6, 3, 7, 17]. Array becomes [10, 6, 3, 7, 17, 26, 32, 56, 72].
- Sub-array [10, 6, 3, 7, 17]. Pivot = 17. Elements smaller are [10, 6, 3, 7]. Array becomes [10, 6, 3, 7, 17, 26, 32, 56, 72].
- Sub-array [10, 6, 3, 7]. Pivot = 7. Elements smaller are [6, 3]. Array becomes [6, 3, 7, 10, 17, 26, 32, 56, 72].
- Sub-array [6, 3]. Pivot = 3. Swap results in [3, 6].
- Final sorted array: [3, 6, 7, 10, 17, 26, 32, 56, 72].
Give the properties asymptotic notations.
Answer
Asymptotic notations are mathematical tools used to describe the limiting behavior of a function as its input grows towards infinity. The primary properties are:
- Big-O Notation (O): Provides an asymptotic upper bound on the growth rate of a function. If f(n) = O(g(n)), then f(n) <= c*g(n) for all n >= n0.
- Omega Notation (Ω): Provides an asymptotic lower bound. If f(n) = Ω(g(n)), then f(n) >= c*g(n) for all n >= n0.
- Theta Notation (Θ): Provides an asymptotic tight bound, meaning the function is bounded both above and below by the same growth rate. f(n) = Θ(g(n)) if and only if f(n) = O(g(n)) and f(n) = Ω(g(n)).
- Transitivity: If f(n) = O(g(n)) and g(n) = O(h(n)), then f(n) = O(h(n)). This applies to all three notations.
- Reflexivity: Any function is asymptotically bounded by itself, e.g., f(n) = O(f(n)).
- Symmetry: f(n) = Θ(g(n)) if and only if g(n) = Θ(f(n)).
Trace the Merge sort algorithm to sort the list A, V, I, S, H, K, R, U, T, H in alphabetical order.
Answer
Sign in to view the complete answer paper.
What is the solution generated by function Job Sequencing algorithm when n = 6 (P1, P2, P3, P4, P5, P6) = (3, 5, 20, 18, 1, 6) and (D1, D2, D3, D4, D5, D6) = (1, 3, 4, 3, 2, 1).
Answer
Sign in to view the complete answer paper.
What is a Spanning tree? Explain Prim’s and Krushkal’s algorithm with the following graph.
Answer
Sign in to view the complete answer paper.
Draw an Optimal Binary Search Tree for n = 4 identifiers (a1, a2, a3, a4) = (do, if, read, while) P(1:4) = (3, 3, 1, 1) and Q(0:4) = (2, 3, 1, 1, 1).
Answer
Sign in to view the complete answer paper.
Discuss the 4 – Queen’s problem. Draw the portion of the state space tree for n = 4 Queens using backtracking algorithm.
Answer
Sign in to view the complete answer paper.
Define Max Heap. Construct Max Heap for the following: 140, 80, 30, 20, 10, 40, 30, 60, 100, 70, 160, 50, 130, 110, 120.
Answer
Sign in to view the complete answer paper.
Show that the maximum number of nodes in a Binary tree of height ‘h’ is 2h+1 - 1.
Answer
Sign in to view the complete answer paper.
Explain in detail about creation of a Binary Search Tree with suitable example.
Answer
Sign in to view the complete answer paper.