0% found this document useful (0 votes)
70 views7 pages

CS 745

. Starting from the root node perform In-order, pre order and post order traversals on the following : binary tree and show the resultant series for each traversal.

Uploaded by

Rameen Ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views7 pages

CS 745

. Starting from the root node perform In-order, pre order and post order traversals on the following : binary tree and show the resultant series for each traversal.

Uploaded by

Rameen Ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Student Declaration

I_____Khadija Nawaz_______________ Registration No.______19-arid-502____________,

hereby declare that I will not be involved in any kind of cheating/copying/plagiarizing in

solving the assignment based paper of Mid Term Examination 2020. I take full responsibility

of my conduct. If I found involved in any kind of such activity of

cheating/copying/plagiarizing then Institute reserves the right to take any disciplinary action

against me.

Student Signature
Finl Exam / Spring 2020 (Paper Duration 24 hours)
Department of Computer Science

Course No.: CS-745 Course Title: Data Structure


Total Marks: 30 Date of Exam: ______8/8/20_______
Degree: MCS Semester: 03 Section: A
Marks
Q.No. 1 2 3 4 5 6 7 8 9 10 Obtained/
Total Marks
Marks
Obtaine
d
Total Marks in Words:
Name of the teacher: Shafiq Babar
Who taught the course:Signature of teacher / Examiner:

To be filled by Student

Registration No.: ………………19-arid-502…….……… Name: ………………Khadija Nawaz…………..

Answer the following questions.

Q.No.1.
Answer the following short questions. (09)

a. Suppose we have the following representation for a complete Binary Search Tree,
tell the Left and Right child nodes of the node D.
b. What is the difference between strict and complete binary tree?
c. List some basic functions of stack.
d. Define the following terminologies used in graphs. (Vertex, Degree of vertex, path,
cycle)
e. How many leaf and non-leaf nodes are present in a perfect binary tree if its depth is
3?
f. Represent the following Binary tree using array representation?
Answer:
a.
2(i)+1=right node=2*4+1=9=I
2(i)=left node=2*4=8=H
i/2=parent node=4/2=2=B

b. Difference between strict and complete binary tree


Strictly Binary Tree: Complete Binary Tree:
if every non-leaf node in a binary tree has Complete Binary tree means that the elements have 2
non-empty left and right sub- trees, the nodes. The tree ‘T’ is said to be complete if all its levels
tree is termed as a strictly binary tree. except possibly nodes and if all the nodes at last level
A strictly binary tree with ‘n’ leaves always appear as far left as possible.
contains 2n – 1 nodes. 1 A binary tree of depth ‘d’ is an almost complete binary tree,
/ \ if
2 3
/ \
 Each leaf in the tree is either at level ‘d’ or at level ‘d
4 5 – 1’.
 For any node ‘n’, in the tree with a right descendant
at level ‘d’, all the left descendants of ‘n’, that are
leaves are also at level ‘d’. 1
/ \
2 3
/ \ / \
4 5 6 7
It is a complete binary tree.

c. List some basic functions of stack.


 Stack is an ordered list of similar data type.
 Stack is a LIFO(Last in First out) structure or we can say FILO(First in Last out).
 push() function is used to insert new elements into the Stack and pop() function is
used to remove an element from the stack. Both insertion and removal are allowed
at only one end of Stack called Top.
 Stack is said to be in Overflow state when it is completely full and is said to be
in Underflow state if it is completely empty.

d. Def the following terms:

Vertex, Degree of vertex, path, cycle

Vertices:

 Vertices is also known as called nodes


 It is denote with labels
Degree of a Vertex
The degree of a vertex is the number of edges incident with that vertex.
 Path
In graph theory, a path in a graph is a finite or infinite sequence of edges that joins a
sequence of vertices that are all distinct by the majority of definitions a guided or
directed path  in a directed graph is a finite or infinite sequence of edges joining a set
of distinct vertices but with the additional restriction that the edges be all directed in 
the same direction.
 Cycle
A circuit that doesn't repeat vertices is called a cycle.

e. How many leaf and non-leaf nodes are present in a perfect binary tree if its
depth is 3?
Answer:
leaf nodes= 2^d = 8
non-leaf nodes= 2^d-1 = 4
a. Represent the following Binary tree using array representation?

Tree representation using Array


No of Nodes : Index 0
Root Node : Index 1
Left Child: Parent Index * 1
Right Child: Parent Index*1+1
0 1 2 3 4 5
5 A B C D E

Q.No.2 a. Write pseudo code for Dikstra’s Algorithm and also solve with example . (04)

Answer: Djikstra's algorithm pseudocode


We need to maintain the path distance of every vertex. We can store that in an
array of size v, where v is the number of vertices.

We also want to be able to get the shortest path, not only know the length of the
shortest path. For this, we map each vertex to the vertex that last updated its path
length.

Once the algorithm is over, we can backtrack from the destination vertex to the
source vertex to find the path.

A minimum priority queue can be used to efficiently receive the vertex with least
path distance.

function dijkstra(G, S)
for each vertex V in G
distance[V] <- infinite
previous[V] <- NULL
If V != S, add V to Priority Queue Q
distance[S] <- 0

while Q IS NOT EMPTY


U <- Extract MIN from Q
for each unvisited neighbour V of U
tempDistance <- distance[U] + edge_weight(U, V)
if tempDistance < distance[V]
distance[V] <- tempDistance
previous[V] <- U
return distance[], previous[]

___________________________________________________________________________
___________________________________________________________________________
_______________________________________________________________

b. Starting from the root node perform In-order, pre order and post order traversals on the

following : binary tree and show the resultant series for each traversal. (04)
___________________________________________________________________________
___________________________________________________________________________
__________________________________________________________________________

Q.No.3.
a. Considers the following unsorted array, sort it by using Merge sort technique and draw
each step graphically.  (04)

56 45 48 55 60 74 46 24 20

Answer:
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
_______________________________________________________________

b.Write a program in C++ to create a Doubly linked list of n nodes and count the number
of nodes. (03)
Answer:
______

___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
__
Q.No.4. (06)
The following array of current size 11 starting from index 1, represents a heap
structure.
a. Draw a tree diagram of the heap which is shown above.
b. Insert a new value 86 into the heap. Draw the new heap tree when insertion is
done.
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________

You might also like