Professional Documents
Culture Documents
Jagran Lakecity University, Bhopal: Course Code: Course Name
Jagran Lakecity University, Bhopal: Course Code: Course Name
Important Instructions
1. All questions are compulsory.
2. Answer all the questions in the same sequence of Question Paper.
3. Assignment’s content should be free of plagiarism and it should be submitted within given deadline.
4. The fonts for writing your answers should be either Calibri (12 pts) or Times New Roman (12 pts).
SECTION – A
Short answer type questions (5 x 8 = 40 marks)
1. List out the areas in which data structures are applied extensively?
Ans-
Data structures refers to the way data is organized and manipulated. It helps to find ways to
make data access more efficient. When dealing with data structure, we not only focus on one
piece of data, but rather different set of data and how they can relate to one another in an
organized manner.
Compiler Design,
Operating System,
Database Management System,
Statistical analysis package,
Numerical Analysis,
Graphics,
Artificial Intelligence,
And Simulation.
Inorder: DGBAHEICF
Postorder: GDBHIEFCA
Ans-
4. Write an algorithm to perform insertion and selection sort.
Ans-
Insertion Sort
Insertion Sort is a simple comparison based sorting algorithm. It inserts every array element into
its proper position.
Algorithm:
InsertionSort (Arr, N) // Arr is an array of size N.
{
For ( I:= 2 to N ) // N elements => (N-1) pass
{
// Pass 1 is trivially sorted, hence not considered
// Subarray { Arr[1], Arr[2], ..., Arr[I-I] } is already sorted
Algorithm:
SelectionSort (Arr, N) // Arr is an array of size N.
{
For ( I:= 1 to (N-1) ) // N elements => (N-1) pass
{ // I=N is ignored, Arr[N] is already at proper place.
// Arr[1:(I-1)] is sorted subarray, Arr[I:N] is undorted subarray
// smallest among { Arr[I], Arr[I+1], Arr[I+2], ..., Arr[N] } is at place min_index
min_index = I;
For ( J:= I+1 to N ) // Search Unsorted Subarray (Right lalf)
{ If ( Arr [J] < Arr[min_index] )
min_index = J; // Current minimum }
Swap ( Arr[I], Arr[min_index] );
// Swap I-th smallest element with current I-th place element
}
}
Algorithm
bfs(vertices, start)
Input: The list of vertices, and the start vertex.
Output: Traverse all of the nodes, if the graph is connected.
Begin
define an empty queue que
at first mark all nodes status as unvisited
add the start vertex into the que
while que is not empty, do
delete item from que and set to u
display the vertex u
for all vertices 1 adjacent with u, do
if vertices[i] is unvisited, then
mark vertices[i] as temporarily visited
add v into the queue
mark
done
mark u as completely visited
done
End
Depth First Search (DFS)
The Depth First Search (DFS) is a graph traversal algorithm. In this algorithm one starting vertex
is given, and when an adjacent vertex is found, it moves to that adjacent vertex first and try to
traverse in the same manner.
Algorithm
dfs(vertices, start)
Input: The list of all vertices, and the start node.
Output: Traverse all nodes in the graph.
Begin
initially make the state to unvisited for all nodes
push start into the stack
while stack is not empty, do
pop element from stack and set to u
display the node u
if u is not visited, then
mark u as visited
for all nodes i connected to u, do
if ith vertex is unvisited, then
push ith vertex into the stack
mark ith vertex as visited
done
done
End
SECTION – B
Long answer type questions (Word Limit 400 to 500) (5 x 12 = 60 marks)
1. Define Stack and Queue. Write an algorithm to perform insertion and
deletion in a Queue.
Ans-
Stack
Stack is a linear data structure which follows a particular order in which the operations are
performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).
Queue
Queue is ordered collection of homogeneous data elements in which insertion and deletion
operation take place at two end . insertion allowed from starting of queue called FRONT point
and deletion allowed from REAR end only
Steps:
Input : A que with elements. FRONT and REAR are two pointer of queue .
Output : The deleted element is stored in ITEM.
Data structure : Que is an array representation of queue structure..
Steps:
Begin:
createSinglyLinkedList (head)
alloc (newNode)
End if
Else then
read (data)
newNode.data ← data
temp ← head
For i ← 2 to n-1
temp ← temp.next
break End if
End for
If (temp != NULL) then
newNode.next ← temp.next
temp.next ← newNode
End if
End else
End
3. Define an AVL tree. Obtain a binary search tree and AVL tree by
inserting one integer at a time in the following sequence.
150, 155, 160, 115, 110, 140, 120, 145, 130, 147, 170, 180.
Ans-
AVL tree is a binary search tree in which the difference of heights of left and right subtrees of any
node is less than or equal to one. The technique of balancing the height of binary trees was
developed by Adelson, Velskii, and Landi and hence given the short form as AVL tree or Balanced
Binary Tree.
65 70 75 80 85 60 55 50 45
Ans-
Sorted array
45 50 55 60 65 70 75 80 85
given below:
Ans-