CS8391-Data Structures Department of CSE & IT 2020 - 2021
CS8391-Data Structures Department of CSE & IT 2020 - 2021
Insert
Make empty
Remove
Next
Previous
Find kth
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
the node contains some data and a pointer linked list where the node contains some
to the next node in the list data and a 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
pointer) pointers)
Complexity of insertion and deletion at a Complexity of insertion and deletion at a
known position is O(n) known position is O(1)
If we need to save memory and searching 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,
stacks heaps, binary trees.
38 What is static linked list? State any two applications of it. (May 15)
In Static Linked List, each node is allocated memory when it is to be inserted
dynamically. Each node contains a pointer pointing to the next node. But in Array List,
we store values in an array and have another array storing the indices of the nodes
which correspond to the next item in the list. There is one key array and one link array.
Since the memory allocated to an array is constant, it is static. The application of static
linked list is to implement stack, hash table and binary tree.
39 State the advantages of ADT.(Nov 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.
UNIT-I / PART-B
1 Explain in detail about the linked list implementation using an example. State the
problems in freeing list node.
2 Write a program to reverse a linked list using recursion.
3 Write a routine to merge given two sorted linked lists.(Dec 15)
4 Write an algorithm to insert an element into a linked list. Explain it with an example.
5 Write and explain the algorithm to copy a linked list.
6 What are the operations on singly linked list? Explain with an example.
7 Write a C code for singly linked list with insert, delete, and display operations using
structure pointers. (May 16, Nov 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)
10 Write a C program to concatenate two double linked lists.
11 Write an algorithm to insert a node at front and end of a circular linked list.
12 i) Make a comparison between a linked list and a linear array. Which one will you
prefer to use and when?
ii) Give the advantages and uses of circular linked lists.
13 Explain the applications of list.
14 Write a C program to perform addition, subtraction and multiplication operations on
polynomial using linked list. (May 15)
15 State the polynomial representation for 6x3+9x2+7x+1 using linked list. Write procedure
to add and multiply two polynomial and explain with suitable example. (Nov 18)
16 What are the various operations on array? Write a procedure to insert an element in the
middle of the array. (Nov 18)
17 Write a procedure to deleting the last node from a circular linked list. (Nov 18)
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
Stack ADT – Operations - Applications - Evaluating arithmetic expressions- Conversion of
Infix to postfix expression - Queue ADT – Operations - Circular Queue – Priority Queue -
deQueue – applications of queues.
UNIT-II / PART-A
1 What is stack?
A stack is a linear data structure in which the elements in a stack are added and
removed only from one end, which is called the TOP. Hence, a stack is called a LIFO
(Last-In-First-Out) data structure, as the element that was inserted last is the first one to
be taken out. Example: Pile of coins, a Stack of trays in cafeteria.
2 Where do we need stacks in computer science?
The answer is in function calls. In order to keep track of the returning point of each
active function, a special stack called system stack or call stack is used. Whenever a
function calls another function, the calling function is pushed onto the top of the stack.
This is because after the called function gets executed, the control is passed back to the
calling function.
3 What 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.
B C
D E F G
B C
D E F G
8 Define a full binary tree.
A full binary tree, is a tree in which all the leaves are on the same level and every non-
leaf node has exactly two children.
9 Define a complete binary tree.
A complete binary tree is a tree in which every non-leaf node has exactly two children
not necessarily to be on the same level.
10 State the properties of a Binary Tree.
Maximum No. of nodes on level n of a binary tree is 2^(n-1),where n>=1.
Maximum No. of nodes in a Binary tree of height is 2^(n-1),where n>=1.
For any non-empty tree,nl=nd+1 where nl is the number of leaf nodes and nd is the
no. of nodes of degree 2.
11 What are the different ways of representing a Binary Tree?
Linear Representation using Arrays.
Linked Representation using Pointers.
12 Define Traversal.
Traversal is an operation which can be performed on a binary tree is visiting all the
nodes exactly once.
In order: traversing the LST, visiting the root and finally traversing the RST.
Preorder: visiting root, traversing LST and finally traversing RST.
Post- order: traversing LST, then RST and finally visiting root.
13 Define a Binary Search Tree.
A Binary Search Tree is a special binary tree, which is either empty or if it is empty it
should satisfy the conditions given below:
Every node has a value and no two nodes should have the same value
(Values should be distinct).
The value in any left subtree is less than the value of its parent node.
The value in any right subtree is greater than the value of its parent node.
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 TL and TR as its
left and right subtrees, then T is height balanced if
1. TL and TR are height balanced.
2. | hL - hR | ≤ 1.
Where hl and hr are the height of TL and TR respectively.
20 What are the drawbacks of AVL trees?
The drawbacks of AVL trees are
Frequent rotations
The need to maintain balances for the tree’s nodes
Overall complexity, especially of the deletion operation.
21 What are the two alternatives that are used to construct a heap?
The two alternatives to construct a heap are
Bottom-up heap construction
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 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)
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
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
a b
c d
10 Consider a directed acyclic graph 'D' given in following graph. sort the nodes of 'D' by
applying topological sort on 'D' (Dec 14)
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?
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
to search an element as it compare all middle, if the searching element is not
element sequentially found in 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
b) External sorting
6 What is meant by external sorting?
External sorting takes place in the secondary memory of a computer, since the number
of objects to be sorted is too large to fit in main memory.
Example:
Merge sort
Multiday Merge
Polyphone Merge
7 What is meant by internal sorting?
An internal sort is any data sorting process that takes place entirely within the main
memory of a computer. This is possible whenever the data to be sorted is small enough
to all be held in the main memory.
Example:
Bubble sort, Insertion Sort, Heap sort, shell sort, quick sort.
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?
It will first find the smallest element in the array and swap it with the element in
the first position, then it will find the second smallest element and swap it with the
element in the second position, and it will keep on doing this until the entire array is
sorted. It is called selection sort because it repeatedly selects the next-smallest element
and swaps it into the right place.
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?
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 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.
1.Division method
2.Square method
3.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.
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.