CS3301 - Data Structures
CS3301 - Data Structures
lOMoARcPSD|31565132
Question Bank
Vision of Institution
To build Jeppiaar Engineering College as an Institution of Academic Excellence in Technical
education and Management education and to become a World Class University.
Mission of Institution
M3 To equip students with values, ethics and life skills needed to enrich their lives and
enable them to meaningfully contribute to the progress of society
M4 To prepare students for higher studies and lifelong learning, enrich them with the
practical and entrepreneurial skills necessary to excel as future professionals and
contribute to Nation’s economy
M3 To produce engineers with good professional sKills, ethical values and life skills for the
betterment of the society.
PEO3 Apply ethical Knowledge for professional excellence and leadership for the
betterment of the society.
PEO4 Develop life-long learning skills needed for better employment and
entrepreneurship
lOMoARcPSD|31565132
SYLLABUS
UNIT I LISTS 9
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 ADT – Radix Sort – Multilists.
TEXT BOOKS:
1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in C”, 2nd Edition, Pearson
Education,2005.
2. Kamthane, Introduction to Data Structures in C, 1st Edition, Pearson Education, 2007
REFERENCES:
1. Langsam, Augenstein and Tanenbaum, Data Structures Using C and C++, 2nd Edition,
Pearson Education, 2015.
2. Thomas H. Cormen, Charles E. Leiserson, Ronald L.Rivest, Clifford Stein, Introduction to
Algorithms", Fourth Edition, Mcgraw Hill/ MIT Press, 2022.
3. Alfred V. Aho, Jeffrey D. Ullman,John E. Hopcroft ,Data Structures and Algorithms, 1st
edition, Pearson, 2002.
4. Kruse, Data Structures and Program Design in C, 2nd Edition, Pearson Education, 2006.
lOMoARcPSD|31565132
INDEX
UNIT -II 1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in
C”, 2nd Edition, Pearson Education,1997.
2. Reema Thareja, “Data Structures Using C”, Second Edition , Oxford
University Press, 2011
UNIT -III 1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in
C”, 2nd Edition, Pearson Education,1997.
2. Reema Thareja, “Data Structures Using C”, Second Edition ,
Oxford University Press, 2011
UNIT -IV 1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in
C”, 2nd Edition, Pearson Education,1997.
2. Reema Thareja, “Data Structures Using C”, Second Edition ,
Oxford University Press, 2011
UNIT -V 1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in
C”, 2nd Edition, Pearson Education,1997.
2. Reema Thareja, “Data Structures Using C”, Second Edition , Oxford
University Press, 2011
lOMoARcPSD|31565132
UNIT I
doubly-linked lists 67
S. Question
No
.
1 What is a data structure?
• A data structure is a method for organizing and storingdata which would allow
efficient
data retrieval and usage.
• A data structure is a way of organizing data thatconsiders not only the
items stored, but
also their relationships to each other.
Every items is related to its previous Every item is attached withmany other
and next item items
lists from singly linked lists, the last node’s next field is connected to the first
node.
struct polynomial
{
int coefficient;int exponent;
struct polynomial *next;
};
33 Difference between linear linked list and circular linked list(apr/may 2019)
Linked list are used to create trees and graphs. Circular linked list : In circular linked list
the last node address part holds the address of the first node hence forming a circular chain
like structure ...............................................................................Linked
list is a linear data structure which consists of group of nodes in a sequence
The header node is the very first node of the linked list. Sometimes a
dummy value such - 999 is stored in the data field of header node. This node is useful for
getting the starting address of the linked list.
44 What is static linked list? State any two applications of it.
➢ The linked list structure which can be represented using arrays iscalled static linked list.
➢ It is easy to implement, hence for creation of small databases, itis useful
.➢ The searching of any record is efficient, hence the applications in which the record need to
be searched quickly, the static linked list areused.
lOMoARcPSD|31565132
PART-B
1 Explain the various operations of the list ADT with examples C311.1
BTL 2
2 Write the program for array implementation of lists C311.1 BTL 5
UNIT II
Stack ADT 78
Operations 79
Circular Queue 95
S. Question
No.
1 Define Stack.
A stack is an ordered list in which all insertions and deletions are made at one
end, called
the top. It is an abstract data type and based on the principle of LIFO (Last In First Out).
{
printf(“\n Stack is empty.\n”);getch();
exit(1);
}
else
{
int temp;
temp=top→element; /* retreiving the top element*/top=top→next; /*
Updating the stack pointer */ return temp; /* returning the popped value
*/
}
}
9 Define queue.
It is a linear data structure that maintains a list ofelements such that
insertion happens at
rear end and deletion happens at front end. FIFO – First In First
Out principle
front = front→next;return i;
}
}
• Dequeue – removing or deleting an element from the queueat the front end
lOMoARcPSD|31565132
If the queue is not empty, this function removes theelement from the
front of the queue, else it prints “UnderFlow”.
void dequeue(int queue[], int& front, int rear)
{ if(front == rear) // Queue is empty
printf(“UnderFlow\n”);
else {
queue[front] = 0; // Delete the front elementfront++;
}
}
STACK QUEUE
Insertion and deletion aremade at one Insertion at one end rearand deletion
end. at other endfront.
The element inserted last would be The element inserted first would be
removed first. SoLIFO structure. removed first. SoFIFO structure.
Postfix :ab+cd+*f/
Prefix :/*+ab+cdf
A-B+C-D+
Each push() and pop() operation increases and decreases the size of the stack
by 1, respectively.
In recursive algorithms, stack data structures is used to store the return address when a
recursive call is encountered and also to store
the values of all the parameters essential to the current state of the function.
38 Write down the function to insert an element into a queue, inwhich the queue is
implemented as an array
Q – Queue X – element to added to the queue Q IsFull(Q) – Checks and true if Queue Q is
full Q->Size - Number of elements in the queue Q Q->Rear – Points to last element of the
queue Q Q->Array –array used to store queue elements void enqueue (int X, Queue Q) {
if(IsFull(Q)) Error (“Full queue”); else { Q->Size++; Q->Rear = Q-
>Rear+1; Q->Array[ Q->Rear ]=X; } }
PART-B
1 Explain Stack ADT and its operations C311.2 BTL5
2 Explain array based implementation of stacks C311.2 BTL5
UNIT III
B-Tree 149
B+ Tree 154
S. Question
No.
2 Define tree?
A tree is a data structure, which represents hierarchicalrelationship between
individual data items.
3 Define leaf?
In a directed tree any node which has out degree o is called a terminal
node or a leaf.
5 List out the steps involved in deleting a node from a binary search tree.
1. t has no right hand child node t->r == z
2. t has a right hand child but its right hand child node hasno left sub tree
t->r->l == z
3.t has a right hand child node and the right hand child node has a left hand
child node t->r-
>l != z
7 What are the steps to convert a general tree into binary tree?
* use the root of the general tree as the root of the binary tree
* determine the first child of the root. This is the leftmost nodein the general tree at
the next
level
* insert this node. The child reference of the parent node refersto this node
* continue finding the first child of each parent node and insertit below the parent
node with the
child reference of the parent to this node.
* when no more first children exist in the path just used, moveback to the parent of
the last node
entered and repeat the above process. In other words,determine the first
sibling of the last
node entered.
* complete the tree for all nodes. In order to locate where thenode fits you must
search for the
lOMoARcPSD|31565132
first child at that level and then follow the sibling references to a nil where the
next sibling can
be inserted. The children of any sibling node can be insertedby locating the parent
and then
inserting the first child. Then the above process is repeated.
The length of the path is the number of edges on the path. In a treethere is exactly
one path form the root to each node.
23 Define binary tree and give the binary tree node structure.
lOMoARcPSD|31565132
33 Define sibling?
Nodes with the same parent are called siblings. The nodes withcommon parents are called
siblings.
34 What are the two methods of binary tree implementation?
Two methods to implement a binary tree are, a. Linear representation.
b. Linked representation
35 List out few of the Application of tree data-structure?
Ø The manipulation of Arithmetic expressionØ Used for Searching
Operation
Ø Used to implement the file system of several popular operatingsystems
Ø Symbol Table constructionØ Syntax analysis
39 What is B Tree
A B-tree is a tree data structure that keeps data sorted and allows searches, insertions, and
deletions in logarithmic amortized time. Unlike self-balancing binary search trees, it is
optimized for systems that read and write large blocks of data. It is most commonly used in
database and file systems.
Important properties of a B-tree: • B-tree nodes have many more than two children. • A B-tree
node may contain more than just a single element.
UNIT IV
S.N
o.
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).
3 Define NP
NP is the class of decision problems for which a given proposed solution for a
given input can be checked quickly to see if it is really a solution.
10 What is a loop?
An edge of a graph which connects to itself is called a loop or
sling.
28 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 witha single Vertex. Hence, the total number of
edges added in graph is
(n-1)+(n-2)+(n-3)+…+1 =n*(n-1)/2.
PART-B
1 Explain the various representation of graph with example in detail? C311.4 BTL5
2 Define topological sort? Explain with an example? C311.4 BTL5
6 Write and explain the prim’s algorithm and depth C311.4 BTL5
firstsearch algorithm.
7 For the graph given below, construct Prims algorithm C311.4 BTL5
2
4 1 2 1 7
8 4 5
3 5 1 4 6
1 2
6 7
8 Explain the breadth first search algorithm C311.4 BTL5
9 Write the algorithm to compute lengths of shortest path C311.4 BTL5
UNIT V
S.
No. PART-B
1 Define sorting
Sorting arranges the numerical and alphabetical data present in a list in a specific
order or sequence. There are a number of sorting techniques available. The algorithms
can be chosen based on the following factors
• Size of the data structure
• Algorithm efficiency
Programmer’s knowledge of the technique
5 Define hashing.
Hash function takes an identifier and computes the address of that identifier in
the hash table using some function
lOMoARcPSD|31565132
11 what is insertion sort? How many passes are required for the elements to be
sorted ?
one of the simplest sorting algorithms is the insertion sort. Insertion sort consist of N-1
passes . For pass P=1 through N-1 , insertion sortensures that the elements in positions
0 through P-1 are in sorted order .It makes use of the fact that elements in position 0
through P-1 are already known to be in sorted order .
17 What are the three cases that arise during the left to right scan in quick sort?
1. I and j cross each other
2. I and j do not cross each other
3. I and j points the same position
19 What is sorting?
Sorting is the process of arranging the given items in a logical order. Sorting is an
example where the analysis can be precisely performed.
lOMoARcPSD|31565132
20 What is mergesort?
The mergesort algorithm is a classic divide conquer strategy. The problem is divided
into two arrays and merged into single array
The main idea behind the selection sort is to find the smallest entryamong in
a(j),a(j+1),… ..................... a(n) and then interchange it with a(j).
This process is then repeated for each value of j.
32 Define searching
Searching refers to determining whether an element is present in a given list of
elements
or not. If the element is present, the search is considered as successful, otherwise it is
considered as an unsuccessful search. The choice of a searching technique is based on the
following factors
a. Order of elements in the list i.e., random or sorted
b. Size of the list
array. If the key match, then a matching element has been found andits index, or
Position, is returned.
Otherwise, if the search key is less than the middle element, then thealgorithm repeats its
action on the sub-array to the left of the middle element or, if thesearch key is
greater, on
the sub-array to the right.
39 What is Rehashing?
If the table is close to full, the search time grows and maybecome equal to
the table size.
When the load factor exceeds a certain value (e.g. greater than 0.5) we do
Rehashing: Build a second table twice as large as the originaland rehash there all
the keys of the original table.
Rehashing is expensive operation, with running time O(N)However, once
done, the new hash table will have good performance.
The problem: in ordinary hashing several disk blocks may be examined to find
an element -a time consuming process.
Extendible hashing: no more than two blocks are examined.
46 What is the output of selection sort after the 2nd iteration given thefollowing sequence?
16 3 46 9 28 14
Ans: 3 9 46 16 28 14
47 How does insertion sort algorithm work?
In every iteration an element is compared with all the elements before it. While comparing if it is
found that the element can be inserted at a suitable position, then space is created for it by shifting
the other elements one position up and inserts the desired element at the suitable position. This
procedure is repeated for all the elements in the list until we get the sorted elements.
48 What operation does the insertion sort use to move numbers from theunsorted section to
the sorted section of the list?
The Insertion Sort uses the swap operation since it is ordering numberswithin a single list.
49 How many key comparisons and assignments an insertion sort makes in its worst case?
The worst case performance in insertion sort occurs when the elements of the input array are in
descending order. In that case, the first pass requires one comparison, the second pass requires two
comparisons, third pass three
comparisons,….kth pass requires (k-1), and finally the last pass requires (n-
lOMoARcPSD|31565132
PART -B
1 Explain the sorting algorithms C311.5 BTL2