0% found this document useful (0 votes)
78 views38 pages

Cs8391-Data Structures Department of Eie & Ice 2021 - 2022

This document provides an overview of linear data structures and lists. It defines key concepts like abstract data types (ADT), data structures, and linear vs non-linear data structures. It also describes list ADT and common list operations. Lists can be implemented using arrays or linked lists, each with their own advantages and disadvantages. Common list operations include traversal, search, insertion, deletion, and sorting.

Uploaded by

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

Cs8391-Data Structures Department of Eie & Ice 2021 - 2022

This document provides an overview of linear data structures and lists. It defines key concepts like abstract data types (ADT), data structures, and linear vs non-linear data structures. It also describes list ADT and common list operations. Lists can be implemented using arrays or linked lists, each with their own advantages and disadvantages. Common list operations include traversal, search, insertion, deletion, and sorting.

Uploaded by

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

CS8391- Data Structures Department of EIE & ICE 2021-

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.

5 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.
St. Joseph’s College of Engineering
Page 1 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
6 Distinguish between linear data structures from non-linear data structures.
Linear data structure Non-linear data structure
 Data is arranged in linear sequence.  Data is not arranged in sequence.
 They are easy to implement in  They are difficult to implement in
computer’s memory since they are computer’s memory since the data
organized sequentially. element can be attached to various
other data elements.
 Example: List, Stacks, Queue etc.  Example: Tree, Graph etc.
7 List out the applications of data structures.
 Compiler design
 Operating system
 Statistical analysis package
 DBMS
 Numerical analysis
 Simulation
 Artificial intelligence
 Graphics
8 Give the classification of data structures.
Data structures are generally categorized into two classes: primitive and non-
primitive data Structures.
 Primitive data structures are the fundamental data types which are supported by
a programming language. Some basic data types are integer, real, character, and
boolean. The terms ‘data type’, ‘basic data type’, and ‘primitive data type’ are
often used interchangeably.
 Non-primitive data structures are those data structures which are created using
primitive data structures. Examples of such data structures include linked lists,
stacks, trees, and graphs. Non-primitive data structures can further be classified
into two categories: linear and non-linear data structures.
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.

St. Joseph’s College of Engineering


Page 2 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022

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.
15 Why linked list is called as self-referential data type?
In a linked list, every node contains a pointer to another node which is of the same type;
it is also called a self-referential data type.
16 What is meant by a Linked List? Or Define linked list. (Dec 19)
Linear list is defined as item in the list called a node and contains two fields, an
information field and next address field. The information field holds the actual element
on the list. The next address field contains the address of the next node in the list.

17 How is an element of a linked list called? What will it contain?


Linked list or list is an ordered collection of elements. Each element in the list is
referred as a node. Each node contains two fields namely,
 Data field
 Link field
18 What is free pool?
The computer maintains a list of all free memory cells. This list of available space is

St. Joseph’s College of Engineering


Page 3 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
called the free pool.
19 Give the comparison between array and linked list. (Dec 18),(NOV/DEC-2020)
Array Linked list
Size of an array is fixed. Size of a list is not fixed.
Memory is allocated from stack. Memory is allocated from heap.
It is necessary to specify the number of It is not necessary to specify the number of
elements during declaration (i.e., during elements during declaration (i.e., memory is
compile time). allocated during run time).
It occupies less memory than a linked list It occupies more memory.
for the same number of elements.
Inserting new elements at the front is Inserting a new element at any position can
potentially expensive because existing be carried out easily.
elements need to be shifted over to make
room.
Deleting an element from an array is not Deleting an element is possible.
possible.
20 List out the advantages of linked lists. (May 14,15)
What are the advantages of linked lists over arrays? (May 19)
Linked lists have many advantages. Some of the very important advantages are:
 Linked lists are dynamic data structures. i.e., they can grow or shrink during the
execution of a program.
 Linked lists have efficient memory utilization. Here, memory is not pre-allocated.
Memory is allocated whenever it is required and it is de-allocated (removed) when
it is no longer needed.
 Insertion and Deletions are easier and efficient. Linked lists provide flexibility in
inserting a data item at a specified position and deletion of the data item from the
given position.
 Many complex applications can be easily carried out with linked lists.
21 What are the disadvantages of linked list over array? (Dec 18)
 The main disadvantage of linked list over array is access time to individual
elements. Array is random-access, which means it takes O(1) to access any element
in the array. Linked list takes O(n) for access to an element in the list in the worst
case.
 Another advantage of arrays in access time is special locality in memory. Arrays are
defined as contiguous blocks of memory, and so any element will be physically near
its neighbors. This greatly benefits from modern CPU caching methods.
 In linked list, Random access is not allowed. We have to access elements
sequentially starting from the first node. So we cannot do binary search with linked
lists.
 Extra memory space for a pointer is required with each element of the list. Hence
Linked lists wastes memory in terms of extra reference points.
22 What are the types of Linked Lists?
There are three common types of Linked List.

St. Joseph’s College of Engineering


Page 4 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
Singly Linked List, Circular Linked List, Doubly Linked List and Circular Doubly Linked
List.
23 What is singly Linked List?
A single linked list is one in which all nodes are linked together in some sequential manner.
Hence, it is also called as linear linked list. A singly linked list allows traversal of data only
in one way.

24 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.
25 What are the operations can we perform on a linked list? (May 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 Give the Structure definition of Singly Linked List.
Struct slinklist
{
int data;
struct slinklist* next;
};typedef struct slinklist node;
node *start = NULL;

27 List out the applications of linked list. (NOV/DEC-2020)


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


Page 5 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022

29 Mention where circular linked lists are widely used?


 A circular linked list is used to maintain the sequence of the Web pages visited.
Traversing this circular linked list either in forward or backward direction helps to
revisit the pages again using Back and Forward buttons.
 Circular linked lists are widely used in operating systems for task maintenance.
 Multiplayer games uses circular list to swap between players in a loop.
30 Write the C structure definition of Doubly Linked Lists.
Struct node
{
struct node *prev;
int data; struct node *next; };
31 What is Doubly Linked Lists?
A double linked list is one in which all nodes are linked together by multiple links which
helps in accessing both the successor node (next node) and predecessor node (previous
node) from any arbitrary node within the list. Therefore, it consists of three parts—data, a
pointer to the next node, and a pointer to the previous node. This helps to traverse in
forward direction and backward direction.

32 List out the applications of doubly linked list. (Dec 20)


 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.

St. Joseph’s College of Engineering


Page 6 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022

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)

St. Joseph’s College of Engineering


Page 7 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
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.
39 State the advantages of ADT. (Dec 18)
 Code is easier to understand (e.g., it is easier to see “high-level” steps being performed,
not obscured by low-level code).
 Implementations of ADTs can be changed (e.g., for efficiency) without requiring
changes to the program that uses the ADTs.
 ADTs can be reused in future programs.
40 Illustrate the difference between Linear Linked List and Circular Linked List. (May 19)
Two pointers are maintained in a node of Only one pointer is maintained in a node of
circular list, one will keep the address of singly list which contains the address of next
first previous node and first next node in node in sequence another will keep the
sequence. address of.
In circular list, we can move backward as In singly, we cannot move in backward
well as forward direction as each node direction because each in node has next node
keeps the address of previous and next pointer which facilitates us to move in
node in sequence. forward direction.
During deletion, we have to keep only one During deletion of a node in between the
node address i.e the node to be deleted. singly list, we will have to keep two nodes
This node will give the address of previous address one the address of the node to be
node automatically. deleted and the node just previous of it.
41 Compare Array ADT and List ADT.(Dec 20 )

Array ADT List ADT

An array is a collection of elements of a A linked list is a collection of objects known


similar data type. as a node where node consists of two parts,
i.e., data and address.
Array elements store in a contiguous Linked list elements can be stored anywhere
memory location. in the memory or randomly stored
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 (or)
Explain the insertion operation linked list. How nodes are inserted after a specified node?
(Dec 19)
5 Write and explain the algorithm to copy a linked list.
6 What are the operations on singly linked list? Explain with an example.
St. Joseph’s College of Engineering
Page 8 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
7 Write a C code for singly linked list with insert, delete, and display operations using
structure pointers. (May 16, Dec 18)
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) (Dec 20)
10 Write a C program to concatenate two double linked lists.
11 Write an algorithm to insert and delete a node at front and end of a circular linked list,
Also to display it. (Dec 20 )
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)
15 State the polynomial representation for 6x 3+9x2+7x+1 using linked list. Write procedure to
add and multiply two polynomial and explain with suitable example. (Dec 18)
16 What are the various operations on array? Write a procedure to insert an element in the
middle of the array. (Dec 18)
17 Write a procedure to deleting the last node from a circular linked list. (Dec 18)
18 What are the applications of linked list in dynamic storage management? (Dec 19)
19 i) Write a program to merge two sorted linked list (P & Q – assume that they are
available) to get a single sorted list S.
Eg. P:1  2  45  56
Q: 3  24  56  63  66
ii) Write a non-recursive procedure to reverse a singly linked list. (May 19)
20 i) Write a function to add two polynomials represented by linked representation. Apply
the function for the following input.
A=3x14 + 2x18 + 1, B = 8x12 + 3x10 + 3x8 + 10x6
ii) Write a function to delete the node n from the given doubly linked list.
p  q  r  n  s  t  z . (May 19)
21 Define data abstraction. Write the ADT for the data structure in which the same condition
can used appropriately, for checking overflow and underflow. Define all basic functions of
this ADT. (May 19)
22 i) Given two sorted Linked lists L1 and L2. Exemplify and write the functions to
compute
ii) State the advantages of Linked list over arrays. Specify any two real time applications of
Linked List . (Dec 20 )
23 Write a routine to implement two stacks using single array. (Dec 20 )
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.

St. Joseph’s College of Engineering


Page 9 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
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 are the different ways to implement Stack?
Stacks can be implemented using either arrays or linked lists.
4 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.
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.

7 What are the different ways to implement stack?


 Stack implementation using array.
 Stack implementation using linked list.
8 Write the array implementation of stack.
Stack can be represented as “Array”. For Representing Stack we have to declare the
following data structure
typedef struct stack
{
int data[MAX];
int top;
}stack;
9 Give the meaning of peek( ), isFull( ) and isEmpty( ) operations.
 Peek( ) - The peek operation returns the value of the topmost element of the stack.
 isFull( ) − check if stack is full.
 isEmpty( ) − check if stack is empty.
10 What is Stack Overflow and Underflow?
St. Joseph’s College of Engineering
Page 10 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
 Any attempt to insert a new element in already full stack is results into Stack
Overflow.
 Any attempt to delete an element from already empty stack results into Stack
Underflow.
11 List out the basic operations that can be performed on a stack
The basic operations that can be performed on a stack are
 Push operation
 Pop operation
 Peek operation
 Empty check
 Fully occupied check
12 What are the different forms of representing arithmetic expressions?
 Infix Notation: Operators are written between the operands.
 Prefix (Polish) Notation: Operators are written before the operands. Postfix Expression
is:AB/C+
13 List out the position of Top in the stack.
Position of Top Status of Stack
-1 Stack is Empty
0 First Element is Just Added into Stack
N-1 Stack is said to Full
N Stack is said to be Overflow
14 How Postfix notations are evaluated?
Postfix notations are evaluated using stacks. Every character of the postfix expression is
scanned from left to right. If the character is an operand, it is pushed onto the stack. Else, if
it is an operator, then the top two values are popped from the stack and the operator is
applied on these values. The result is then pushed onto the stack.
15 Differentiate between a stack and an array.
STACK ARRAY
Stack is a ordered collection of items Array is an ordered collection of items
Stack is a dynamic object whose size is Array is a static object i.e. no of item is fixed
constantly changing as items are pushed and is assigned by the declaration of the array
and popped 
Stack may contain different data types It contains same data types.
16 How does a stack implemented using linked lists differ from a stack implemented using
an array?
Stack implemented using array works only on fixed no of data values. The amount of data
must be specified at the beginning of the implementation itself whereas linked list works
for variable size of data. So, there is no need to fix the size at the beginning of the
implementation.
17 Give some applications of stack. (Dec 14, Nov/Dec 18,19)
 Reversing a list
 Parentheses checker
 Conversion of an infix expression into a postfix expression

St. Joseph’s College of Engineering


Page 11 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
 Evaluation of a prefix expression
 Recursion
 Tower of Hanoi
18 Explain how stacks are used in a recursive program?
A recursive function is defined as a function that calls itself to solve a smaller version of its
task until a final call is made which does not require a call to itself. They are implemented
using system stack.
19 Why are parentheses not required in postfix/prefix expressions?
Parenthesis is not required because the order of the operators in the postfix /prefix
expressions determines the actual order of operations in evaluating the expression.
20 What do you understand by a multiple stack?
If the stack is allocated less space, then frequent OVERFLOW conditions will be
encountered. To deal with this problem, the code will have to be modified to reallocate
more space for the array. In case we allocate a large amount of space for the stack, it may
result in sheer wastage of memory. Thus, there lies a trade-off between the frequency of
overflows and the space allocated. To deal with this problem is to have multiple stacks or
to have more than one stack in the same array of sufficient size.
21 Given the prefix form of the given infix expression a*b/c+d. (May 16)
Prefix form :
+/*abcd
22 What is Tower of Hanoi?
Tower of Hanoi is one of the examples illustrating the recursion technique. The problem is
moving a collection of N disk of decreasing size from one pillar to another pillar. The
movement of the disk is restricted by the following rules:
Rule 1: Only one disk could be moved at a time.
Rule 2: No larger disk could ever reside on a pillar on top of a smaller disk.
Rule 3: A 3rd Pillar could be used as an intermediate to store one or more disks, while they
were being moved from source to destination.
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
25 What are the Steps to be followed to convert an expression from Infix to Postfix? (Dec 19)
Read the infix expression one character at a time.

St. Joseph’s College of Engineering


Page 12 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
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 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.
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 Write the rules to be followed during infix to postfix conversions. (Dec 19)
 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.
30 Draw the Queue representation. / Brief about generalized version of queue.And list the
operations performed by it. (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).

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 does a Priority Queue mean? (Dec 18)
A Priority queue is an abstract data type in which each element is assigned a priority. The
priority of the element will be used to determine the order in which these elements will be
processed. The General rule of processing the elements of apriority queue is:
 An element with higher priority is processed before an element with a lower
priority.
 Two elements with the same priority are processed on a First-Come-First-Served
(FCFS) basis.
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.

38 What are the types of double-ended queue?


There are two variants of a double-ended queue. They include
 Input restricted deque: In this dequeue, insertions can be done only at one of the ends,
while deletions can be done from both ends.
 Output restricted deque: In this dequeue, deletions can be done only at one of the ends,
while insertions can be done on both ends
39 What is Circular Queue?
Circular Queue is a linear data structure in which the operations are performed based on
St. Joseph’s College of Engineering
Page 14 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
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’.

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.

St. Joseph’s College of Engineering


Page 15 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
 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
45 A priority queue is implemented as a Max-heap. Initially it has 5 elements. The level
order traversal of the heap is 10, 8, 5, 3, 2. Two new elements ‘11’ and ‘7’ are inserted into
the heap in that order. Give the level order traversal of the heap after the insertion of the
elements. (May 19)
11, 8, 10, 3, 2, 5, 7
46 Write a program to reverse a string using LIFO ADT . (NOV/DEC-2020)
void push(char x){
if(top==max-1){
printf("stack overflow");
} else {
stack[++top]=x;
} }
void pop(){
printf("%c",stack[top--]);
}
main()
{
char str[]="I Love Programming";
int len = strlen(str), i;
for(i=0; i<len; i++)
push(str[i]);
for(i=0; i<len; i++)
pop();
}
Output
gnimmargorP evoL I
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. Or Write an algorithm for push and pop operations on Stack
using Linked List (Dec 19)
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
St. Joseph’s College of Engineering
Page 16 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
abcd+e*+f+*
7 Convert A * (B + C) * D to postfix notation
8 Explain the implementation of Converting Infix to Postfix Expression. (Dec 18)
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 (May 19)
iii) A – (B / C + ( D % E * F ) / G ) * H (Dec 18)
iv) (4+8)*(6-5)/((3-2)*(2+2)) (Dec 20)
10 Evaluate the following postfix expression
i) abcd+e*+f+* where a=3 b=2 c=5 d=6 e= 8 f=2.
ii) 9 3 4 * 8 + 4 / - (Dec 18)
iii) 54 6 + 7 4 - * 9 / 35 15 + + (Dec 20)
11 Write C program that checks if expression is correctly parenthesized using stack. (May 15)
(Dec 20)
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. Or Implement a
priority queue using linked list. (Dec 19)
18 Explain the concept of circular queue with example? How is it better than linear queue?
(Dec 18)
19 Write an algorithm to perform the four operations in a double ended queue that is
implemented as an array. Or What is a DeQueue? Explain its operation with example (May
14,Dec 19)
20 Differentiate between double ended queue and circular queue. (May 16)
21 There are n balls in the box. The colours of the balls are red and blue. You are requested to
stack the ball in the bottom sealed basket one by one. The order of placing the balls is two
consecutive red balls followed by the two consecutive blue balls. Later, create two empty
queues Q1 and Q2. Remove the last inserted ball from the basket and place it in Q1.
Similarly remove the next ball from the basket and insert in Q2. Develop a program to
repeat this process until the basket is empty and also print the colour of the balls in both
queues. (Dec 19)
22 What are circular queue. Write the procedure to insert an element to circular queue and
delete an element from a circular queue using array implementation. (Dec 18)(Dec 20)
23 What are expression trees. Write the procedure for constructing an expression tree. (Dec 18)
24 Write algorithms to check if the given parenthesized arithmetic expression contains
balanced parenthesis and to convert such expression to postfix form and evaluate it.

St. Joseph’s College of Engineering


Page 17 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
Illustrate with example. (May 19)
25 i) State the advantage of Circular queue over linear queue. Write the functions for
Insertion in a circular queue.
ii) Build the max heap for the following 90, 150, 70, 40, 100, 20, 30, 10, 110 and show the
result of delete max. (May 19)
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.

Example : directory structure hierarchy


2 Give some applications of Trees.
 Implementing the file system of several operating systems.
 Evaluation of arithmetic expression.
 Set representation.
 Gaming/Decision making problems.
3 Define node, degree, siblings, depth/height, level.(Nov/Dec 19)
 Node: A node is an item of information with branches to other items.
 Degree: The number of subtrees of a node is called is degree.
 Siblings: The children of the same parent is said to be siblings.
 Level: The level of a node is defined recursively by assuming the level of the root to be
one and if a node is at level l, then its children at level l+1.
 Depth/Height: The depth/height of a tree is defined to be the level of a node which is
maximum.
4 Write the routine for node declaration in trees.
typedef struct TreeNode , *PtrToNode;
struct TreeNode
{
ElementType Element;
PtrToNode FirstChild;
PtrToNode NextSibling;

St. Joseph’s College of Engineering


Page 18 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
};
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.

The path from A-H is A-C-G-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.

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
St. Joseph’s College of Engineering
Page 19 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
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.
13 Define a Binary Search Tree. (Dec 19)
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.

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 Define Forest.
A forest is a collection on N(N>0) disjoint tree or group of trees. If the root is removed
from the tree that tree becomes a forest.
Uses:
 Forest data structure finds great use in data science.
 Social networking websites.
 Operating system storage
 Big Data
16 Perform inorder, preorder and postorder traversal for the given tree.

St. Joseph’s College of Engineering


Page 20 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022

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

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 T L 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 are the two alternatives that are used to construct a heap?
The two alternatives to construct a heap are
 Bottom-up heap construction

St. Joseph’s College of Engineering


Page 21 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
 Top-down heap construction
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.
25 Define binary heaps.
A binary heap is a heap data structure created using a binary tree. It can be seen as a
binary tree with two additional constraints:
 The shape property: the tree is an almost complete binary tree; that is, all levels of
the tree, except possibly the last one (deepest) are fully filled, and, if the last level of
the tree is not complete, the nodes of that level are filled from left to right.
 The heap property: each node is greater than or equal to each of its children
according to some comparison predicate which is fixed for the entire DS.
26 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.
27 Define Min-heap and Max-heap.
 Min-heap: A min-heap is a mirror image of the heap structure. It is a complete binary
St. Joseph’s College of Engineering
Page 22 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
tree in which every element is less than or equal to its children. So the root of the min-
heap contains the smallest element.
 Max-heap: A heap in which the parent has a larger key that the child’s key values then
it is called Max-heap
28 Define B-tree? (Dec 15, May 16)
A B-tree of order m in an m-way search tree that is either empty or is of height ≥1 and
 The root node has at least 2 children
 All nodes other than the root node and failure nodes have at least m/2 children.
 All failure nodes are at same level.
29 Explain AVL rotation. Mention the two types of rotations (Dec 13)
Some modifications done on AVL tree in order to rebalance it is called Rotation of AVL
tree. Two types of rotation are
1. single rotation
 Left-Left Rotation
 Right-Right Rotation
2. Double rotation.
 Left-Right Rotation
 Right-Left Rotation
30 Define Priority Queue?
Priority queue is a specialized data structure in which the elements are organized
according to the priorities of some key value.
31 Define splay tree.
A splay tree is a binary search tree in which restructuring is done using a scheme called
splay. A splay is heuristic method which moves a given vertex v to the roof of the splay
tree using a sequence of rotations.
32 Show the result of inorder traversal of the binary search tree given in figure. (Nov 18)

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)

St. Joseph’s College of Engineering


Page 23 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022

List the siblings for node E = D


Compute the height = 3
34 The depth of complete binary tree is 8 compute the number of nodes in leaf. (May 19)
Nodes at depth d in a perfect binary tree = 2d
Nodes at depth d in a perfect binary tree = 28 = 256 leaf nodes
35 Illustrate Heap Data Structure . (Dec 20)
A Heap is a special Tree-based data structure in which the tree is a complete binary tree. Generally,
Heaps can be of two types:
Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present
at all of it’s children. The same property must be recursively true for all sub-trees in that Binary
Tree.
Min-Heap: In a Min-Heap the key present at the root node must be minimum among the keys
present at all of it’s children. The same property must be recursively true for all sub-trees in that
Binary Tree.

36 How to resolve dangling threads in binary tree? Illustrate . (Dec 20)


Threaded Binary Trees are an improvement over Binary Search Trees that uses stack for iterative
traversal. ... Moreover, leftmost pointer in an In-Threaded Binary Tree always points to NULL since
no inorder predecessor for the leftmost node is available. This thread is referred to as dangling left
thread.

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.

4 What is an undirected graph?


An undirected graph is graph, i.e., a set of objects (called vertices or nodes) that are
connected together, where all the edges are bidirectional. An undirected graph is
sometimes called an undirected 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

St. Joseph’s College of Engineering


Page 26 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
edge to the next vertex in the sequence.
8 Define out degree of a graph?
In a directed graph, for any node v, the number of edges which have v as their initial node
is called the out degree of the node v. Ex : out degree of c =2

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

10 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).

11 Define path in a graph?


The path in a graph is the route taken to reach terminal node from a starting node. A path
in a graph is a sequence of vertices such that from each of its vertices there is an edge to
the next vertex in the sequence.

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

St. Joseph’s College of Engineering


Page 28 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
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.
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)

St. Joseph’s College of Engineering


Page 29 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022

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.

St. Joseph’s College of Engineering


Page 30 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
7 Write short notes about Euler circuit and write a program to find it? Give an Example.
ii)Find the Eulers path and Eulers circuit for the graph given below.(Dec 20)

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 )

9 Explain the various applications of Graphs. (Dec 19)


10 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)

11 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


Page 31 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022

12 Describe an appropriate algorithm to find the shortest path from ‘A’ to every other node of
A for the given graph. (May 19)

13 i) Explain in detail about strongly connected components and illustrate with an


example. (May 19)
ii) Find an Euler path or an Euler circuit using DFS for the following graph fig.

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.

UNIT V SEARCHING, SORTING AND HASHING TECHNIQUES


Searching- Linear Search - Binary Search. Sorting - Bubble sort - Selection sort - Insertion sort -
Shell sort – Radix sort. Hashing- Hash Functions – Separate Chaining – Open Addressing –
Rehashing – Extendible Hashing.
UNIT-V / PART-A
1 Define best case of an algorithm.
It is the shortest time that an algorithm will use over all instances of size n for a given
problem to produce the result.
2 What is binary search?
St. Joseph’s College of Engineering
Page 32 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
Binary search is also a method used to locate a specified item in a sorted list. This method
starts by comparing the searched element to the elements in the middle of the list. If the
comparison determines that the two elements are equal the method stops and returns the
position of the element. If the searched element is greater than the middle element, it starts
the method again using only the bottom half of the sorted list. If the searched element is
less than the middle element, it starts the method again using only the top half of the
sorted list.
3 What is the best case and Average case analysis of shell sort?
 Best case Analysis – O(N log N)
 Average case Analysis – O(N1 . 5)
Differentiate linear search and binary search.
Linear search Binary search
Linear search is easy but takes more time Binary search it start searching from middle,
to search an element as it compare all if the searching element is not found in
element sequentially middle then it goes to left or right and vice
versa.and hence take less time than linear
search
Iterative in nature Divide and conquer in nature
Linear search requires O(n)times Binary search is very best in time and
efficiency. It requires O(log n)times
5 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 External sorting
6 What is meant by external sorting? (Dec 19)
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
7 What is meant by internal sorting? (Dec 19)
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.
8 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
9 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.
10 What is meant by selection sort? /Steps involved in selection sort (Dec 20)
It will first find the smallest element in the array and swap it with the element in
St. Joseph’s College of Engineering
Page 33 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
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.
11 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.
12 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.
13 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.
14 What are the advantages of selection sort?
 It is simple and easy to implement.
 It can be used for small data sets.
 It is 60 percent more efficient than bubble sort.
15 What is linear search?
Linear search is the simplest searching method, which checks each element in a list
sequentially until it finds a specified element. The input to the linear search method is a
sequence and the item that needs to be searched. The output is true if the specified item is
within the provided sequence or false if it is not in the sequence. The complexity of linear
search is O (n).
16 What is meant by Shell sort?
The shell sort, sometimes called the “diminishing increment sort,” improves on the
insertion sort by breaking the original list into a number of smaller sublists, each of which
is sorted using an insertion sort. The unique way that these sub lists are chosen is the key
to the shell sort. Instead of breaking the list into sub lists of contiguous items, the shell sort
uses an increment i, sometimes called the gap, to create a sub list by choosing all items that
are i items apart.
17 What is meant by Radix Sort? Or Define Radix Sort.(Nov/Dec 19)
A multiple pass distribution sort algorithm that distributes each item to a bucket according
to part of the item's key beginning with the least significant part of the key. After each
pass, items are collected from the buckets, keeping the items in order, then redistributed

St. Joseph’s College of Engineering


Page 34 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
according to the next most significant part of the key.
18 List some popular sorting methods.
 Bubble sort
 Bucket sort
 Insertion sort
 Merge sort
 Quick sort
 Selection sort
 Shell sort
19 What is Hashing?
Hashing is a technique used to identify the location of an identifier ‘x’ in the memory by
some arithmetic functions like f(x), which gives address of ‘x’ in the table.
20 Explain Hash Function.
Hash Function takes an identifier and computes the address of that identifier in the
hash table.
A simple Hash function :
HASH (KEYVALUE) = KEYVALUE MOD TABLESIZE
21 Mention Different types of popular hash function.
 Division method
 Square method
 Folding method
22 Define Collision.
When two different keys compute in the same location or address in the hash table
through any one of the hashing function then it is termed as collision.
23 Mention Different types of collision resolving techniques.
The collision resolving techniques are:
 Separate chaining.
 Open Addressing
 Linear Probing
 Quadratic Probing
 Double Hashing.
24 Define Separate Chaining
Separate Chaining is a technique used to avoid collision, where a linked list is used to store
the keys which fall into the same address in the hash table.
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.

St. Joseph’s College of Engineering


Page 35 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
26 What are the uses of hash table?
 Compilers can use hash table to keep track of declared variable in source code.
 A hash table is useful for any graph theory problem where nodes have real names
instead of numbers.
 A third use of hash table is in program that plays games.
 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 is the need of Extendible Hashing method?
Brief about Extendible Hashing. (May 19)
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.
30 State the complexity of binary search. (Dec 18)
Time Complexity of Binary Search O (log n)
31 What is double Hashing?
 Double hashing is a collision resolving technique in Open Addressed Hash tables.
 Double hashing uses the idea of applying a second hash function to key when a
collision occurs. Double hashing can be done using :
(hash1(key) + i * hash2(key)) % TABLE_SIZE
Here hash1() and hash2() are hash functions and TABLE_SIZE is size of hash table.
(We repeat by increasing i when collision occurs)
32 What are the advantage and disadvantage of separate chaining and linear probing? (Dec
18)(Dec 20)
Advantages of separate chaining
 Simple to Implement
 Hash Table Capacity Not Limited
 Robust technique
Disadvantages of separate chaining
 Cost of maintaining linked list is high.
Advantages of Linear Probing
 Requires less memory than Separate Chaining because no pointers are used.
 Simpler to implement than Quadratic or Double Hashing.
Disadvantages of Linear Probing
St. Joseph’s College of Engineering
Page 36 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
 Elements begin to cluster together in groups of adjacent array locations
 Causes "primary clustering" in which there are large blocks of occupied cells within
the hash table. There are "holes" when an element is removed and it is difficult to
determine when to stop looking through the hash table.
33 Compare linear search and binary search. (May 19)
Basis for comparison Linear search Binary search
Time Complexity O(N) O(log 2 N)
Best case time First Element O(1) Center Element O(1)
Prerequisite for an array No required Array must be in sorted order
Worst case for N number of N comparisons are required Can conclude after only log2N
elements comparisons
Can be implemented on Array and Linked list Cannot be directly
implemented on linked list
Insert operation Easily inserted at the end of Require processing to insert
list at its proper place to maintain
a sorted list.
Algorithm type Iterative in nature Divide and conquer in nature
Usefulness Easy to use and no need for Anyhow tricky algorithm and
any ordered elements. elements should be organized
in order.
UNIT-V / PART-B
1 With example explain the binary search technique.Compare Binary and Linear search
(Dec 20)
2 Explain the insertion sort with its time complexity .Sort the following sequence using
Insertion sort 3,10,4,2,8,6,5,1 (Dec 20)
3 State and explain the shell sort. State and explain the algorithm for shell sort. Sort the
elements using shell sort. (Dec 18)
4 Explain separate chaining and extendible hashing.
5 i) Explain the common collision resolution strategies in open address hashing. (Dec 18)
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. Or Write an algorithm to implement
selection sort with suitable example. (Dec 19)(Dec 20)
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 (Dec 18)
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 and extendible hashing. (Dec 18)
St. Joseph’s College of Engineering
Page 37 of 38
CS8391- Data Structures Department of EIE & ICE 2021-
2022
When do you perform rehashing? Illustrate with example. (May 19)
11 Distinguish between linear search and binary search. State and explain the algorithms for
both the search with example. (Dec 18)
12 Write an algorithm for binary search with suitable example.(Dec 19)
13 Explain Open Addressing in detail. (Dec 18)
14 Consider a hash table with 9 slots. The hash function is h(k) = k mod 9. The following keys
are inserted in the order 5, 28, 19, 15, 20, 33, 12, 7, 10. Draw the contents of the hash table
when the collisions are resolved by
i) Chaining
ii) Linear Probing
iii) Double Hashing. The second hash function h 2(x) = 7 – (x mod 7) (May 19) (Dec
20)
15 i) Write a function to perform merge sort. Give example.
ii) Write a routine for insertion sort. Sort the following sequence using insertion
sort. 3, 10, 4, 2, 8, 6, 5, 1
16 Indicate whether you use an Array, Linked List or Hash Table to store data in each of the
following cases. Justify your answer. (May 19)
i) A list of employee records need to be stored in a manner that is easy to find max or
min in the list
ii) A library needs to maintain books by their ISBN number. Only thing important is
finding them as soon as possible.
iii) A data set needs to be maintained in order to find the median of the set quickly

St. Joseph’s College of Engineering


Page 38 of 38

You might also like