Question Paper Code : 50006
B.E./B.Tech. DEGREE EXAMINATIONS, APRIL/MAY 2024.
Second Semester
Artificial Intelligence and Data Science
AD 3251 — DATA STRUCTURES DESIGN
(Common to : Computer Science and Business Systems)
(Regulations 2021)
Answer ALL questions.
PART A — (10 × 2 = 20 marks)
- 1.
What are the various object oriented principles?
- 2.
Analyze the following code to predict and solve the recurrence relation to find time complexity. procedure whirlpool(m) begin if (m <= 0) then print ("eddy!"); exit( ); else swirl=whirlpool(m-1) + whirlpool(m-1); print("whirl"); end whirlpool
- 3.
Give the advantages of double ended queues.
- 4.
Implement a function that counts the number of nodes in a circularly linked list.
- 5.
Write down the time complexing of Binary Search.
- 6.
The keys 1,5,28,19,15,20, 33,12, 17, 10 are inserted into a hash table in which collision resolution is done by chaining. If the hash function, h(k) = k mod 4 and what is the length of the longest chain?
- 7.
The in order and pre order traversal of a binary tree are d b e a f c g and a b d e c f g. Give the post order traversal of the tree.
- 8.
Give some applications of multiway search tree.
- 9.
Does either Prim's or Kruskal's algorithm work if there are negative edge weights?
- 10.
What is topological ordering?
PART B — (5 × 13 = 65 marks)
- 11.(a)
Suppose you are on the design team for new e-book reader. What are the primary classes and methods that the Python software for your reader will need? Draw an inheritance diagram for this and implement it. Your software architecture should at least include ways for customers to buy new books, view their list of purchased books, and read their purchased books.
- Or
- (b)
Given an unsorted sequence, S, of integers and an integer k, describe a recursive algorithm for rearranging the elements in S so that all elements less than or equal to k come before any elements larger than k. What is the running time of your algorithm on a sequence of n values?
- 12.(a)
You are given a linked list, L, and another list, P, containing integers sorted in ascending order. The operation printLots(L,P) will print the elements in L that are in positions specified by P. For instance if P = 1, 3, 4, 6 the elements in positions 1,3,4 and 6 in L are printed. Write the procedure printLots(L,P). What is the running time of your procedure?
- Or
- (b)
How does a circular queue differ from a linear queue? Explain the algorithms to perform primitive operations of a circular queue.
- 13.(a)
Tamarindo Airlines wants to give a first-class upgrade coupon to their top log n frequent flyers, based on the number of miles accumulated, where n is the total number of the airlines' frequent flyers. The algorithm they currently use, which runs in O(n log n) time, sorts the flyers by the number of miles flown and then scans the sorted list to pick the top log n flyers. Describe an algorithm that identifies the top log n flyers in O(n) time.
- Or
- (b)
Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a hash function h(x) = x (mod ( ) 10), show the results for
- (i)separate chaining hash table with explanations(3)
- (ii)hash table using linear probing with explanations(3)
- (iii)hash table using quadratic probing with explanations(3)
- (iv)hash table with second hash function h2(x) = 7 - (x mod 7)(4)
- 14.(a)
Write a program to take N elements and do the following:
- (i)Insert them into a heap one by one.(4)
- (ii)Build a heap in linear time and write the pseudocodes.(5)
- (iii)Compare the running time of both algorithms for sorted, reverse-ordered, and random inputs.(4)
- Or
- (b)
- (i)Explain the significance of AVL trees over binary search trees in performing insertion and deletion operations. Write the general representations of AVL trees to execute LL, RL, L0, and R-1 operations.(7)
- (ii)Consider the following AVL tree shown in Fig 14 (b). After inserting 15, delete 18 from the tree, and perform the required rotations to maintain the tree as balanced one. [Fig 14 (b): AVL tree with root 4; 4 has children 2 and 7; 2 has children 1 and 3; 7 has children 6 and 17; 6 has left child 5; 17 has children 14 and 18](6)
- 15.(a)
Explain Depth first traversal algorithm on a graph and give its applications.
- Or
- (b)
Differentiate the minimum spanning tree obtained by using prim's and kruskal's algorithms with examples. Also compare the result of these two algorithms with time complexities.
PART C — (1 × 15 = 15 marks)
- 16.(a)
- (i)Construct a binary tree and binary search tree with the following data. 40,89,7,1,45,56,77,3,19,145,67,347,13,6,23,10,42,5,33,9(5)
- (ii)Perform the delete operations as sequence to delete the following numbers on the constructed binary and binary search trees. After each deletion, show the binary and binary search trees with current elements 5,1,89,40(6)
- (iii)Analyze the best, average and worst case time complexities of the insertion, deletion and searching an element in binary trees and binary search trees.(4)
- Or
- (b)
- (i)Explain the concept of divide and conquer and illustrate how the sorting algorithms merge and quick are coming under divide and conquer strategy.(5)
- (ii)Write merge sort and quick sort algorithms and demonstrate the execution of these algorithms on the following elements. Show the position of the elements in each phase of the execution of the algorithms. 56,7,2,454,5,21,56,7,45,90,9,7(5)
- (iii)Write the recurrence relation of recursive merge sort algorithm and solve it to find time complexity. Also analyze the quick sort algorithm to compute the worst case time complexity.(5)