Data Structure
Data Structure
(A) Queue
(B) Stack
(C) Arrays
(D) All of these
Time complexity: It is a way of representing the amount of time needed by a program to run to
the completion.
Space complexity: It is the amount of memory space required by an algorithm, during a course of
its execution. Space complexity is required in situations when limited memory is available and for the
multi user system.
Characteristics of an Algorithm
An algorithm must follow the mentioned below characteristics:
Output: An algorithm must have 1 or well defined outputs, and should match with the desired output.
programming code.
Unambiguous: An algorithm must be unambiguous and clear. Each of their steps and
The first element of the array is exactly contained in the memory location that array refers (0 elements
away), so it should be denoted as array[0] . Most programming languages have been designed this
way, so indexing from 0 is pretty much inherent to the language
In the worst case, the number of comparisons needed to search a singly linked list of length n for a
given element is ............
(A) log2 n
(B) n/2
(C) log2 n-1
1
(D) N
A & C are not correct as we can not do binary search in Linked list.
Worst case is we do not find the element in list. We might end up searching entire list & comparing
with each element.
Applications of Queue
Due to the fact that queue performs actions on first in first out basis which is quite fair for the
ordering of actions. There are various applications of queues discussed as below.
Queues are widely used as waiting lists for a single shared resource like printer, disk, CPU.
Queues are used in asynchronous transfer of data (where data is not being transferred at the
same rate between two processes) for eg. pipes, file IO, sockets.
Queues are used like MP3 media player, CD player, etc. as buffers in most of the applications
Queue are used to maintain the play list in media players in order to add and remove the songs
from the play-list.
Queues are used in operating systems for handling interrupts.
Which data structure allows deleting data elements from the front and adding at the back?
(A) Stack
(B) Queue
(C) Binary-search tree
(D) Map
2
Explanation:
A full binary tree (sometimes proper binary tree or 2-tree or strictly binary tree) is a tree in which
every node other than the leaves has two children.
A complete binary tree is a binary tree in which every level, except possibly the last, is
completely filled, and all nodes are as far left as possible
3
AVL Tree is invented by GM Adelson - Velsky and EM Landis in 1962. The tree is named AVL in
honour of its inventors.
AVL Tree can be defined as height balanced binary search tree in which each node is associated
with a balance factor which is calculated by subtracting the height of its right sub-tree from that
of its left sub-tree.
Tree is said to be balanced if balance factor of each node is in between -1 to 1, otherwise, the tree will
be unbalanced and need to be balanced.
A tree in which, for every node, the difference between the height of its left subtree and right subtree
is not more than one is
(A) AVL Tree
(B) Complete Binary Tree
(C) B – Tree
(D) B+ Tree
4
SN B Tree B+ Tree
1 Search keys can not be repeatedly stored. Redundant search keys can be present.
2 Data can be stored in leaf nodes as well Data can only be stored on the leaf nodes.
as internal nodes
3 Searching for some data is a slower Searching is comparatively faster as data can
process since data can be found on only be found on the leaf nodes.
internal nodes as well as on the leaf
nodes.
5 Leaf nodes can not be linked together. Leaf nodes are linked together to make the
search operations more efficient.
Consider a B+-tree in which the maximum number of keys in a node is 5. What is the minimum
number of keys in any non-root node?
1
2
3
4
(A + B) * C *+ABC AB+C*
(A + B) * (C + D) *+AB+CD AB+CD+*
5
Graphs are represented using ............
(A) Adjacency tree
(B) Adjacency linked lisT
(C) Adjacency graph.
(D) Adjacency queue
A recursive call is one where procedure A calls itself or calls procedure B which then calls
procedure A again. ..
Explanation:
Prefix of (A+B) * (C - D) / E*F
(+AB) * (-CD) / E*F
*+AB-CD /E*F
*/*+AB-CDEF
n elements of a Queue are to be reversed using another queue. The number of “ADD” and
“REMOVE” operations required to do so is:
(A) 2*n
(B) 4*n
(C) n
(D) The task cannot be accomplished
To reverse the content of queue, we need a stack. It can not be done by using a Queue.
: Linear search is highly inefficient compared to binary search when dealing with:
6
a. Small, unsorted arrays.
b. Small, sorted arrays.
c. Large, unsorted arrays.
d. Large, sorted arrays.
If a node in a BST has two children, then its in-order predecessor has .............
(A) no left child
(B) no right child
(C) two children
(D) no child
If a node in a BST has two children, then its in-order Successor has .............
(A) no left child
(B) no right child
(C) two children
(D) no child
7
The postfix form of the expression (A+ B)*(C*D− E)*F / G is:
(A) AB+ CD*E − FG /**
(B) AB + CD* E − F **G /
(C) AB + CD* E − *F *G /
(D) AB + CDE * − * F *G /
Consider a set A = {1, 2, 3, …….., 1000}. How many members of A shall be divisible by
3 or by 5 or by both 3 and 5 ?
(A) 533 (B) 599
(C) 467 (D) 66
A U B ) = (A) + (B) - (A ∩ B)
A U B = 333+200-66=533-66=467
8
Which of the following is true for computation time in insertion, deletion and finding maximum and
minimum element in a sorted array ?
(A) Insertion – 0(1), Deletion – 0(1), Maximum – 0(1), Minimum – 0(l)
(B) Insertion – 0(1), Deletion – 0(1), Maximum – 0(n), Minimum – 0(n)
(C) Insertion – 0(n), Deletion – 0(n), Maximum – 0(1), Minimum – 0(1)
(D) Insertion – 0(n), Deletion – 0(n), Maximum – 0(n), Minimum – 0(n)
In a sorted array, if we want to insert or delete then we have to traverse whole array and check where
is the suitable position, so it will take
O(n).
If array is sorted then end position will tell the maximum or minimum, so finding maximum or
minimum will take O(1).