CSD3009 - Data Structure and Analysis of Algorithm
CSD3009 - Data Structure and Analysis of Algorithm
:
Name :
PART - A ( 30 Marks)
1 (a) Let A and B be two linked lists. Write a function to create a new linked list C that 10
contains elements alternative from A to B in reverse order beginning with the last
element of A. If you run out of elements in one of the lists, then append the remaining
elements of the other list to C. Discuss its time and space complexity.
OR
(b) Suppose you have railroad shunting yard with three shunting tracks that operate as 10
queue. The initial ordering of car/bogie is 3, 1, 8, 2, 7, 4, 5,9, 6. Following figure shows
the configuration of the shunting tracks, the input track, and the output track. Write a
step-by-step procedure to rearrange the all-inputs car using these three shunting tracks
with assumption that only one car can be moved at a time. Also write a program to
solve railroad cars arrangement problem. Discuss its time complexity.
H1
H2 9 8 7 6 5 4 3 2 1
6 9 5 4 7 2 8 1 3
H3
Shunting Tracks
2 (a) What is the bottleneck of binary search tree (BST)? How it is minimized by AVL Tree? 10
Show the result of inserting the following elements 22, 45, 65, 67, 78, 89, 87, 65, 54,
43, 32, 57, 48, 39, 26, 37, 60, 40, 20 into an initially empty AVL tree. Specify the type
of rotation after each insertion.
OR
(b) Consider the following list: 10
45,56,78,23,11,54,88,43,55,21,67,55
Page 1 of 2
Sort the above list by using:
o Quick sort
o Radix sort
Analyse the time complexity of both the sorting algorithm.
3 (a) Explain the divide and conquer approach for algorithm design. How the merge sort is 10
used as divide and conquer approach? Write and solve the recurrence relation of merge
sort. Also explain the working of merge sort on the following data:
11, 66, 33, 77, 88, 22, 44, 55, 99
OR
(b) For the digraph of Figure below obtain: 10
I. its adjacency matrix and its adjacency list representation
II. Breadth First Search (BFS) traversal of the graph.
III. Depth First Search (DFS) traversal of the graph.
1 3
4
2
5
6
5 Explain and write the algorithm of the single source shortest path problem. Find the 10
shortest path from the source node 5 to destination node 1. Also discuss its time
complexity.
2 5
1500
300 800
1200 4 250
1000
1000 3
1 6
1400
8
1700 900
1000
7
Page 2 of 2