Professional Documents
Culture Documents
Answers
OCT 18 • ENGINEERING SAMPLE PAPERS • 1000 VIEWS • 0 COMMENTS
Data Structures and Algorithm is considered as one of the important subject for the
interviews, find the latest and most asked Data structures questions and answers in a
interview with all the fundamental concepts. Questions has been listed after consulting
from different technical recruiters and successful candidates. Still if it need any
improvement please do let us know through the comment section. You can give your
valuable feedback through the comments. Any type of suggestions will be highly
appreciated.
Introduction : Data structure is the way or concept of storing and organizing data
storing data using the Data structures techniques. Some data structures are used for
some highly specialized application. Data structures are the main technique or concept
for designing an efficient algorithm. In this section, there are lots of Data Structure
questions and answers which will surely help to build some basic concepts related to
Data Structure.
data structure
Operating System
Compiler Design
Artificial Intelligence
Numerical Analysis
Graphics
Simulation
(b) What are the major data structures used in the following areas : RDBMS,
(c)If you are using C language to implement the heterogeneous linked list,
The heterogeneous linked list includes different data types in its nodes and we need a
link, pointer to connect them. It is not possible to use ordinary pointers for this. So we
use void pointer. Void pointer has the ability of storing pointer to any type as it is
Two. ( One queue is used for actual storing of data and another for storing priorities.)
whom to return when the function has to return. Recursion uses system stack for
storing the return addresses of the function calls. Each and every recursive function has
its equivalent iterative function. Even when such equivalent iterative procedures are
Straight Merging
Natural Merging
Polyphase Sort
Syntax analysis
Direct method
Subtraction method
Modulo-Division method
Digit-Extraction method
Mid-Square method
Folding method
Pseudo-random method
(i)Write the types of Collision Resolution Techniques and the methods used in
Open addressing
Overflow block
Closed addressing
Linked list
Binary tree
(j)In RDBMS, what is the efficient data structure used in the internal
storage representation?
B+ tree. As in B+ tree, leaf node stores all the data, that’s why the Searching is easier.
It is a tree associated with a network. All the nodes of the graph appear on the tree for
one time. A minimum spanning tree is a spanning tree organized so that the total edge
3. Does the minimum spanning tree of a graph give the shortest distance
No. Minimal spanning tree assures that the total weight of the tree is kept at
its minimum. But the distance between any two nodes involved in the minimum-
queue and retrieved from the other end of the queue, while the removal and insertion
5.What is the difference between storing data on the heap vs. on the stack?
The stack is smaller, but faster for creating variables, while the heap is limited in size
only by how much memory can be allocated. Stack would contain most compile time
variables, while heap would contain anything created with malloc or new.
(b) Suppose Base(AAA) = 300 and w=4 words per memory cell for AAA. Find
Length(AAA) = 50-5+1 = 46
Length(BBB) = 10-(-5)+1 = 16
Length(CCC) = 18-1+1 = 18
8 memory cells
(d) PUSH(STACK, R)
(e) PUSH(STACK,L)
(f) PUSH(STACK, S)
(g) PUSH(STACK,P)
(e) STACK:A,C,R,L,_,_,_,_
It is a collection of elements such that each and every element has been assigned a
priority
Data Structures
Arrays:
An array is a collection of homogeneous elements that can be placed in contiguous
memory locations that can be individually referenced by using their indexes.
For example, three values of type int can be declared as an array without declaring
three different variables.
Single-Dimensional Array:
Declaring Arrays:
To declare an array, we require the type of the element and the number of elements.
Syntax: type arrayname [ arraysize ] ;
Here, the arraysize must be an integer constant that is greater than zero and the type
can be any valid data type.
Ex: double id [5];
It means that 5-element array which is named as id of data type double.
Initializing Arrays:
We can initialize arrays in different types. For example,
double id [] = {1, 2, 3, 4, 5}; Here if we did not mention any size, then it will
allocated for the number of values we have entered in braces {}.
double id [5] = {1, 2, 3, 4, 5}; Here the number of values in braces {} should not be
greater than the value specified in square brackets [].
double id [4] = 4; This type is for inserting an element into a particular index of an
array.
Accessing Array Elements:
An element from an array can be accessed by using its index number.
For example, double empCode = id [2];
Multi-Dimensional Array:
Declaring Arrays:
The general form of a multidimensional array declaration is given as:
type name [size1] [size2] . . . [sizeN];
For example, four dimensional array can be declared as,
int fourdim [3][4][5][6];
The simplest form of multidimensional array is the two-dimensional array. The
syntax for declaring the two-dimensional array of size x,y is
type arrayname [x] [y];
where type can be any data type and arrayname can be an identifier. And the two-
dimensional array can be considered as a table with x number of rows and y number of
columns.
For example, a two-dimensional array a, which contains three rows and four columns
can be given as:
Hence every element in array a can be identified by the name of the form a[i][j],
where i and j are subscripts that uniquely identify each element in a.
Linked Lists:
A Linked List is a data structure which consists of a group of nodes which are placed
together in a sequence having data and a reference to the next node in the sequence.
The linked lists are the most common and simplest data structures which are used for
implementing several other common abstract data types like lists, stacks, queues etc.,
The main advantage of using this linked list is that it allows the elements to be
inserted and deleted easily without causing any reorganisation of entire structure
because the data items need not be stored in contiguous memory locations.
These linked lists are dynamic data structures which allocates the memory required
while running the program. And the linear data structures like stacks and queues can
be easily executed with the linked list.
Linked lists can reduce the access time and can expand in real time without memory
overhead. But linked lists also have some disadvantages like, pointers require extra
storage space, hence they have a tendency of wasting the memory.
Nodes in a linked list can be read in a sequential order from the starting to ending as
they are in sequential access. For reverse traversing, linked lists face difficulties as
singly linked lists are extremely difficult to navigate backwards, whereas doubly
linked lists are somewhat easier to read but memory will be wasted for back pointer.
The record in the linked list is called as node or element. Each node contains the data
or information and the address of the next node. The head of the list will be the first
node and thetail will be the next node of the list or the end of the list.
There are different types of linked lists. They are:
Singly Linked List:
In Singly linked list, it have the data field and the next field which is pointed towards
the next node. In this linked list, we can perform insertion, deletion of the nodes and
traversal.
A stack is a recursive data structure. The structural definition of a stack is that, a stack
is either empty or may contain some elements in top.
Queues
A queue is an abstract data type in which the elements can be inserted to the rear
terminal position, known as enqueue, and the removal of the elements from the front
terminal position, known as dequeue. Hence this queue is a First-In-First-Out (FIFO)
data structure.
In the FIFO data structure, the first element entered into it is the first element that
should be removed. It means that if a new element is inserted and that element should
be dequeued only after removing of the elements that are inserted before the new
element.
For example, the line of people for the ticket in railway reservation counter. The new
people will be added back to the line and the removing will be done from the front.
The difference between stacks and the queues is that only in removing of the
elements. In stack the element that is added recently will be deleted first, where as in
queue, the element that is added first will be removed first.