You are on page 1of 69

TCS Preparation Camp

(Data Structures)
Vijay Kumar Dwivedi
Assistant Professor
UCER, Prayagraj
Mobile: 9235668045
Email: vijay.kr.dwivedi@gmail.com
Question 1
Tell how to check that linked list is circular?
Question 1
Tell how to check that linked list is circular?
Ans:
• A linked list is called circular if it is not NULL-
terminated and all nodes are connected in the
form of a cycle.

• The idea is to store head of the linked list and


traverse it. If we reach NULL, linked list is not
circular. If reach head again, linked list is
circular.
Question 2

Why is it difficult to store linked list in an array?


Question 2

Why is it difficult to store linked list in an array?


Ans:
• Because of defragmentation, when node should
be deleted.
• Limited size of array, even in case of dynamic
growth of array, lots of memory is wasted.
Question 3
What is Data Structure?
Question 3
What is Data Structure?
Ans:
• A data structure is a particular way of
organizing data in a computer so that it can be
used effectively.
• For example, we can store a list of items
having the same data-type using
the array data structure.
Question 4
• Differentiate between Linear and Non Linear
Data Structures?
Question 5
List out the areas in which data structures are
applied extensively?
Question 5
List out the areas in which data structures are
applied extensively?
Ans:

Compiler Design

Operating System

Database Management System

Statistical Analysis Package

Numerical Analysis

Graphics

Artificial Intelligence
Question 6

Define ADT
Question 6

Define ADT

Ans:
 ADT stands for Abstract Data Type
 ADT is defined by set of values and set of operations
 The definition of ADT only mentions what operations are to
be performed but not how these operations will be
implemented.
 It does not specify how data will be organized in memory
and what algorithms will be used for implementing the
operations.
 It is called “abstract” because it gives an implementation-
independent view.
Question 7

Minimum number of queues needed


to implement the priority queue?
Question 7

Minimum number of queues needed


to implement the priority queue?
Ans: Two
One queue is used for the actual
storing of data, and the other one is
used for storing the priorities.
Question 8
What is the data structures used to perform
recursion?
Question 8
What is the data structures used to perform
recursion?
Ans: Stack
Question 9

What do you mean by Polish and Reverse
Polish notations of an expression?
Question 9

What do you mean by Polish and Reverse
Polish notations of an expression?

Ans:
 Polish (Prefix)
 Reverse Polish (Postfix)
Question 10
Convert the expression
((A + B) * C - (D - E) ^ (F + G))
to equivalent Prefix and Postfix notations.
Question 10
Convert the expression
((A + B) * C - (D - E) ^ (F + G))
to equivalent Prefix and Postfix notations.
Ans:
Prefix Notation: – * +ABC^ – DE + FG
Postfix Notation: AB + C * DE – FG + ^ -
Question 11
List out few applications of the tree
data-structure?
Question 11
List out few applications of the tree
data-structure?
Ans:

The manipulation of Arithmetic
expression

Symbol Table construction

Syntax analysis
Question 12
List out few of the applications that make use of
Multilinked Structures?
Question 12
List out few of the applications that make use of
Multilinked Structures?
Ans: Sparse matrix, Index generation.
Question 13

What is sparse matrix?

Question 13

What is sparse matrix?

Ans:

A matrix is a two-dimensional data object
made of m rows and n columns, If most of
the elements of the matrix have 0 value,
then it is called a sparse matrix.
Question 14

Differentiate between Array and Linked
List?

Question 15
What is the type of the algorithm used in
solving the 8 Queens problem?
Question 15
What is the type of the algorithm used in
solving the 8 Queens problem?
Ans: Backtracking.
Question 16

What is AVL Tree?
Question 16

What is AVL Tree?

Ans:
 Named after their inventor Adelson, Velski &
Landis, AVL trees are height balancing binary
search tree.
 It checks the height of the left and the right
sub-trees and assures that the difference is
not more than 1. This difference is called the
Balance Factor.
Question 17

What do you mean by Hashing?

Question 17

What do you mean by Hashing?

Ans:
 Hashing is an important Data Structure which
is designed to use a special function called the
Hash function which is used to map a given
value with a particular key for faster access of
elements.
 The efficiency of mapping depends of the
efficiency of the hash function used.
Question 18

Enumerate various types of hash function?
Question 18

Enumerate various types of hash function?

Ans:
 Division method

In this the hash function is dependent upon the
remainder of a division.
 Mid square method

In this method firstly key is squared and then mid
part of the result is taken as the index.
 Digit folding method

In this method the key is divided into separate
parts and by using some simple operations these
parts are combined to produce a hash key.
Question 19

Draw an AVL Tree of the word
“COMPUTER”
Question 19

Draw an AVL Tree of the word
“COMPUTER”
Question 20

Explain different type of rotations in AVL
Question 20

Explain different type of rotations in AVL

Ans:

L-L Rotation


R-R Rotation
Question 20 Contd...

Explain different type of rotations in AVL

Ans: L-R Rotation


Question 20 Contd...

Explain different type of rotations in AVL

Ans: R-R Rotation


Question 21

What is Collision?

Question 21

What is Collision?

Ans:
 Since a hash function gets us a small number
for a key which is a big integer or string, there
is a possibility that two keys result in the same
value.
 The situation where a newly inserted key
maps to an already occupied slot in the hash
table is called collision
 It must be handled using some collision
handling technique.
Question 22

Different type of Collision Resolution
Technique?
Question 22

Different type of Collision Resolution
Technique?

Ans: Mainly two methods to handle collision:

1) Separate Chaining
 The idea is to make each cell of hash table point to a linked
list of records that have same hash function value.

2) Open Addressing
 Linear Probing: In linear probing, we linearly probe for next
slot.
 Quadratic Probing We look for i2‘th slot in i’th iteration.
 Double Hashing We use another hash function hash2(x)

and look for i*hash2(x) slot in i’th rotation.


Question 23

What is Graph?

Question 23

What is Graph?

Ans:

A Graph is a non-linear data structure
consisting of nodes and edges.

The nodes are sometimes also referred to
as vertices and the edges are lines or arcs
that connect any two nodes in the graph.

More formally a Graph can be defined as
 A Graph consists of a finite set of vertices(or
nodes) and set of Edges which connect a pair
of nodes.
Question 24

Differentiate between Tree and Graph?

Question 24


Question 25

Differentiate between DFS and BFS?


Question 25


Question 26

What is Spanning Tree?

Question 26

What is Spanning Tree?

Ans:

A spanning tree is a subset of Graph G,
which has all the vertices covered with
minimum possible number of edges.
Hence, a spanning tree does not have
cycles and it cannot be disconnected..


Question 27
What are the various operations
that can be performed on
different Data Structures?
Question 27
What are the various operations that can
be performed on different Data
Structures?
Ans:
1. Traversing
2. Searching
3. Inserting
4. Deleting
5. Sorting
6. Merging
Question 28
What is Stack and where it can be used?
Question 28
What is Stack and where it can be used?
Ans:

A stack is defined by having a LIFO (Last In First Out)
ordering principle. The first element added to a stack
is the last to be removed. Equivalently, the last
element added to a stack is the first to be removed.
Operations that act on a stack have a unique
terminology:

Push - add a new element to the stack.

Pop - remove an element from the stack.

Uses of Stack - undo\redo operation in word
processors, Expression evaluation and syntax
parsing, etc.
Question 29
What is a Linked List and what are its
types?
Question 29
What is a Linked List and what are its
types?
Ans:
A Linked List is a linear data structure made up
of multiple node elements that are linked
together using pointers.
Linked Lists can be dynamic in size, and have
more optimal insertion and deletion than arrays.
There are four common types of Linked List:

Singly Linked List

Doubly Linked List

Circular Linked List

Doubly Circular Linked List
Question 30
How to implement a stack using queue?
Question 30
How to implement a stack using queue?
Ans:

In push operation, the new element is
always enqueued to q1.

In pop() operation, if q2 is empty then
all the elements except the last, are
moved to q2.

Finally the last element is dequeued
from q1 and returned.
Question 31

Define Binary Search Tree?

Question 31

Define Binary Search Tree?

Ans: A binary search tree (BST) is a node
based binary tree data structure which has the
following properties.

• The left subtree of a node contains only nodes
with keys less than the node’s key.

• The right subtree of a node contains only nodes
with keys greater than the node’s key.
 • Both the left and right subtrees must also be
binary search trees.

Question 32

What are different methods of Traversing a
Binary Tree?

Question 32

What are different methods of Traversing a
Binary Tree?

Ans:
 InOrder Traversal
 PreOrder Traversal
 Post Order Traversal

Question 33

In Order Traversal ?

PreOrder Traversal ?

Post Order Traversal ?
Question 33

In Order Traversal

PreOrder Traversal

Post Order Traversal


Ans:


a) Inorder (Left, Root, Right) : 4 2 5 1 3

(b) Preorder (Root, Left, Right) : 1 2 4 5 3

(c) Postorder (Left, Right, Root) : 4 5 2 3 1

You might also like