Cs8391-Data Structures Department of Eie & Ice 2021 - 2022
Cs8391-Data Structures Department of Eie & Ice 2021 - 2022
2022
UNIT I LINEAR DATA STRUCTURES – LIST
Abstract Data Types (ADTs) – List ADT – array-based implementation – linked list
implementation –singly linked lists- circularly linked lists- doubly-linked lists – applications
of lists –Polynomial Manipulation – All operations (Insertion, Deletion, Merge, Traversal).
UNIT-I / PART-A
1 Define Abstract Data Type (ADT). What are operations of ADT? (May 15,16, Dec 15,19)
An abstract data type (ADT) is the way we look at a data structure, focusing on what it
does and ignoring how it does its job. An ADT is a set of elements with a collection of
well-defined operations. Union, Intersection, size, complement and find are the various
operations of ADT.
Examples of ADTs include list, stack, queue, set, tree, graph, etc
2 What is Data Structure?
A data structure is basically a group of data elements that are put together under one
name, and which defines a systematic way of storing and organizing data either in
computer’s memory or on the disk storage so that it can be used efficiently.
Some common examples of data structures are arrays, linked lists, queues, stacks,
binary trees and hash tables
3 Why Data Structures?
Data structures study how data are stored in a computer so that operations can be
implemented efficiently. Data structures are especially important when you have a large
amount of information. Conceptual and concrete ways to organize data for efficient
storage and manipulation.
4 Draw the classification diagram of data structures.
34 What are the advantages of circular linked list over linear linked list?
The major advantage of circular lists (over non-circular lists) is that they eliminate some
extra-case code for some operations (like deleting last node). Also, some applications lead
naturally to circular list representations. For example, a computer network might best be
modeled using a circular list.
35 List three operations possible for general list that are not allowed for either stacks or
queues?
Linked list are more flexible in regard to insertion and deletion and rearrangement
Inserting a new entry at any position
Delete a data at any position
Retrieve data at any position
36 List out the applications of Circular doubly linked list.
Managing songs playlist in media player applications.
Managing shopping cart in online shopping.
37 Distinguish singly linked list with doubly linked list.
Singly linked list Doubly linked list
A singly linked list is a linked list where A doubly linked list is complex type of linked
the node contains some data and a pointer list where the node contains some data and a
to the next node in the list pointer to the next as well as the previous
node in the list
It allows traversal only in one way It allows a two way traversal
It uses less memory per node (single It uses more memory per node(two pointers)
pointer)
Complexity of insertion and deletion at a Complexity of insertion and deletion at a
known position is O(n) known position is O(1)
If we need to save memory and searching If we need better performance while
is not required, we use singly linked list searching and memory is not a limitation, we
go for doubly linked list
If we know that an element is located If we know that an element is located
towards the end section, eg. ‘zebra’ still we towards the end section e.g. ’zebra’ we can
need to begin from start and traverse the start searching from the Back.
whole list
Singly linked list can mostly be used for They can be used to implement stacks, heaps,
stacks binary trees.
38 What is static linked list? State any two applications of it. (May 15)(Dec 20)
The process of inserting an element in the queue is called enqueue, and the process of
deleting an element from the queue is called dequeue.
31 What is Enqueue and Dequeue?
The process of inserting an element in the queue is called enqueue, and the process of
St. Joseph’s College of Engineering
Page 13 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
deleting an element from the queue is called dequeue.
32 How queue data structure can be implemented?
In the computer’s memory, queues can be implemented using both arrays and linked lists.
33 Give the storage requirement of linked representation of queue.
The storage requirement of linked representation of queue with n elements is O (n) and the
typical time requirement for operations is O (1).
40 What are the different ways to implement priority queue? (Dec 18)
Linked Representation of a Priority Queue.
Array Representation of a Priority Queue
41 How to implement priority queue using a linked list?
When a priority queue is implemented using a linked list, then every node of the list will
have three parts:
(a) The information or data part,
(b) The priority number of the element, and
(c) The address of the next element.
42 What are multiple queues?
Multiple queues mean to have more than one queue in the same array of sufficient size.
43 Difference between stack and queue
Stack Queue
A Stack Data Structure works on Last In A Queue Data Structure works on First In
First Out (LIFO) principle. First Out (FIFO) principle.
A Stack requires only one reference A Queue requires two reference pointers.
pointer.
A Stack is primarily a vertical A Queue is a horizontal representation of
representation of data items. data items.
A Stack contains TOP as its reference for A Queue contains REAR and FRONT as its
data processing. reference for data processing.
Adding operation in the stack is called as Removing element in the stack is called as
PUSH. POP.
Removing element in the stack is called as Removing element in the queue is called as
POP. dequeue.
The way recursive system call works, it System interrupt is a good example where
uses Stack mechanism. queue mechanism is used
44 List out the applications of queues.
17 Draw the expression tree for the given postfix expression using stack.
AB*C+
1 2
*
A B
A B
3
4
C +
*
A B
C
*
A B
Inorder Traversal – 1 2 3 4 5 6 7 9
33 For the tree in Figure .
(a) List the siblings for node E
(b) Compute the height. (Nov 18)
UNIT-III / PART-B
1 a) What are the types of representation of binary tree?
b) Show that for the perfect binary tree of height h containing 2h+1-1nodes
St. Joseph’s College of Engineering
Page 24 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
2 What is traversal? Give an algorithm for traversal in the binary tree. Or Explain the tree
traversal techniques with an example. (Dec 19)
3 Draw a Binary search tree for the following input list 60,25,75,15,50,66,33, 44. Trace the
algorithm to delete the nodes 25, 75, 44 from the tree./ 45,56,39,12,34,32,10,78,67,89,91 also
give pre order and post order traversal. (Dec 20)
4 Write a routine to implement the basic binary search tree operations. Or How to insert and
delete an element into a binary search tree and write down the code for the insertion
routine with an example. (Dec 19)(Dec 20)
5 Explain in detail about Threaded binary trees.
6 Write the algorithm to construction an expression tree and construction an expression tree
for the input ab+cde+**.
7 Show the result of inserting 10,12,1,14,6,5,8,15,3,9,7,4,11,13, and, 2, one at a time, in to an
initially empty binary heap.
8 Write and test a program that performs the operation Insert, DeleteMin, Build Heap,
Findmin, DecreaseKey, Delete, and IncreaseKey in a binary Heap.
9 Show the result of inserting 2, 4,1,5,9,3,6,7 in to an initially empty AVL Tree.
10 Write a procedure to implement AVL single and double rotations.
11 Write a routine to perform insertion and deletion in B-Tree.
12 Explain in detail about splay trees and its rotations with example.
13 Construct the heap for the following array structure and write a procedure to perform
percolate up and percolate down in a binary heap.
5 19 8 37 75 55 14 22 43 4
14 Distinguish between B Tree and B+ Tree. Create a B tree of order 5 by inserting the
following elements: 3, 14, 7, 1, 8, 5, 11, 17, 13, 6, 23, 12, 20, 26, 4, 16, 18, 24, 25 and 19 . (Nov 18)
/ Construct B tree 2,14,12,4,22,8,16,26,20,10,38,18,36,48,6,24,28,40,42,32 (Dec 20 )
Create B+ tree of order 5 - 90,27,7,9,18,21,3,4,16,11,21,72. (Dec 20 )
15 Write the following routines to implement the basic binary search tree operations. (Nov 18)
i) Perform search operation in binary search tree.
ii) Find_min and Find_max
16 i) Write a routine for post order traversal. Is it possible to find minimum and
maximum value in the binary search tree using traversals? Discuss
ii) Display the given tree using Inorder, Preorder, Postorder traversals.
iii) Delete 11 and 10 from the above binary search tree. And display the tree after each
deletion (May 19)
17 i) Write a routine for AVL tree insertion. Insert the following elements in the empty
tree and how do you balance the tree after each element insertion? Elements :
2,5,4,6,7,9,8,3,1,10.
ii) Discuss about B+ tree. And discuss the applications of heap. (May 19)
St. Joseph’s College of Engineering
Page 25 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
UNIT IV NON LINEAR DATA STRUCTURES – GRAPHS
Definition – Representation of Graph – Types of graph - Breadth-first traversal - Depth-first
traversal – Topological Sort – Bi-connectivity – Cut vertex – Euler circuits – Applications of
graphs.
UNIT-IV / PART-A
1 Define Graph.
A graph G consist of a nonempty set V which is a set of nodes of the graph, a set E which
is the set of edges of the graph, and a mapping from the set for edge E to a set of pairs of
elements of V. It can also be represented as G=(V, E).
2 Define adjacent nodes.
Any two nodes which are connected by an edge in a graph are called adjacent nodes. For
example, if an edge x ε E is associated with a pair of nodes (u,v) where u, v ε V, then we
say that the edge x connects the nodes u and v.
3 What is a directed graph?
A directed graph is graph, i.e., a set of objects (called vertices or nodes) that are connected
together, where all the edges are directed from one vertex to another. A directed graph is
sometimes called a digraph or a directed network.
5 What is a loop?
An edge of a graph which connects to itself is called a loop or sling. Where graphs are
defined so as to allow loops and multiple edges, a graph without loops or multiple edges is
often distinguished from other graphs by calling it a simple graph.
6 What is a simple graph?
A simple graph is a graph, which has not more than one edge between a pair of nodes than
such a graph is called a simple graph.
7 What is a simple path?
A path in a diagram in which the edges are distinct is called a simple path. It is also called
as edge simple.
A path in a graph is a sequence of vertices such that from each of its vertices there is an
a b
c
9 Define in degree of a graph?
In a directed graph, for any node v, the number of edges which have v as their terminal
node is called the in degree of the node v. Ex : In degree of c =1
a b
a b
a
e
a
c d
a a
The path from ‘a’ to ‘e’ are P1 = ((a,b),(b,e)) P2 = ((a,c),(c,d),(d,e))
12 What is a cycle or a circuit?
A path which originates and ends in the same node is called a cycle or circuit.
A cycle is a path where the last vertex is adjacent to the first. A cycle in which no vertex
repeats (such as 1-2-3-1 versus 1-2-3-2-1) is said to be simple.
13 What is an acyclic graph?
A simple diagram which does not have any cycles is called an acyclic graph. An acyclic
graph does not contain any cycles. Trees are connected acyclic undirected graphs. Directed
acyclic graphs are called DAGs.
14 What are the two traversal strategies used in traversing a graph?
St. Joseph’s College of Engineering
Page 27 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
Breadth First Search
Depth First Search
15 When is a graph said to be weakly connected?
When a directed graph is not strongly connected but the underlying graph is connected,
then the graph is said to be weakly connected.
16 What is an undirected acyclic graph?
When every edge in an acyclic graph is undirected, it is called an undirected acyclic graph.
It is also called as undirected forest.
17 Define connected and strongly connected graph. (Dec 19)
Two Vertices u and v are said to be connected if there exists a path from u to v in the
graph. A directed graph is said to be connected if every pair of vertices in the graph is
connected.
A directed graph is said to be strongly connected if for every pair of distinct vertices vi
and vj, there exists two disjoint paths, one from vi to vj and the other from vj to vi.
18 What are the different ways to represent graph (Dec 14,18 May 16)
Two ways of representing a graph are:
Adjacency matrix
Adjacency list
19 List the two important key points of depth first search.
If path exists from one node to another node, walk across the edge – exploring the edge.
If path does not exist from one specific node to any other node, return to the
previous node where we have been before – backtracking.
20 What do you mean by breadth first search (BFS)?
The breadth first traversal is a graph search algorithm that begins at root node and
explores all the beginning nodes. Then for each of those nearest nodes, it explores their
unexplored neighbor nodes and so on, until it finds the goal.
21 Define Shortest path problem?
For a given graph G=(V, E), with weights assigned to the edges of G, we have to find the
shortest path (path length is defined as sum of the weights of the edges) from any given
source vertex to all the remaining vertices of G
22 What is Bi- connectivity in graph? (May 19)
A connected undirected graph is bi-connected if there are no vertices whose removal
disconnects the rest of the graph.
If the nodes are computers and the edges are links, then if any computer goes down,
network mail is unaffected, except, of course, at the down computer. Similarly, if a
mass transit system is bi-connected, users always have an alternate route should some
terminal be disrupted.
23 What is Euler path and Euler circuit? (Dec 18)
An Euler path is a path that uses every edge of a graph exactly once. An Euler path
starts and ends at different vertices.
An Euler circuit is a circuit that uses every edge of a graph exactly once. An Euler
circuit starts and ends at the same vertex.
24 What is topological sorting (Dec 15)
Topological or topological ordering of a directed graph is a linear ordering of its vertices
27 Prove that the maximum number of edges that a graph with n Vertices is n*(n-1)/2.
Choose a vertex and draw edges from this vertex to the remaining n-1 vertices. Then, from
these n-1 vertices, choose a vertex and draw edges to the rest of the n-2 Vertices. Continue
this process till it ends with a single Vertex. Hence, the total number of edges added in
graph is (n-1)+(n-2)+(n-3)+…+1 =n*(n-1)/2.
28 Define adjacency list.(Nov/Dec 19)
Adjacency List is the Array[ ] of Linked List, where array size is same as number of
Vertices in the graph. Every Vertex has a Linked List. Each Node in this Linked list
represents the reference to the other vertices which share an edge with the current vertex.
The weights can also be stored in the Linked List Node.
29 Given a weighted, undirected graph with |V| nodes. Assume all weights are non-
negative. If each edge has weights ≤ w. What can you say about the cost of Minimum
Spanning tree?
G = (V, E) is an undirected graph with non-negative edge weights w : E → Z +. A spanning
tree is a tree with V − 1 edges, i.e. a tree that connects all the vertices. The total cost
(weight) of a spanning tree T is defined as w(T) = ∑ e∈T w(e). A minimum spanning tree is a
tree of minimum total weight.
30 Give the adjacency matrix representation of the following graph. (Dec 20)
A B C D E
A 0 1 inf 1 inf
B 1 0 1 1 inf
C inf 1 0 inf 1
D 1 1 inf 0 1
E inf inf 1 1 0
31 Give the procedure for finding articulation point (Dec 20 )
A vertex is said to be an articulation point in a graph if removal of the vertex and
associated edges disconnects the graph. So, the removal of articulation points increases the
number of connected components in a graph
UNIT-IV / PART-B
1 Explain in detail about Topological Sort Explain topological sort with algorithm and
suitable example (May 12, Dec 18)
2 Explain the various types of graphs with an example?
3 Compare BFS and DFS with pseudo code.(May 12)
Distinguish between breadth first search and depth first search with example. (Dec 18)
4 Describe the various representations of graphs (Dec 13)
5 (i) Explain the different ways to represent a graph.
(ii) Show the adjacency matrix, adjacency list and multi-list representation of a given
undirected graph.
6 Explain in detail about Bi-connectivity with an Example.
8 Present the pseudo codes of the different graph traversal methods and demonstrate with
an example or Explain depth first and breadth first traversal. Give the routine(Dec 16,19)
(Dec 20 )
11 Consider a directed acyclic graph 'D' given in following graph. sort the nodes of 'D' by
applying topological sort on 'D' (Dec 14)
12 Describe an appropriate algorithm to find the shortest path from ‘A’ to every other node of
A for the given graph. (May 19)
14 From the Figure, in what order are the vertices visited using DFS and BFS starting from the
vertex A? Where a choice exists, use alphabet order.