Cs33 - Data Structures Questions and Answers
Cs33 - Data Structures Questions and Answers
PART A
2
Insertions and deletions are Insertions and deletions are carried
somewhat difficult out easily
It occupies less memory than a It occupies more memory
linked list for the same number of
elements
17. 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
3
22. State 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 parenthesis
24. Mention the advantages of representing stacks using linked lists than arrays
• It is not necessary to specify the number of elements to be stored in a stack
during its declaration, since memory is allocated dynamically at run time
when an element is added to the stack
• Insertions and deletions can be handled easily and efficiently
• Linked list representation of stacks can grow and shrink in size without
wasting memory space, depending upon the insertion and deletion that occurs
in the list
• Multiple stacks can be represented efficiently using a chain for each stack
4
restricted deque allows insertion at one end (it can be either front or rear) only. The
output restricted deque allows deletion at one end (it can be either front or rear) only.
30. Difference between Abstract Data Type, Data Type and Data Structure
• An Abstract data type is the specification of the data type which specifies the
logical and mathematical model of the data type.
• A data type is the implementation of an abstract data type.
• Data structure refers to the collection of computer variables that are connected
in some specific manner.
i.e) Data type has its root in the abstract data type and a data structure comprises a set
of computer variables of same or different data types
31. Define data type and what are the types of data type?
Data type refers to the kinds of data that variables may hold in the programming
language. Eg) int, float, char, double – C
The following are the types of data type:
• Built in data type- int, float, char, double which are defined by
programming language itself
• User defined data type- Using the set of built in data types user can define
their own data type
Eg) typedef struct student
{
int roll;
char name;
}S;
S s1;
Where S is a tag for user defined data type which defines the structure
student and s1 is a variable of data type S.
5
• A well-written modular program places certain dependencies in only one
routine, making changes easier
34. State the difference between primitive and non-primitive data types
Primitive data types are the fundamental data types. Eg) int, float, double, char
Non-primitive data types are user defined data types. Eg) Structure, Union and
enumerated data types
35. State the difference between persistent and ephemeral data structure
Persistent data structures are the data structures which retain their previous state
and modifications can be done by performing certain operations on it. Eg) Stack
Ephemeral data structures are the data structures which cannot retain its previous
state. Eg) Queues
6
• Real life line
• Calls to large companies
• Access to limited resources in Universities
• Accessing files from file server
PART – B
5. Write an algorithm for inserting and deleting an element from doubly linked list?
Explain linear linked implementation of Stack and Queue?
• Introduction to Doubly linked list
• Operations: insertion and deletion with algorithm
• Linked list implementation of Stack
• Linked list implementation of Queue
7
UNIT II – TREE STRUCTURES
PART A
1. Define a tree
A tree is a collection of nodes. The collection can be empty; otherwise, a tree
consists of a distinguished node r, called the root, and zero or more nonempty (sub) trees
T1, T2,…,Tk, each of whose roots are connected by a directed edge from r.
2. Define root
This is the unique node in the tree to which further sub-trees are attached.
4. Define leaves
These are the terminal nodes of the tree. The nodes with degree 0 are always the
leaves.
8
5. Define internal nodes
The nodes other than the root and the leaves are called internal nodes.
Here, node A is at level 0, nodes B and C are at level 1 and nodes D and E
are at level 2.
9
A tree may be defined as a forest in which only a single node (root) has no
predecessors. Any forest consists of a collection of trees.
10
21. What are the tasks performed while traversing a binary tree?
• Visiting a node
• Traverse the left sub-tree
• Traverse the right sub-tree
11
• Every node has a value and no two nodes should have the same value i.e) the
values in the binary search tree are distinct
• The values in any left sub-tree is less than the value of its parent node
• The values in any right sub-tree is greater than the value of its parent node
• The left and right sub-trees of each node are again binary search trees
32. Why it is said that searching a node in a binary search tree is efficient than that of a
simple binary tree?
In binary search tree, the nodes are arranged in such a way that the left node is
having less data value than root node value and the right nodes are having larger value
than that of root. Because of this while searching any node the value of the target node
will be compared with the parent node and accordingly either left sub branch or right sub
branch will be searched. So, one has to compare only particular branches. Thus searching
becomes efficient.
PART – B
12
• Operations of binary search tree: Insertion and Deletion
• Example
13
UNIT III – BALANCED TREES
PART – A
14
The height of left subtree minus height of right subtree is called balance
factor of a node in AVL tree.The balance factor may be either 0 or +1 or -1.The
height of an empty tree is -1.
8. Define Heap.
A heap is defined to be a complete binary tree with the property that the
value of each node is atleast as small as the value of its child nodes, if they exist.
The root node of the heap has the smallest value in the tree.
15
• The root is either a leaf or has between 2 and 3 children.
• All non-leaf nodes (except the root) have between 2 and 3 children.
• All leaves are at the same depth.
16
19. What do you mean by the term “Percolate up”?
To insert an element, we have to create a hole in the next available heap
location. Inserting an element in the hole would sometimes violate the heap order
property, so we have to slide down the parent into the hole. This strategy is
continued until the correct location for the new element is found. This general
strategy is known as a percolate up; the new element is percolated up the heap
until the correct location is found.
PART- B
17
UNIT IV – HASHING AND SET
PART – A
1. Define Hashing.
Hashing is the transformation of string of characters into a usually shorter
fixed length value or key that represents the original string. Hashing is used to
index and retrieve items in a database because it is faster to find the item using the
short hashed key than to find it using the original value.
18
6. What are the collision resolution methods?
• Separate chaining or External hashing
• Open addressing or Closed hashing
11. What are the types of collision resolution strategies in open addressing?
• Linear probing
• Quadratic probing
• Double hashing
19
clustering means that any key hashes into the cluster will require several attempts
to resolve the collision and then it will add to the cluster.
20
A relation R is defined on a set S if for every pair of elements (a,b), a,b ε S,
aRb is either true or false. If aRb is true, then we say that a is related to b.
PART – B
21
1. Explain hashing with example.
• Hashing techniques
• Example
22
UNIT V –GRAPHS
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).
5. What is a loop?
An edge of a graph which connects to itself is called a loop or sling.
23
8. Define outdegree 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.
18. What are the two traversal strategies used in traversing a graph?
a. Breadth first search
b. Depth first search
24
20. Name two algorithms two find minimum spanning tree
Kruskal’s algorithm
Prim’s algorithm
22. List the two important key points of depth first search.
i) If path exists from one node to another node, walk across the edge – exploring
the edge.
ii) If path does not exist from one specific node to any other node, return to the
previous node where we have been before – backtracking.
25
PART – B
26