2 Marks With Answers
2 Marks With Answers
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 1 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
7 List out the applications of data structures.
❖ Compiler design
❖ Operating system
❖ Statistical analysis package
❖ DBMS
❖ Numerical analysis
❖ Simulation
❖ Artificial intelligence
❖ Graphics
8 List out the operations on linear Data Structures.
❖ Traversal: Visit every part of the data structure.
❖ Search: Traversal through the data structure for a given element.
❖ Insertion: Adding new elements to the data structure.
❖ Deletion: Removing an element from the data structure.
❖ Sorting : Rearranging the elements in some type of order(e.g Increasing or Decreasing)
❖ Merging: Combining two similar data structures into one.
9 Define Lists.
A list, also called a sequence, is a container that stores elements in a certain linear order, which
is imposed by the operations performed. The basic operations supported are retrieving,
inserting, and removing an element given its position. Special types of lists include stacks and
queues, where insertions and deletions can be done only at the head or the tail of the sequence.
The basic realization of sequences is by means of arrays and linked lists.
10 Define List Abstract Data Type.
A list is a sequence of zero or more elements of a given type a1, a2, . . . , an (n ≥ 0)
❖ n : length of the list
❖ a1 : first element of the list
❖ an : last element of the list
❖ n = 0 : empty list
❖ elements can be linearly ordered according to their position in the list
We say ai precedes ai+1, ai+1 follows ai, and ai is at position i
11 What are the various operations done under list ADT?
❖ Print list
❖ Insert
❖ Make empty
❖ Remove
❖ Next
❖ Previous
❖ Find kth
12 What are the different ways to implement list?
There are two ways to implement list
✓ Simple array implementation of list
✓ Linked list implementation of list
13 Write the Array Implementation of Lists.
❖ Here, elements of list are stored in the (contiguous) cells of an array.
❖ List is a structure with two members.
member 1 : an array of elements
member 2 : last — indicates position of the last element of the list
14 What are the disadvantages of array-based implementation?
❖ Arrays are of fixed size.
❖ Data elements are stored in contiguous memory locations which may not be always
available.
❖ Insertion and deletion of elements can be problematic because of shifting of elements from
their positions.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 2 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 3 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
24 Give the Structure definition of Singly Linked List.
struct slinklist
{
int data;
struct slinklist* next;
};
typedef struct slinklist node;
node *start = NULL;
25 What are the operations can we perform on a linked list? (June 14)
The basic operations that can be performed on linked list are,
❖ Creation of a list.
❖ Insertion of a node.
❖ Modification of a node.
❖ Deletion of a node.
❖ Traversal of a node.
26 What is the use of header in a linked list?
A linked list contains a pointer, referred as the head pointer, which points to the first node in the
list that stores the address of the first node of the list.
27 List out the applications of linked list.
1. 1. Linked lists are used to represent and manipulate polynomial. Polynomials are expression
containing terms with non-zero coefficient and exponents.
For example: P(x) = a0 Xn + a1 Xn-1 + …… + an-1 X + an
2. Represent very large numbers and operations of the large number such as addition,
multiplication and division.
3. Linked lists are to implement stack, queue, trees and graphs.
4. Implement the symbol table in compiler construction
28 What is circular linked list? (Dec 14, May 16)
The circular linked list (CLL) is similar to singly linked list except that the last node’s next
pointer points to first node. The list will be accessed like a chain. Circular linked list can be used
to help the traverse the same list again and again if needed.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 4 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
31 Write the C structure definition of Doubly Linked Lists.
struct node
{
struct node *prev;
int data;
struct node *next;
};
32 List out the applications of doubly linked list.
❖ Doubly linked list can be used in navigation systems where both front and back navigation
is required.
❖ It is used by browsers to implement backward and forward navigation of visited web pages
i.e. back and forward button.
❖ It is also used by various applications to implement Undo and Redo functionality.
❖ It can also be used to represent deck of cards in games.
❖ It is also used to represent various states of a game.
33 What is Circular doubly linked list?
A circular doubly linked list is one, which has both the successor pointer and predecessor
pointer in the circular manner. The objective behind considering circular double linked list is to
simplify the insertion and deletion operations performed on double linked list. In circular
double linked list the right link of the right most node points back to the start node and left link
of the first node points to the last node.
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 Distinguish singly linked list with doubly linked list.
Singly linked list Doubly linked list
A singly linked list is a linked list where the A doubly linked list is complex type of linked
node contains some data and a pointer to the list where the node contains some data and a
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 pointer) It uses more memory per node(two pointers)
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 is If we need better performance while searching
not required, we use singly linked list and memory is not a limitation, we go for
doubly linked list
If we know that an element is located towards If we know that an element is located towards
the end section, eg. ‘zebra’ still we need to the end section e.g. ’zebra’ we can start
begin from start and traverse the whole list searching from the Back.
Singly linked list can mostly be used for stacks They can be used to implement stacks, heaps,
binary trees.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 5 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
37 List out the applications of Circular doubly linked list.
❖ Managing songs playlist in media player applications.
❖ Managing shopping cart in online shopping.
38 What is static linked list? State any two applications of it. (May 15)
In Static Linked List, each node is allocated memory when it is to be inserted dynamically. Each
node contains a pointer pointing to the next node. But in Array List, we store values in an array
and have another array storing the indices of the nodes which correspond to the next item in the
list. There is one key array and one link array. Since the memory allocated to an array is
constant, it is static.
❖ The application of static linked list is to implement stack, hash table and binary tree.
UNIT-I / PART-B
1 Explain in detail about the linked list implementation using an example. State the problems in
freeing list node.
2 Write a program to reverse a linked list using recursion.
3 Write a routine to merge given two sorted linked lists.(Dec 15)
4 Write an algorithm to insert an element into a linked list. Explain it with an example.
5 Write and explain the algorithm to copy a linked list.
6 What are the operations on singly linked list? Explain with an example.
7 Write a C code for singly linked list with insert, delete, and display operations using structure
pointers. (May 16)
8 Describe the creation of a doubly linked list and appending the list. Give relevant coding C.
(Dec 14, May 14)
9 Illustrate the algorithm to implement the doubly linked list and perform all the operations on
the created list. (May 16)
10 Write a C program to concatenate two double linked lists.
11 Write an algorithm to insert a node at front and end of a circular linked list.
12 i) Make a comparison between a linked list and a linear array. Which one will you prefer to
use and when?
ii) Give the advantages and uses of circular linked lists.
13 Explain the applications of list.
14 Write a C program to perform addition, subtraction and multiplication operations on
polynomial using linked list. (May 15)
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
Stack ADT – Operations - Applications - Evaluating arithmetic expressions- Conversion of Infix to
postfix expression - Queue ADT – Operations - Circular Queue – Priority Queue - deQueue –
applications of queues.
UNIT-II / PART-A
1 What is stack?
A stack is a linear data structure in which the elements in a stack are added and removed only
from one end, which is called the TOP. Hence, a stack is called a LIFO (Last-In-First-Out) data
structure, as the element that was inserted last is the first one to be taken out.
Example: Pile of coins, a Stack of trays in cafeteria.
2 Where do we need stacks in computer science?
The answer is in function calls. In order to keep track of the returning point of each active
function, a special stack called system stack or call stack is used. Whenever a function calls
another function, the calling function is pushed onto the top of the stack. This is because after
the called function gets executed, the control is passed back to the calling function.
3 What is the use of system stack?
The system stack ensures a proper execution order of functions. Therefore, stacks are frequently
used in situations where the order of processing is very important, especially when the
processing needs to be postponed until other conditions are fulfilled.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 6 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
4 What are the different ways to implement Stack?
Stacks can be implemented using either arrays or linked lists.
5 What are the basic operations of stack?
A stack supports two basic operations: push, pop. The push operation adds an element to the
top of the stack and the pop operation removes the element from the top of the stack.
6 Draw the stack representation.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 8 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
23 What are the Steps to be followed for the Evaluation of Postfix Expression?
Read the postfix expression one character at a time until it encounters the delimiter ‘#’.
Step 1: If the character is an operand, push its associated value onto the attack.
Step 2: If the character is an operator, POP two values from the stack, apply the operator to them
and push the result on to the attack.
24 What are the advantages of using infix notations and postfix notations?
Advantages of using infix notations
❖ It is the mathematical way of representing the expression
❖ It is easier to see visually which operation is done from first to last
Advantages of using postfix notations
❖ Need not worry about the rules of precedence
❖ Need not worry about the rules for right to left associativity
❖ Need not need parenthesis to override the above rules
25 What are the Steps to be followed to convert an expression from Infix to Postfix?
Read the infix expression one character at a time.
Step 1: If the character is an operand, place it on to the output.
Step 2: If the character is an operator, push it onto the stack. If the stack operator has a higher or
equal priority than input operator then pop that operator from the stack and place it onto the
output.
Step 3: If the character is a left parenthesis, push it onto the stack.
Step 4: If the character is a right parenthesis, pop all the operators from the stack till it
encounters left parenthesis, discard both the parenthesis in the output.
26 Write the rules to be followed during infix to postfix conversions.
❖ Fully parenthesize the expression starting from left to right. During parenthesizing, the
operators having higher precedence are first parenthesized.
❖ Move the operators one by one to their right, such that each operator replaces their
corresponding right parenthesis.
❖ The part of the expression, which has been converted into postfix is to be treated as single
operand.
27 Write the rules to be followed during infix to prefix conversions.
❖ Fully parenthesize the expression starting from left to right. During parenthesizing, the
operators having higher precedence are first parenthesized.
❖ Move the operators one by one to their left, such that each operator replaces their
corresponding left parenthesis.
❖ The part of the expression, which has been converted into prefix is to be treated as single
operand.
❖ Once the expression is converted into prefix form, remove all parentheses.
28 What are the postfix and prefix forms of the expression?
A+B*(C-D)/(P-R) Postfix form: ABCD-*PR-/+ Prefix form: +A/*B-CD-PR
29 What is Queue? (Dec 15)
A queue is a FIFO (First-In, First-Out) data structure in which the element that is inserted first is
the first one to be taken out. The elements in a queue are added at one end called the REAR and
removed from the other end called the FRONT.
30 Draw the Queue representation.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 9 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
31 What is Enqueue and Dequeue?
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.
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).
34 What are the classifications of queue?
A queue data structure can be classified into the following types:
1. Circular Queue 2. Deque 3. Priority Queue 4. Multiple Queue
35 What is Circular Queue?
Circular Queue is a linear data structure in which the operations are performed based on FIFO
(First In First Out) principle and the last position is connected back to the first position to make
a circle. It is also called ‘Ring Buffer’.
36 Explain the concept of a circular queue? How is it better than a linear queue?
Circular queue have less memory consumption as compared to linear queue because while
doing insertion after deletion operation it allocate an extra space the first remaining vacant but
in circular queue the first is used as it comes immediate after the last.
37 What is deque? (Dec 14,15) (May 14,16)
A deque (Double-Ended Queue) (pronounced as ‘deck’ or ‘dequeue’) is a list in which the
elements can be inserted or deleted at either end. It is also known as a head-tail linked list
because elements can be added to or removed from either the front (head) or the back (tail) end.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 10 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
40 What are the different ways to implement priority queue?
❖ 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 means 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 First A Queue Data Structure works on First In First
Out (LIFO) principle. Out (FIFO) principle.
A Stack requires only one reference pointer. A Queue requires two reference pointers.
A Stack is primarily a vertical representation A Queue is a horizontal representation of data
of data items. items.
A Stack contains TOP as its reference for data A Queue contains REAR and FRONT as its
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 uses System interrupt is a good example where
Stack mechanism. queue mechanism is used
44 List out the applications of queues.
❖ Queues are widely used as waiting lists for a single shared resource like printer, disk, CPU.
❖ Queues are used to transfer data asynchronously (data not necessarily received at same rate
as sent) between two processes (IO buffers), e.g., pipes, file IO, sockets.
❖ Queues are used as buffers on MP3 players and portable CD players, iPod playlist.
❖ Queues are used in Playlist for jukebox to add songs to the end, play from the front of the
list.
❖ Queues are used in operating system for handling interrupts. When programming a real-
time system that can be interrupted, for example, by a mouse click, it is necessary to process
the interrupts immediately, before proceeding with the current job. If the interrupts have to
be handled in the order of arrival, then a FIFO queue is the appropriate data structure.
UNIT-II / PART-B
1 What is a Stack? Write the algorithm to perform insertion &deletion operation in the array
implementation of stack.
2 Discuss about stack ADT in detail. Explain any one application of stack. (Dec 14)
3 Write the Routine to perform Push, Pop and Peek operation in the Linked List implementation
of stack.
4 Write a program to reverse a list of given numbers.
5 Convert the infix expression (a*b)+((c*g)-(e/f)) into reverse polish notation.
6 Explain the implementation of Evaluating Postfix Expression with an example of abcd+e*+f+*
7 Convert A * (B + C) * D to postfix notation
8 Explain the implementation of Converting Infix to Postfix Expression.
9 Write an algorithm for convert infix expression to postfix expression with an example of
i) (A+(B*C-(D/E^F)*G)*H). (May 14)
ii) a + b * c + (d * e + f) * g
10 Evaluate the following postfix expression abcd+e*+f+* where a=3 b=2 c=5 d=6 e= 8 f=2.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 11 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
11 Write C program that checks if expression is correctly parenthesized using stack. (May 15)
12 What is a Queue? Write an Algorithm to perform Enqueue and Dequeue operation in the array
implementation of queue. Give relevant examples and diagrammatic representations.
13 Explain about Queue ADT in detail. Explain any one application of queue with suitable
example. (Dec 14)
14 Write a procedure to insert & delete an element in the linked list implementation of queue.
15 Write C program to implement Queue Functions using Arrays and Macros. (May 15)
16 Write a Program to create a queue from stack.
17 Explain Priority Queue with suitable example? Give its applications.
18 Explain the concept of circular queue with example? How is it better than linear queue?
19 Write an algorithm to perform the four operations in a double ended queue that is implemented
as an array. (May 14)
20 Differentiate between double ended queue and circular queue. (May 16)
UNIT III NON LINEAR DATA STRUCTURES – TREES
Tree ADT – tree traversals - Binary Tree ADT – expression trees – applications of trees – binary
search tree ADT –Threaded Binary Trees- AVL Trees – B-Tree - B+ Tree - Heap – Applications of
heap.
UNIT-III/ PART-A
1 Define Tree. Give an example.
A Tree is a collection of one or more nodes with a distinct node called the root, while remaining
nodes are partitioned as T1 ,T2, ..,Tk , K≥ 0 each of which are sub trees, the edges of T1,T2,…,Tk
are connected the root.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 12 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
5 Define a path in a tree.
A path in a tree is a sequence of distinct nodes in which successive nodes are connected by
edges in the tree.
B C
D E F G
H
The path from A-H is A-B-D-H
6 Define terminal and nonterminal nodes in a tree
❖ A node which has no children is called a terminal node. It is also referred as a leaf node.
These nodes have a degree as zero.
❖ All intermediate nodes that traverse the given tree from its root node to the terminal nodes
are referred as terminal nodes.
7 Define a Binary Tree ADT with an example.
A Binary Tree is a tree, which has nodes either empty or not more than two child nodes, each of
which may be a leaf node.
B C
D E F G
8 Define a full binary tree.
A full binary tree, is a tree in which all the leaves are on the same level and every non-
leaf node has exactly two children.
9 Define a complete binary tree.
A complete binary tree is a tree in which every non-leaf node has exactly two children
not necessarily to be on the same level.
10 State the properties of a Binary Tree.
❖ Maximum No. of nodes on level n of a binary tree is 2^(n-1),where n>=1.
❖ Maximum No. of nodes in a Binary tree of height is 2^(n-1),where n>=1.
❖ For any non-empty tree,nl=nd+1 where nl is the number of leaf nodes and nd is the no. of
nodes of degree 2.
11 What are the different ways of representing a Binary Tree?
❖ Linear Representation using Arrays.
❖ Linked Representation using Pointers.
12 Define Traversal.
Traversal is an operation which can be performed on a binary tree is visiting all the nodes
exactly once.
❖ In order: traversing the LST, visiting the root and finally traversing the RST.
❖ Preorder: visiting root, traversing LST and finally traversing RST.
❖ Post- order: traversing LST, then RST and finally visiting root.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 13 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
13 Define a Binary Search Tree.
A Binary Search Tree is a special binary tree, which is either empty or if it is empty it should
satisfy the conditions given below:
❖ Every node has a value and no two nodes should have the same value (Values should be
distinct).
❖ The value in any left subtree is less than the value of its parent node.
❖ The value in any right subtree is greater than the value of its parent node.
4 8
3 5 7 9
14 Define Threaded Binary tree.
A Threaded Binary Tree is a binary tree in which every node that does not have a right child has
a THREAD (in actual sense, a link) to its INORDER successor. By doing this threading we avoid
the recursive method of traversing a Tree, which makes use of stacks and consumes a lot of
memory and time.
15 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
16 Perform inorder, preorder and postorder traversal for the given tree.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 14 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
17 Define Forest.
A forest is a collection on N(N>0) disjoint tree or group of trees are called forest. If the root is
removed from the tree that tree becomes a forest.
18 Define balanced search tree. (Dec 13)
Balanced search tree have the structure of binary tree and obey binary search tree properties
with that it always maintains the height as O(log n) by means of a special kind of rotations.
E.g. AVL, Splay, B-tree.
19 Define AVL tree. (Dec 13)
An empty tree is height balanced. If T is a non-empty binary tree with TL and TR as its left and
right subtrees, then T is height balanced if
1. TL and TR are height balanced.
2. | hL - hR | ≤ 1.
Where hl and hr are the height of TL and TR respectively.
20 What are the drawbacks of AVL trees?
The drawbacks of AVL trees are
❖ Frequent rotations
❖ The need to maintain balances for the tree’s nodes
❖ Overall complexity, especially of the deletion operation.
21 What is a heap?
A heap is a partially ordered data structure, and can be defined as a binary tree assigned to its
nodes, one key per node, provided the following two conditions are met
❖ The tree’s shape requirement-The binary tree is essentially complete, that is all the leaves
are full except possibly the last level, where only some rightmost leaves will be missing.
❖ The parental dominance requirement-The key at each node is greater that or equal to the
keys of its children.
22 What is the main use of heap?
Heaps are especially suitable for implementing priority queues. Priority queue is a set of items
with orderable characteristic called an item’s priority, with the following operations
❖ Finding an item with the highest priority
❖ Deleting an item with highest priority
❖ Adding a new item to the set
23 Give three properties of heaps?
The properties of heap are
❖ There exists exactly one essentially complete binary tree with ‘n’ nodes. Its height is
equal to log2n
❖ The root of the heap is always the largest element
❖ A node of a heap considered with all its descendants is also a heap
24 Give the main property of a heap that is implemented as an array.
A heap can be implemented as an array by recording its elements in the top-down, left-to-right
fashion. It is convenient to store the heap’s elements in positions 1 through n of such an array. In
such a representation
❖ The parental node keys will be in the first n/2 positions of the array, while the leaf keys
will occupy the last n/2 positions
❖ The children of a key in the array’s parental position ‘i’ (1 i n/2) will be in positions 2i
and 2i+1and correspondingly, the parent of the key in position ‘i’ (2 i n) will be in
position i/2.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 15 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 17 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
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 weighted graph?
A weighted graph is a graph in which each branch is given a numerical weight. A weighted
graph is therefore a special type of labeled graph in which the labels are numbers (which are
usually taken to be positive).
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))
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 18 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
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 Define connected and strongly connected graph.
❖ 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.
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 What are the two traversal strategies used in traversing a graph?
❖ Breadth First Search and Depth First Search
18 What are the different ways to represent graph (Dec 14, 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?
❖ 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.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 19 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
23 What is Euler path and Euler circuit?
❖ 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 such
that for every directed edge u v from vertex u to vertex v, u comes before v in the ordering.
25 List out the applications of depth—first search (May 16)
❖ Detecting cycle in a graph
❖ Path Finding
❖ Topological Sorting
❖ To test if a graph is bipartite
26 What is cut- vertex (or) what is an articulation point?
❖ If a graph is not bi-connected, the vertices whose removal would disconnect the graph are
known as articulation points.
❖ These nodes are critical in many applications. The graph in following Figure is not bi-
connected: C and D are articulation points. The removal of C would disconnect G, and the
removal of D would disconnect E and F, from the rest of the graph
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.
UNIT-IV / PART-B
1 Explain in detail about Topological Sort Explain topological sort with algorithm and suitable
example (May 12)
2 Explain the various types of graphs with an example?
3 Compare BFS and DFS with pseudo code.(May 12)
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.
7 Write a short notes about Euler circuit? Give an Example.
8 Present the pseudo codes of the different graph traversal methods and demonstrate with an
example (Dec 16)
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 20 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
9 Write an algorithm for breadth first search on a graph and give the nodes of the graph 'G' given
in following figure based on the algorithm (Dec 14)
10 Consider a directed acyclic graph 'D' given in following graph. sort the nodes of 'D' by applying
topological sort on 'D' (Dec 14)
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 21 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
3 Differentiate linear search and binary search.
Linear search Binary search
Linear search is easy but takes more time to Binary search it start searching from middle, if
search an element as it compare all element the searching element is not found in middle
sequentially then it goes to left or right and vice versa.
and hence take less time than linear search
Linear search requires O(n)times Binary search is very best in time and
efficiency. It requires O(log n)times
4 What is meant by sorting and what are its classifications?
Ordering the data in an increasing or decreasing order according to some relationship among
the data item is called sorting.
a) Internal sorting
b) External sorting
5 What is meant by external sorting?
External sorting takes place in the secondary memory of a computer, since the number of objects
to be sorted is too large to fit in main memory. Example: Merge sort, Multiday Merge,
Polyphone merge.
6 What is meant by internal sorting?
An internal sort is any data sorting process that takes place entirely within the main memory of
a computer. This is possible whenever the data to be sorted is small enough to all be held in the
main memory. Example: Bubble sort, Insertion Sort, Heap sort, shell sort, quick sort.
7 What are the various factors to be considered in deciding a sorting algorithm?
❖ Programming time
❖ Execution time of the program
❖ Memory needed for program environment
8 What is the main idea in Bubble sort?
The basic idea underlying the bubble sort is to pass through the file sequentially several times.
Each pass consists of comparing each element in the file with its successor (x[i] and x [i+1] and
interchanging the two elements if they are not in proper order.
9 What is meant by selection sort?
It will first find the smallest element in the array and swap it with the element in
the first position, then it will find the second smallest element and swap it with the element in
the second position, and it will keep on doing this until the entire array is sorted. It is called
selection sort because it repeatedly selects the next-smallest element and swaps it into the right
place.
10 What is complexity analysis?
It is the analysis of the amount of memory and time an algorithm requires to completion.
There are two types of Complexity
❖ Space Complexity: Space complexity of an algorithm is the amount of memory it needs to
run to completion.
❖ Time Complexity: Time complexity is the amount of computer time an algorithm requires to
run to completion.
11 What is insertion sort?
Insertion sort iterates, consuming one input element each repetition, and growing a sorted
output list. Each iteration, insertion sort removes one element from the input data, finds the
location it belongs within the sorted list, and inserts it there. It repeats until no input elements
remain.
12 What are the advantages of Insertion Sort?
❖ It is easy to implement and efficient to use on small sets of data
❖ It performs better than algorithms like selection sort and bubble sort. It is over twice as fast
as the bubble sort and almost 40 percent faster than the selection sort.
❖ It requires less memory space.
❖ It can be efficiently implemented on data sets that are already substantially sorted
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 22 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 23 of 24
CS8391- Data Structures Department of CSE & IT 2018-2019
25 Define Open Addressing.
Open addressing is an alternative to resolving collisions with linked lists. In an open addressing
hashing system, if a collision occurs; alternative cells are tried until an empty cell is found.
26 What are the uses of hash table?
1. Compilers can use hash table to keep track of declared variable in source code.
2.A hash table is useful for any graph theory problem where nodes have real names instead of
numbers
3. A third use of hash table is in program that plays games.
4. On line spell checkers
27 What is meant by Rehashing?
The rehashing method builds new table that is about twice as big and scan down the entire
original hash table, computing the new hash value for each element and inserting it in the new
table
28 When should we rehash?
❖ when table is half full
❖ when an insertion fails
❖ when load reaches a certain level
29 What are the advantages of Rehashing?
❖ Programmer doesn’t worry about the table size.
❖ Simple to implement.
❖ Can be used in other data structures as well.
30 What is the need of Extendible Hashing method?
When open addressing hashing or separate chaining hashing is used, Collisions could cause
several blocks to be examined during a Find, even for a well distributed hash table. Furthermore,
when the table gets too full, an extremely expensive rehashing step must be performed, which
requires O (N) disk accesses. This problem can be overcomes by using extendible hashing.
UNIT-V / PART-B
1 With example explain the binary search technique.
2 Explain the insertion sort with its time complexity.
3 Write an algorithm for Shell Sort Explain with examples.
4 Explain separate chaining and extendible hashing.
5 i) Explain the common collision resolution strategies in open address hashing.
ii) Describe the different hashing functions with an example.
6 Explain the algorithm to perform Radix Sort with Example.
7 Write the selection sort algorithm and explain with suitable example. Give its worst case,
Average Case and Best case time complexities.
8 Explain about collision resolution techniques.
9 Given input {4371,1323,6173,4199,4344,9679,1989} and a hash function h(X) = X (mod 10). Show
the resulting
1.Separate chaining table
2.Open addressing hash table using linear probing
3.Open addressing hash table using Quadratic probing
4.Open addressing hash table with second hash function h2(X)=7-(X mod 7)
10 Explain in detail about Rehashing method.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 24 of 24