Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Regulation: 2018

Reg.
No.:

BANNARI AMMAN INSTITUTE OF TECHNOLOGY


(An Autonomous Institution Affiliated to Anna University, Chennai)
SATHYAMANGALAM – 638 401

END SEMESTER THEORY EXAMINATIONS - JANUARY 2022


III Semester

18IT304 & DATA STRUCTURES AND ALGORITHMS

Degree & Branch: B.Tech. & IT

Time: 3 Hrs. Maximum: 100 Marks

Instructions:
1. Students should not mark/write anything on the Question Paper other than the register number.
2. Sections A to E contain questions for 30 Marks each.
3. Students can attempt answering any two out of three subsections in each section.

Q.No. Questions

SECTION A COURSE OUTCOME 1 MAXIMUM: 20 MARKS


A1 Consider an ABC Orphanage is collecting funds from various volunteers to help the people in need.
They store the collected amount (in rupees) digitally. Daily status of balance amount is to be stored
on a sequence array in memory, under the same variable name called fund_generated.
(i) Write the code to,
a) Declare an integer array in the name “fund_generated”, provided the size of the array
is 5.
b) Store the values as (350, 550, 780, 900, and 345).
c) Print the values in the “fund_generated” array.
(6 Marks – [Ap/P,2])
(ii) Identify the run time complexity of code given below,
int sum = 0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
sum++;
(2 Marks – [Ap/P,2])
(iii) Which of the following is the advantage in choosing array for storing and accessing data?
a) Retrieving data in the array is tedious
b) We can retrieve data from random locations
c) We can store only the fixed size of elements in the array
Justify your answer.
(2 Marks – [An/C,3])
A2 Assume a vaccination centre, where each person is provided with a random token number from 1 to
100. Once, the tokens are distributed, the vaccination process is started. Then, the people are sorted
in ascending order based on the token numbers. Various sorting techniques can be used to make
the process efficient.
(i) 5 Tokens are distributed in given order as {5, 4, 3, 2, 1}. Identify the correct order of performing

Page 1 of 10
an bubble sort on the given set of values from the given choices.
a) 4 3 2 1 5 3 2 1 4 5 2 1 3 4 5 1 2 3 4 5
b) 4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5
c) 4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2
d) 4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5
Write the code for your answer.
(5 Marks – [Ap/P,2])
(ii) Apply Quick sort on a given sequence of tokens 42,23,74,11,65,58,94,36,99,87. What is the
sequence after first phase when pivot is first element?
(5 Marks – [Ap/P,2])

A3 A set of 10000 people are assembled for a Marathon in Chennai. Ms. Rani was invited by her friends
Ms.Salini and Ms.Devi for the marathon. A unique number is printed in each of the runners T-Shirt
for identification. Rani got struck in the traffic and she joins the crowd at the end. Now, Rani can use
any strategy or searching algorithm to search her friends in the vast crowd.
(i) Given that the unique number 57 belongs to Ms.Devi
The track contains the following people: 13, 19, 67, 94, 88, 57, 33, 22, 89, 91
At which call it identifies the Runner by using linear search (recursive) algorithm? And write the
code for this.
(5 Marks – [Ap/P,2])
(ii) Given an array M = {2, 5, 8, 12, 16, 23, 38, 56, 72, 91} and key = 23; How many iterations are
done until the element is found using binary search?
(2 Marks – [Ap/P,3])
(iii) In binary search algorithm if the value to be found is greater than the middle value of the
array, Which part of the array could be taken for further operation and write the code ?
(3 Marks – [U/C,2])
SECTION B COURSE OUTCOME 2 MAXIMUM : 20 MARKS
B1 Consider the data about students’ marks are stored for tracking their academic records in the form of
linked list. Each node in a linked list contains the records of the individual students.
(i) Each node contains maximum of two fields.
? ?
Name the form of list and explain the use of both the fields in the linked list node.
(2 Marks – [U/C,1])
(ii) Write the code and calculate the asymptotic time complexity to insert a student record at the
first position in the linked list.
(4 Marks – [An/C,2])
(iii) Write the c code to print all the elements in a Singly Linked List.
(4 Marks – [Ap/P,2])
B2 Suppose a teacher along with her 100 students goes to watch a movie. On reaching the theatre, the
teacher is sad to know that 100 continuous seats are not available for her students. The students will
sit in the theatre in a scattered way. To assemble her students after the movie, she needs to know
where every single one of them is sitting.

"How will I remember 100 seat numbers?” she thinks. Then an idea strikes her. She tells her
students to form a line and assigns each one of them with an unoccupied seat number. She also tells
the students to remember the seat number of the student standing behind him/her. Now the teacher
needs to know seat number of only the first child. By asking the seat number of the next student from
the first student she can go to the second student. In this way she can know where all the other
students are sitting by knowing only 1 address.

Page 2 of 10
Figure 1 Singly Linked List
Here, Head represents the teacher, A, B, C and D is students.
Consider the above scenario for answering the below questions:
(i) Identify which type of linked list is suitable to Exchange seat number with memory locations.
Justify your choice
a) Singly Linked List
b) Double Linked List
c) Circular Linked List
d) Hybrid Linked list
(3 Marks – [U/C,1])
(ii) Identify the type of memory allocation methods used in linked list. Give a suitable example
system/scenario for the same.
a) Static Memory allocation
b) Random memory allocation
c) Dynamic Memory allocation
d) Fixed memory allocation
(3 Marks – [U/C,2])
(iii) Figure 2 and 3 depicts a single linked list and circular linked list. What differentiates a circular
linked list from a Single linked list? Justify your answer.

Figure 2 Single Linked List

Figure 3 Circular Linked List


(4 Marks – [An/C,2])
B3 Suppose a company is facing recession and is trying to implement layoffs. And they are implementing
Seniority policy in layoffs meaning the Employees who have joined the company most recently will
have to exit the company first. Same principle used in stack data structure.
(i) Consider the following operation performed on a stack of size 10.
Push(2);
Pop();
Push(3);
Push(4);
Pop();
Push(5);
Pop();
Pop();
Push(7);
After the completion of all operation, Identify the number of elements present on stack and

Page 3 of 10
show the operations.
a) 1
b) 2
c) 3
d) 4
(2 Marks – [Ap/P,2])
(ii) Suppose you are planning to reverse the word “GeeksQuiz” using a stack principle. Identify
what will be the reversed string. Justify your choice.
a) zuiQskeeG
b) GeeksQuiz
c) ziuQskeeG
d) skeeGziuQ
(2 Marks – [Ap/P,2])
(iii) Consider the following pseudo code that uses a stack.

declare a stack of characters


while ( there are more characters in the word to read )
{
read a character
push the character on the stack
}
while ( the stack is not empty )
{
pop a character off the stack
write the character to the screen
}
What is output for input "abbcabb"?
a) bbabbca
b) abbcabb
c) bbacbba
d) bbacabb
Justify your choice.
(4 Marks – [Ap/P,2])
(iv) If the elements “D”, “A”, “T” and “A” are placed in a stack and are deleted one at a time, in what
order will they be removed?
(2 Marks – [Ap/P,2])

SECTION C COURSE OUTCOME 3 MAXIMUM: 20 MARKS


C1 Consider the following Tree and answer the following questions:

Page 4 of 10
Fig:4 Tree

(i) With reference to Fig:4 match the following terminologies with their equivalent description and
sample node numbers given:

Description Node numbers


Terminology
1) Root A) Nodes with the same parent i) 2,3
2) Leaf B) Converse notion of child ii) 4.5,6,7
3) Parent C) Top node in a tree iii) 1
4) Siblings D) Node with no children iv) 6,10,13,14
(4 Marks – [U/C,2])
(ii) With reference to Fig: 4, List out the internal and external nodes.
(4 Marks – [U/C,2])
(iii) If a parent node has exactly zero or two children. What type of tree can best represent the
family?
a) Binary tree
b) AVL tree
c) Complete binary tree
d) Full binary tree
(2 Marks – [U/C,2])
C2 ABC Constructions Pvt Ltd. has announced an opening for design engineers post. A set of
candidates are assembled in a room to appear for the interview. Assume the data about candidates
are stored in a tree data structure for ease of access.
Assume, their scoring orders are presented in the tree as below.

Page 5 of 10
Fig: 5 Tree
In the above Fig: 5, write pre-order, in-order and post order traversals and write the steps for
 (i) each.
(6 Marks – [Ap/C,2])
(ii) Which of the following is true about the given tree (Fig: 5)?
a) Tree
b) Binary tree
c) Binary search tree
d) AVL tree
Justify your answer.
(2 Marks – [Ap/C,2])
(iii) Suppose the numbers 15, 14 and 10 are inserted in to the given tree (Fig: 5). Draw the binary
search tree after inserting the given numbers.
(2 Marks – [Ap/C,2])
C3 The central library has designed a portal to store the number of people entering the library. For this
purpose, the librarian chooses the tree data structure. His primary requirement is to keep the tree
balanced.

Fig: 6 Tree
Identify which of the following is true about the given tree(Fig: 6 )
a) Binary tree
b) Binary search tree
(i)  c) AVL tree
d) B tree
Justify your answer.
(2 Marks – [Ap/C,2])
(ii) Suppose the numbers 19 and 20 are inserted in to given tree (Fig:6). Draw the tree after
inserting the given numbers and also predict the balance factors of the node 20, 19 and 18.
(3 Marks – [Ap/P,2])
(iii) Suppose the numbers 4 and 1 are inserted in to the given tree (Fig: 6). Predict the balance
factors of the nodes 1, 4 and 5. If the balance factor exceeds +2, which rotation is used to
balance the tree and draw the balance tree.
(5 Marks – [Ap/P,2])
SECTION D COURSE OUTCOME 4 MAXIMUM: 20 MARKS
D1 A person is travelling from Coimbatore to Bangalore. Multiple ways are available on-road to reach
the destination. Choosing the right path is one of the prime concern of the travel. The data structure
that suits the scenario is Graph data structure. Each place is marked by a node with a value on it and
is connected to adjacent nodes using edges.
(i) From the below given undirected graph, identify the sum of the degrees of all vertices in the
graph.

Page 6 of 10
Fig:7 undirected graph

(5 Marks – [Ap/P,2])
(ii) Calculate the in-degree and out-degree for the vertex ‘B’ in the below given graph.

Fig:8 Graph
(2 Marks – [Ap/P,2])
(iii) Identify the type of graphs in figure below from the given options and explain them.
A B C

Fig:9 List of Graphs

(3 Marks – [Ap/P,2])
D2 Let’s say there is a person currently at Agra, and they need to parcel 4 packages to other 4 cities.
Since there are many roads connecting the cities, to save time, He searches for paths which will take
least amount of time for delivering the packages.

Page 7 of 10
Fig. 10: Directed Graph
In the above scenario, He searches for paths which will take least amount of time for
delivering the packages from one source to all other destination. Identify the suitable algorithm
to solve the problem.
a) Prim’s algorithm
 (i) b) Dijkstra algorithm
c) Kruskal’s algorithm
d) Bellman ford algorithm
Justify your choice and find the minimum path from one source (Agra) to all other destination
(6 Marks – [Ap/P,2])
In World Wide Web, web pages are considered to be the vertices. There is an edge from a
page u to other page v if there is a link of page v on page u. What type of graph is this and
justify?
a) Directed graph
(ii)
b) Undirected graph
c) Weighted graph
d) Acyclic graph
(4 Marks – [U/C,2])
D3 Consider the following Undirected Graph and answer the following questions:

Fig. 11: Undirected Graph


(i) With reference to the figure 11, Find the minimum cost for the given undirected weighted graph
using Kruskal’s Algorithm.
(6 Marks – [Ap/P,2])
(ii) Which of the following are the applications of spanning tree?

Page 8 of 10
i) Network design
ii) Cluster analysis
iii) Google maps
iv) Find the locations of maps
v) Approximation algorithms for NP hard problems

(1 Mark – [U/C,2])
(iii) Differentiate Prim’s and Kruskal’s algorithm with respect to spanning tree.
(3 Marks– [U/C,2])
SECTION E COURSE OUTCOME 5 MAXIMUM: 20 MARKS
E1 A business is requesting a service provider to provide him storage space to store all his company data
and access them whenever needed from any location. The company data is stored in memory and
there are chances where sudden increase in data storage is seen beyond the allocated memory. Help
the service provider to provide continuous support to his client.
(i) How does a memory leak occur? What are the methods in which memory leak can be
avoided?
(4 Marks– [An/C,2])
(ii) Identify the correct library which composes of all the methods that supports dynamic memory
allocation like malloc(), calloc(),free().
a) math.h
b) stdlib.h
c) stdio.h
d) conio.h
Justify your answer with example.
(3 Marks– [Ap/P,2])
(iii) When you design an application, there are chances of underestimating the memory size.
Suggest a solution for this case to increase the memory size.
(3 Marks– [Ap/C,2])
E2 In movie theatre, a large queue is formed on the days of movie release. In this case, fan club
members are given the highest priority to get tickets. The best option to implement this is using Heap
data structure.
The input number of tickets for each fan group shows the priority of the club. Hence, the input is
given as,
{68, 66, 75, 33, 37, 42, 20, 77, 29, 54}
(i) Draw the MIN-HEAP for the input values provided in the description and show the step by step
insertion.
(5 Marks– [Ap/P,2])
(ii) Draw the MAX-HEAP for the input values provided in the description and show the step by step
insertion.
(5 Marks– [Ap/P,2])
E3 Assume a Department library contains 100,000 books. Each book falls under different category. So,
grouping books under same category is not possible. Now, if a reader wants a particular book,
retrieving the book was harder. Hence, the library in-charge named all the books with a unique ID and
took hash of the ID number and placed the book on corresponding shelf to easily identify the location.
This technique is called Hashing.
(i) We have a hash table of size 7 to store integer keys, with hash function h(x) = x mod 7. If we
use linear probing and insert elements in the order 23, 17, 19, 13, 25, 50. Which bucket 17 will
be placed?
(5 Marks– [Ap/P,2])
(ii) Consider the hash function is x mod 10.
Given an input, [34, 27, 89, 11, 79, 99, 92].
Identify the key that generates a hash value of 9 and gets stored in hash table.
(3 Marks– [Ap/P,2])
(iii) In the above scenario, hashing techniques are used to search the data. How much time it

Page 9 of 10
takes to search the data.
a) O(1) time
b) O(n2 )time
c) O(logn) time
d) O(n logn) time
Justify your choice.
(2 Marks– [An/C,2])
***End of Question Paper***

Page 10 of 10

You might also like