Data Structure Interview Questions
Data Structure Interview Questions
Linear Data Structure: A data structure is called linear if all of its elements are
arranged in the sequential order. In linear data structures, the elements are stored in
a non-hierarchical way where each item has the successors and predecessors except
the first and last element.
Non-Linear Data Structure: The Non-linear data structure does not form a
sequence i.e. each item or element is connected with two or more other items in a
non-linear arrangement. The data elements are not arranged in the sequential
structure.
o Compiler Design,
o Operating System,
o Database Management System,
o Statistical analysis package,
o Numerical Analysis,
o Graphics,
o Artificial Intelligence,
o Simulation
4) What is the difference between file structure
and storage structure?
Difference between file structure and storage structure:
The main difference between file structure and storage structure is based on memory
area that is being accessed.
7) What is a Stack?
Stack is an ordered list in which, insertion and deletion can be performed only at one
end that is called the top. It is a recursive data structure having pointer to its top
element. The stack is sometimes called as Last-In-First-Out (LIFO) list i.e. the element
which is inserted first in the stack will be deleted last from the stack.
8) List the area of applications where stack data
structure can be used?
o Expression evaluation
o Backtracking
o Memory Management
o Function calling and return
PUSH: PUSH specifies that data is being "inserted" into the stack.
POP: POP specifies data retrieval. It means that data is being deleted from the stack.
o Increment the variable top so that it can refer to the next memory allocation
o Copy the item to the at the array index value equal to the top
o Repeat step 1 and 2 until stack overflows
Pop:
16)What is an array?
Arrays are defined as the collection of similar types of data items stored at
contiguous memory locations. It is the simplest data structure in which each data
element can be randomly accessed by using its index number.
17) How to reference all the elements in a one-
dimension array?
It can be done by using an indexed loop such that the counter runs from 0 to the
array size minus one. In this manner, you can reference all the elements in sequence
by using the loop counter as the array subscript.
o Row-Major Order: In row-major ordering, all the rows of the 2D array are stored into
the memory contiguously. First, the 1st row of the array is stored into the memory
completely, then the 2nd row of the array is stored into the memory completely and
so on till the last row.
o Column-Major Order: In column-major ordering, all the columns of the 2D array are
stored into the memory contiguously. first, the 1st column of the array is stored into
the memory completely, then the 2nd row of the array is stored into the memory
completely and so on till the last column of the array.
o node data
o pointer to the next node in sequence (next pointer)
o pointer to the previous node (previous pointer).
o Queues are widely used as waiting lists for a single shared resource like a printer,
disk, CPU.
o Queues are used in the asynchronous transfer of data (where data is not being
transferred at the same rate between two processes) for eg. pipes, file IO, sockets.
o Queues are used as buffers in most of the applications like MP3 media player, CD
player, etc.
o Queues are used to maintain the playlist in media players to add and remove the
songs from the play-list.
o Queues are used in operating systems for handling interrupts.
30) What are the drawbacks of array
implementation of Queue?
o Memory Wastage: The space of the array, which is used to store queue elements,
can never be reused to store the elements of that queue because the elements can
only be inserted at front end and the value of front might be so high so that, all the
space before that, can never be filled.
o Array Size: There might be situations in which, we may need to extend the queue to
insert more elements if we use an array to implement queue, It will almost be
impossible to extend the array size, therefore deciding the correct array size is always
a problem in array implementation of queue.
o General Tree
o Forests
o Binary Tree
o Binary Search Tree
o Expression Tree
o Tournament Tree
1 Search keys cannot repeatedly be stored. Redundant search keys can be present.
2 Data can be stored in leaf nodes as well as internal Data can only be stored on the leaf nodes.
nodes
3 Searching for some data is a slower process since Searching is comparatively faster as data
data can be found on internal nodes as well as on the only be found on the leaf nodes.
leaf nodes.
4 Deletion of internal nodes is so complicated and Deletion will never be a complexed process
time-consuming. element will always be deleted from the
nodes.
5 Leaf nodes cannot be linked together. Leaf nodes are linked together to make
search operations more efficient.
o Graphs are used in circuit networks where points of connection are drawn as vertices
and component wires become the edges of the graph.
o Graphs are used in transport networks where stations are drawn as vertices and
routes become the edges of the graph.
o Graphs are used in maps that draw cities/states/regions as vertices and adjacency
relations as edges.
o Graphs are used in program flow analysis where procedures or modules are treated
as vertices and calls to these procedures are drawn as edges of the graph.
54) In what scenario, Binary Search can be used?
Binary Search algorithm is used to search an already sorted list. The algorithm follows
divide and conqer approach