0% found this document useful (0 votes)
3 views31 pages

Data Structure MCQ

The document contains multiple-choice questions (MCQs) related to data structures and algorithms, covering topics such as interfaces, time complexity, and array operations. It provides explanations for the answers to each question, enhancing understanding of key concepts in computer science. The content is structured to test knowledge on various aspects of data structures, including their characteristics and performance analysis.

Uploaded by

SCHOOL EDUCATION
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views31 pages

Data Structure MCQ

The document contains multiple-choice questions (MCQs) related to data structures and algorithms, covering topics such as interfaces, time complexity, and array operations. It provides explanations for the answers to each question, enhancing understanding of key concepts in computer science. The content is structured to test knowledge on various aspects of data structures, including their characteristics and performance analysis.

Uploaded by

SCHOOL EDUCATION
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Data Structure MCQ 5.

What is true about Interface in data


Basic structure?
1. How many cases are there, which are A. Each data structure has an interface.
used to compare various data structure's B. Interface represents the set of
execution time in a relative manner? operations that a data structure supports.
A. 2 C. An interface only provides the list of
B. 3 supported operations, type of parameters
C. 4 they can accept and return type of these
D. 5 operations.
Ans : B D. All of the above
Ans : D
Explanation: There are three cases which
are usually used to compare various data Explanation: Interface : Each data
structure's execution time in a relative structure has an interface. Interface
manner : Worst Case ,Average Case and represents the set of operations that a
Best Case. data structure supports. An interface only
provides the list of supported operations,
2. Which case of data structure operation type of parameters they can accept and
takes maximum time? return type of these operations.
A. Worst Case
B. Average Case 6. Which of the following is not a
C. Best Case Characteristics of a Data Structure?
D. None of the above A. Completeness
Ans : A B. Correctness
C. Time Complexity
Explanation: Worst Case : This is the D. Space Complexity
scenario where a particular data structure Ans : A
operation takes maximum time it can take.
Explanation: Completeness is not a
3. In Average case, if operation takes ƒ(n) Characteristics of a Data Structure.
time in execution, then m operations will
take? 7. Which characteristics shows that
A. ƒ(n) running time or the execution time of
B. f(m) operations of data structure must be as
C. mf(n) small as possible?
D. nf(m) A. Completeness
Ans : C B. Correctness
C. Time Complexity
Explanation: If an operation takes ƒ(n) D. Space Complexity
time in execution, then m operations will Ans : C
take mƒ(n) time.
Explanation: Time Complexity : Running
4. __________ is a single elementary unit time or the execution time of operations of
of information representing an attribute of data structure must be as small as
an entity. possible.
A. Entity Set
B. Record 8. Data items that cannot be divided are
C. File called as?
D. Field A. Group Items
Ans : D B. Attribute and Entity
C. Elementary Items
Explanation: Field is a single elementary D. File items
unit of information representing an Ans : C
attribute of an entity.
Explanation: Data items that cannot be Explanation: Queues data structure allows
divided are called as Elementary Items. deleting data elements from front and
inserting at rear.
9. Which of the following analysis known
as theoretical analysis of an algorithm? 13. Which of the following sorting
A. A Posterior Analysis algorithm is of divide-and-conquer type?
B. A Priori Analysis A. Bubble sort
C. A Feasibility Analysis B. Insertion sort
D. A Independent Analysis C. Quick sort
Ans : B D. Selection sort
Ans : C
Explanation: A Priori Analysis : This is a
theoretical analysis of an algorithm. Explanation: Quick sorting algorithm is of
Efficiency of an algorithm is measured by divide-and-conquer type.
assuming that all other factors, for
example, processor speed, are constant 14. The time factor when determining the
and have no effect on the implementation. efficiency of algorithm is measured by?
A. Counting microseconds
10. Which of the following analysis known B. Counting the number of key operations
as empirical analysis of an algorithm? C. Counting the number of statements
A. A Posterior Analysis D. Counting the kilobytes of algorithm
B. A Priori Analysis Ans : B
C. A Feasibility Analysis
D. A Independent Analysis Explanation: The time factor when
Ans : A determining the efficiency of algorithm is
measured by Counting the number of key
Explanation: A Posterior Analysis : This is operations.
an empirical analysis of an algorithm. The
selected algorithm is implemented using 15. In an array representation of binary
programming language. This is then tree the right child of root will be at location
executed on target computer machine. In of?
this analysis, actual statistics like running A. 2
time and space required, are collected. B. 3
C. 4
11. O(1) means computing time is D. 6
A. Constant Ans : B
B. Quadratic
C. Linear Explanation: In an array representation of
D. Cubic binary tree the right child of root will be at
Ans : A location of 3.

Explanation: O(1) means computing time 16. The upper bound on the time
is Constant. complexity of the nondeterministic sorting
algorithm is?
12. Which data structure allows deleting A. O(n)
data elements from front and inserting at B. O(n log n)
rear? C. O(1)
A. Stacks D. O( log n)
B. Queues Ans : A
C. Deques
D. Binary search tree Explanation: The upper bound on the time
Ans : B complexity of the nondeterministic sorting
algorithm is O(n)
17. In analysis of algorithm, approximate Ans : D
relationship between the size of the job
and the amount of work required to do is Explanation: An algorithm should have 1
expressed by using _________. or more well-defined outputs, and should
A. Central tendency match the desired output.
B. Differential equation
C. Order of magnitude 22. __________ of an algorithm
D. Order of execution represents the amount of memory space
Ans : D required by the algorithm in its life cycle.
A. Space complexity
Explanation: In analysis of algorithm, B. Time Complexity
approximate relationship between the size C. Quadratic Complexity
of the job and the amount of work required D. Exponential Complexity
to do is expressed by using Order of Ans : A
execution
Explanation: Space complexity of an
18. What is the type of the algorithm used algorithm represents the amount of
in solving the 8 Queens problem? memory space required by the algorithm in
A. Backtracking its life cycle.
B. Dynamic
C. Branch and Bound 23. The space required by an algorithm is
D. Both A and B equal to the sum of the following _______
Ans : A components.
A. 1
Explanation: Backtracking algorithm used B. 2
in solving the 8 Queens problem. C. 3
D. 4
19. Which of the following belongs to the Ans : B
algorithm paradigm?
A. Minimum & Maximum problem Explanation: The space required by an
B. Knapsack problem algorithm is equal to the sum of the
C. Selection problem following two components : A fixed part
D. Merge sort that is a space required to store certain
Ans : B data and variables and A variable part is a
space required by variables.
Explanation: Knapsack problem belongs to
the algorithm paradigm. 24. Which is the formal way to express the
upper bound of an algorithm's running
20. The [] notation is time.
A. Symmetric A. Big Oh Notation
B. Reflexive B. Omega Notation
C. Transitive C. Theta Notation
D. All of the above D. None of the above
Ans : D Ans : A

Explanation: The [] notation is All of the Explanation: Big Oh Notation : The


above. notation Ο(n) is the formal way to express
the upper bound of an algorithm's running
21. An algorithm should have _________ time. It measures the worst case time
well-defined outputs complexity or the longest amount of time
A. 0 an algorithm can possibly take to
B. 1 complete.
C. 0 or more
D. 1 or more
25. The Omega notation is the formal way
to express the __________ of an
algorithms running time.
A. upper bound
B. medium bound
C. lower bound
D. both the lower bound and the upper
bound
Ans : C

Explanation: The Omega notation is the


formal way to express the lower bound of
an algorithm's running time. It measures
the best case time complexity or the best
amount of time an algorithm can possibly
take to complete.
ARRAY Ans : A
1. A program P reads in 500 integers in
the range [0..100] exepresenting the Explanation:If we take look at the inner
scores of 500 students. It then prints the statements of first loops, we can notice
frequency of each score above 50. What that the statements swap A[i][j] and A[j][i]
would be the best way for P to store the for all i and j. Since the loop runs for all
frequencies? elements, every element A[l][m] would be
A. An array of 50 numbers swapped twice, once for i = l and j = m and
B. An array of 100 numbers then for i = m and j = l. Swapping twice
C. An array of 500 numbers means the matrix doesn’t change.
D. A dynamically allocated array of 550
numbers 4.What is the output of the following piece
Ans : A of code?
public class array
Explanation: An array of size 50 looks the {
best option to store number of students for public static void main(String args[])
each score. We need to store frequencies {
of scores above 50. We can ignore scores int []arr = {1,2,3,4,5};
below 50 and to index the scores above System.out.println(arr[2]);
50, we can subtract 50 from the score System.out.println(arr[4]);
value. }}
A. 3 and 5
2. Which of these best describes an array? B. 5 and 3
A. A data structure that shows a C. 2 and 4
hierarchical behavior D. 4 and 2
B. Container of objects of similar types Ans : A
C. Container of objects of mixed types
D. All of the mentioned Explanation:Array indexing starts from 0.
Ans : B
5. Consider an array A[20, 10], assume 4
Explanation: Array contains elements only words per memory cell and the base
of the same type. address of array A is 100. What is the
address of A[11, 5] ? Assume row major
3. Let A be a square matrix of size n x n. storage.
Consider the following program. What is A. 560
the expected output? B. 565
C = 100 C. 570
for i = 1 to n do D. 575
for j = 1 to n do Ans : A
{
Temp = A[i][j] + C 6. What is the output of the following piece
A[i][j] = A[j][i] of code?
A[j][i] = Temp - C public class array
} {
for i = 1 to n do public static void main(String args[])
for j = 1 to n do {
Output(A[i][j]); int []arr = {1,2,3,4,5};
A. The matrix A itself System.out.println(arr[5]);
B. Transpose of matrix A }}
C. Adding 100 to the upper diagonal A. 4
elements & subtracting 100 from diagonal B. 5
elements of A C. ArrayIndexOutOfBoundsException
D. None of the above D. InavlidInputException
Ans : C C. Find the ith smallest element
D. All of the above
Explanation: Trying to access an element Ans : B
beyond the limits of an array gives
ArrayIndexOutOfBoundsException. Explanation:The worst case time
complexity for deleting an element from
7. Which of the following is an illegal array array can become O(n).
definition?
A. Type COLONGE : (LIME, PINE, MUSK, 11.The smallest element of an array's
MENTHOL); var a : array [COLONGE] of index is called its
REAL; A. lower bound.
B. var a : array [REAL] of REAL; B. upper bound.
C. var a : array [‘A’…’Z’] of REAL; C. range.
D. var a : array [BOOLEAN] of REAL; D. extraction.
Ans : B Ans : A

8. Which of the following concepts make 12. The extra key inserted at the end of
extensive use of arrays? the array is called a,
A. Binary trees A. End key.
B. Scheduling of processes B. Stop key.
C. Caching C. Sentinel.
D. Spatial locality D. Transposition.
Ans : D Ans : C

Explanation:Whenever a particular 13. The largest element of an array index


memory location is referred, it is likely that is called its
the locations nearby are also referred, A. lower bound.
arrays are stored as contigous blocks in B. range.
memory, so if you want to access array C. upper bound.
elements, spatial locality makes it to D. All of these.
access quickly. Ans : C

9.Let A[1...n] be an array of n distinct 14. Each array declaration need not give,
numbers. If i < j and A[i] > A[j], then the implicitly or explicitly, the information about
pair (i, j) is called an inversion of A. What A. the name of array
is the expected number of inversions in B. the data type of array
any permutation on n elements ? C. the first data from the set to be stored
A. θ(n) D. the index set of the array
B. θ(lgn) Ans : C
C. θ(nlgn)
D. θ(n2) 15. The elements of an array are stored
Ans : D successively in memory cells because
A. by this way computer can keep track
Explanation:The expected number of only the address of the first element and
inversions in any permutation on n the addresses of other elements can be
elements is θ(n2). calculated
B. the architecture of computer memory
10. Which of the following operations is does not allow arrays to store other than
not O(1) for an array of sorted data. You serially
may assume that array elements are C. both of above
distinct. D. none of above
A. Find the ith largest element Ans : A
B. Delete an element
Complexity {
1. Which of the following case does not a = a + i + j;
exist in complexity theory? }
A. Best case }
B. Worst case A. O(N)
C. Average case B. O(N*log(N))
D. Null case C. O(N * Sqrt(N))
Ans : D D. O(N*N)
Ans : D
Explanation:Null case does not exist in
complexity Theory. Explanation:= N + (N – 1) + (N – 2) + … 1
+0
2. What is the time, space complexity of = N * (N + 1) / 2
following code: = 1/2 * N^2 + 1/2 * N
int a = 0, b = 0; O(N^2) times.
for (i = 0; i < N; i++)
{ 5. The Worst case occur in linear search
a = a + rand(); algorithm when
} A. Item is somewhere in the middle of the
for (j = 0; j < M; j++) array
{ B. Item is not in the array at all
b = b + rand(); C. Item is the last element in the array
} D. Item is the last element in the array or
A. O(N * M) time, O(1) space is not there at all
B. O(N + M) time, O(N + M) space Ans : D
C. O(N + M) time, O(1) space
D. O(N * M) time, O(N + M) space Explanation:The Worst case occur in
Ans : C linear search algorithm when Item is the
last element in the array or is not there at
Explanation:The first loop is O(N) and the all.
second loop is O(M). Since we don’t know
which is bigger, we say this is O(N + M). 6. What is the time complexity of following
This can also be written as O(max(N, M)). code:
Since there is no additional space being int i, j, k = 0;
utilized, the space complexity is constant / for (i = n / 2; i <= n; i++)
O(1). {
for (j = 2; j <= n; j = j * 2)
3. The complexity of linear search {
algorithm is k = k + n / 2;
A. O(n) }
B. O(log n) }
C. O(n2) A. O(n)
D. O(n log n) B. O(nLogn)
Ans : A C. O(n^2)
D. O(n^2Logn)
Explanation: The worst case complexity of Ans : B
linear search is O(n).
Explanation:Let’s take the examples here.
4.What is the time complexity of following for n = 16, j = 2, 4, 8, 16
code: for n = 32, j = 2, 4, 8, 16, 32
int a = 0; So, j would run for O(log n) steps.
for (i = 0; i < N; i++) i runs for n/2 steps.
{ So, total steps = O(n/ 2 * log (n)) =
for (j = N; j > i; j--) O(n*logn)
C. O(N / 2)
7. The worst case occur in quick sort when D. O(log N)
A. Pivot is the median of the array Ans : D
B. Pivot is the smallest element
C. Pivot is the middle element Explanation:We have to find the smallest x
D. None of the mentioned such that N / 2^x N x = log(N).
Ans : B
11. What is the time complexity of
Explanation:This happens when the pivot following code:
is the smallest (or the largest) element. int a = 0, i = N;
Then one of the partitions is empty, and while (i > 0)
we repeat recursively the procedure for N- {
1 elements. a += i;
i /= 2;
8. What does it mean when we say that an }
algorithm X is asymptotically more efficient A. O(N)
than Y? B. O(Sqrt(N))
A. X will always be a better choice for C. O(N / 2)
small inputs D. O(log N)
B. X will always be a better choice for Ans : D
large inputs
C. Y will always be a better choice for Explanation: We have to find the smallest
small inputs x such that N / 2^x N x = log(N)
D. X will always be a better choice for all
inputs 12. The complexity of Binary search
Ans : B algorithm is
A. O(n)
Explanation: An algorithm X is said to be B. O(log )
asymptotically better than Y if X takes C. O(n2)
smaller time than y for all input sizes n D. O(n log n)
larger than a value n0 where n0 > 0. Ans : B

9. The complexity of Fibonacci series is Explanation: The compexity of binary


A. O(2n) search is O(logn).
B. O(log n)
C. O(n2) 13. The complexity of merge sort algorithm
D. O(n log n) is
Ans : A A. O(n)
B. O(log n)
Explanation:= Fibonacci is f(n) = f(n-1) + C. O(n2)
f(n-2), f(0) = 0, f(1) = 1. Let g(n) = 2n. Now D. O(n log n)
prove inductively that f(n) > = g(n). Ans : D

10. What is the time complexity of Explanation: The worst case complexity
following code: for merge sort is O(nlogn)..
int a = 0, i = N;
while (i > 0) 14. The complexity of Bubble sort
{ algorithm is
a += i; A. O(n)
i /= 2; B. O(log n)
} C. O(n2)
A. O(N) D. O(n log n)
B. O(Sqrt(N)) Ans : C
Explanation: The worst case complexity 19.If for an algorithm time complexity is
for Bubble sort is O(n2)ans best case is given by O(log2n) then complexity will:
O(n)/. A. constant
B. polynomial
15. The worst case complexity for insertion C. exponential
sort is D. none of the mentioned
A. O(n) Ans : D
B. O(log n)
C. O(n2) Explanation: The growth rate of that
D. O(n log n) function will be logarithmic therefore
Ans : C complexity will be logarithmic.

Explanation: In worst case nth comparison 20. If for an algorithm time complexity is
are required to insert the nth element into given by O(n) then complexityof it is:
correct position. A. constant
B. linear
16. The worst case complexity of quick C. exponential
sort is D. none of the mentioned
A. O(n) Ans : B
B. O(log n)
C. O(n2) Explanation: The growth rate of that
D. O(n log n) function will be linear.
Ans : C
21. if for an algorithm time complexity is
Explanation: The worst case complexity of given by O(n2) then complexity will:
quick sort is O(n2). A. constant
B. quardratic
17. To measure Time complexity of an C. exponential
algorithm Big O notation is used which: D. none of the mentioned
A. describes limiting behaviour of the Ans : B
function
B. characterises a function based on Explanation: The growth rate of that
growth of function function will be quadratic therefore
C. upper bound on growth rate of the complexity will be quardratic..
function
D. all of the mentioned 22. If for an algorithm time complexity is
Ans : D given by O((3/2)^n) then complexity will:
A. constant
Explanation: Big O notation describes B. quardratic
limiting behaviour, and also gives upper C. exponential
bound on growth rate of a function. D. none of the mentioned
Ans : C
18. If for an algorithm time complexity is
given by O(1) then complexityof it is: Explanation: The growth rate of that
A. constant function will be exponential therefore
B. polynomial complexity will be exponential.
C. exponential
D. none of the mentioned 23. the time complexity of binary search is
Ans : A given by:
A. constant
Explanation: The growth rate of that B. quardratic
function will be constant. C. exponential
D. none of the mentioned
Ans : D 29. Which algorithm is having highest
space complexity?
Explanation: It is O(log2n), therefore A. Bubble sort
complexity will be logarithmic. B. Insertion Sort
C. Quick Sort
24. The time complexity of linear search is D. Merge Sort
given by: Ans : D
A. O(log2n)
B. O(1) 30. If the array is already sorted, then the
C. exponential running time for merge sort is: ?
D. none of the mentioned A. O(1)
Ans : D B. O(n*log n)
C. O(n)
Explanation: It is O(n), therefore D. O(n^2)
complexity will be linear. Ans : B

25. Which algorithm is better for sorting


between bubble sort and quicksort?
A. bubble sort
B. quick sort
C. both are equally good
D. none of the mentioned
Ans : B

Explanation: Running time of quicksort is


logarithmic whereas for bubble sort it is
quardratic

26. State true or false


Time complexity of binary search
algorithm is constant
A. True
B. False
Ans : B

Explanation: It is O(log2n), therefore


complexity will be logarithmic.

27. Two main measures for the efficiency


of an algorithm are
A. Time and space
B. Processor and memory
C. Complexity and capacity
D. Data and space
Ans : A

28. Which is the best data structure for


round robin algorithm for CPU scheduling?
A. Stack implemented using queues
B. Doubly linked list
C. Circular queue
D. Queue implemented using stacks
Ans : C
STACK 5.In a stack, if a user tries to remove an
1. Which one of the following is an element from empty stack it is called
application of Stack Data Structure? _________.
A. Managing function calls A. Underflow
B. The stock span problem B. Empty collection
C. Arithmetic expression evaluation C. Overflow
D. All of the above D. Garbage Collection
Ans : D Ans : A

2. Process of inserting an element in stack Explanation:In a stack, if a user tries to


is called ____________. remove an element from empty stack it is
A. Create called Underflow.
B. Push 6. Consider the following pseudocode that
C. Evaluation uses a stack. What is output for input
D. Pop "letsfindc"?
Ans : B
declare a stack of characters
Explanation: Process of inserting an while ( there are more characters in the
element in stack is called Push. word to read )
3. The postfix form of A*B+C/D is? {
A. *AB/CD+ read a character
B. AB*CD/+ push the character on the stack
C. A*BC+/D }
D. ABCD+/* while ( the stack is not empty )
Ans : B {
pop a character off the stack
Explanation: The postfix form of A*B+C/D write the character to the screen
is AB*CD/+. }

4.Which of the following is true about A. letsfindcletsfindc


linked list implementation of stack? B. cdnifstel
A. In push operation, if new nodes are C. letsfindc
inserted at the beginning of linked list, D. cdnifstelcdnifstel
then in pop operation, nodes must be Ans : B
removed from end.
B. In push operation, if new nodes are 7.Entries in a stack are "ordered". What is
inserted at the end, then in pop operation, the meaning of this statement?
nodes must be removed from the A. A collection of stacks is sortable
beginning. B. Stack entries may be compared with
C. Both of the above the '<' operation
D. None of the above C. The entries are stored in a linked list
Ans : D D. There is a Sequential entry that is one
by one
Explanation: To keep the Last In First Out Ans : D
order, a stack can be implemented using
linked list in two ways: a) In push Explanation: It means There is a
operation, if new nodes are inserted at the Sequential entry that is one by one.

8. The prefix form of A-B/ (C * D ⋀ E) is?


beginning of linked list, then in pop
operation, nodes must be removed from
beginning. b) In push operation, if new A. -/*⋀ACBDE
nodes are inserted at the end of linked list, B. -ABCD*⋀DE
then in pop operation, nodes must be C. -A/B*C⋀DE
removed from end. D. -A/BC*⋀DE
Ans : C Ans : D

⋀ E) is -A/B*C⋀DE.
Explanation: The prefix form of A-B/ (C * D 12.Pushing an element into stack already
having five elements and stack size of 5 ,
then stack becomes
9.Following is an incorrect pseudocode for A. Overflow
the algorithm which is supposed to B. Crash
determine whether a sequence of C.Underflow
parentheses is balanced: Which of these D. User flow
unbalanced sequences does the above Ans : C
code think is balanced?
13. Which of the following applications
declare a character stack may use a stack?
while ( more input is available) A. A parentheses balancing program
{ B. Tracking of local variables at run time
read a character C. Compiler Syntax Analyzer
if ( the character is a '(' ) D. All of the mentioned
push it on the stack Ans : D
else if ( the character is a ')' and the stack
is not empty ) Explanation: All are applications of stack.
pop a character off the stack
else 14.Consider the usual algorithm for
print "unbalanced" and exit determining whether a sequence of
} parentheses is balanced.
print "balanced" The maximum number of parentheses that
appear on the stack AT ANY ONE TIME
A. ((()) when the algorithm analyzes: (()(())(()))
B. ())(() are:
C. (()())) A. 1
D. (()))() B. 2
Ans : A C. 3
D. 4 or more
Explanation: At the end of while loop, we Ans : C
must check whether the stack is empty or
not. For input ((()), the stack doesn't Explanation: Applying the postfix
remain empty after the loop. expression evaluation.

10.What is the value of the postfix 15.Consider the usual algorithm for
expression 6 3 2 4 + – *: determining whether a sequence of
A. Something between -5 and -15 parentheses is balanced.
B. Something between 5 and -5 Suppose that you run the algorithm on a
C. Something between 5 and 15 sequence that contains 2 left parentheses
D. Something between 15 and 100 and 3 right parentheses (in some order).
Ans : D The maximum number of parentheses that
appear on the stack AT ANY ONE TIME
Explanation:On solving the postfix during the computation?
expression the answer comes out to 18. A. 1
B. 2
11. Process of removing an element from C. 3
stack is called __________ D. 4 or more
A. Create Ans : C
B. Push
C. Evaluation Explanation: Applying the postfix
D. Pod expression evaluation.
16. The data structure required to check 21. Which data structure is needed to
whether an expression contains balanced convert infix notation to postfix notation?
parenthesis is? A. Branch
A. Stack B. Tree
B. Queue C. Queue
C. Array D. Stack
D. Tree Ans : D
Ans : A
22. The prefix form of A-B/ (C * D ^ E) is?
17. Here is an infix expression: 4 + 3*(6*3- A. -/*^ACBDE
12). Suppose that we are using the usual B. -ABCD*^DE
stack algorithm to convert the expression C. -A/B*C^DE
from infix to postfix notation. D. -A/BC*^DE
The maximum number of symbols that will Ans : B
appear on the stack AT ONE TIME during
the conversion of this expression? Explanation: Process of inserting an
A. 1 element in stack is called Push.
B. 2
C. 3 23. The postfix form of A*B+C/D is?
D. 4 A. *AB/CD+
Ans : D B. AB*CD/+
C. A*BC+/D
18. What data structure would you mostly D. ABCD+/*
likely see in a non recursive Ans : C
implementation of a recursive algorithm?
A. Linked List Explanation: Applying the prefix
B. Stack expression evaluation..
C. Queue
D. Tree 24.What is the result of the following
Ans : B operation
Top (Push (S, X))
19.The process of accessing data stored A. X
in a serial access memory is similar to B. Null
manipulating data on a C. S
A. Heap D. None of the mentioned
B. Binary Tree Ans : A
C. Array
D. Stack 25.The prefix form of an infix expression p
Ans : D + q – r * t is?
A. + pq – *rt
20.The postfix form of A*B+C/D is? B. – +pqr * t
A. *AB/CD+ C. – +pq * rt
B. AB*CD/+ D. – + * pqrt
C. A*BC+/D Ans : C
D. ABCD+/*
Ans : B Explanation: Applying the prefix
expression evaluation.
Explanation: Applying the postfix
expression evaluation.
QUEUE Explanation: A queue can be implemented
1. Which one of the following is an using two stacks.
application of Queue Data Structure?
A. When a resource is shared among 5.In a Queue, if a user tries to remove an
multiple consumers. element from empty Queue it is called
B. When data is transferred A. Underflow
asynchronously (data not necessarily B. Empty collection
received at same rate as sent) between C. Overflow
two processes D. Garbage Collection
C. Load Balancing Ans : A
D. All of the above
Ans : D Explanation:In a Queue, if a user tries to
remove an element from empty Queue it is
2. In linked list implementation of queue, if called Underflow.
only front pointer is maintained, which of
the following operation take worst case 6. If the elements "A", "B", "C" and "D" are
linear time? placed in a queue and are deleted one at
A. Insertion a time, in what order will they be
B. Deletion removed?
C. To empty a queue A. ABCD
D. Both Insertion and To empty a queue B. DCBA
Ans : D C. DCAB
D. ABCD
Explanation: Since front pointer is used for Ans : A
deletion, so worst time for the other two
cases. Explanation: Because Queue follow FIFO
rule.
3. Let the following circular queue can
accommodate maximum six elements with 7.A priority queue can efficiently
the following data.What will happen after implemented using which of the following
ADD O operation takes place? data structures? Assume that the number
front = 2 rear = 4 of insert and peek (operation to see the
queue = _______; L, M, N, ___, ___ current highest priority item) and extraction
A. front = 2 rear = 5 (remove the highest priority item)
queue = ______; L, M, N, O, ___ operations are almost same
B. front = 3 rear = 5 A. Array
queue = L, M, N, O, ___ B. Linked List
C. front = 3 rear = 4 C. Heap Data Structures like Binary Heap,
queue = ______; L, M, N, O, ___ Fibonacci Heap
D. front = 2 rear = 4 D. None of the above
queue = L, M, N, O, ___ Ans : C
Ans : A
8. In case of insertion into a linked queue,
4.How many stacks are needed to a node borrowed from the __________ list
implement a queue. Consider the situation is inserted in the queue.
where no other data structure like arrays, A. AVAIL
linked list is available to you. B. FRONT
A. 1 C. REAR
B. 2 D. None of the mentioned
C. 3 Ans : A
D. 4
Ans : B Explanation: All the nodes are collected in
AVAIL list.
9.If the MAX_SIZE is the size of the array 14. In Breadth First Search of Graph,
used in the implementation of circular which of the following data structure is
queue. How is rear manipulated while used?
inserting an element in the queue? A. Stack
A. rear=(rear%1)+MAX_SIZE B. Queue
B. rear=rear%(MAX_SIZE+1) C. Linked list
C. rear=(rear+1)%MAX_SIZE D. None of the mentioned
D. rear=rear+(1%MAX_SIZE) Ans : B
Ans : C
15. A data structure in which elements can
10.Suppose a circular queue of capacity (n be inserted or deleted at/from both the
– 1) elements is implemented with an ends but not in the middle is?
array of n elements. Assume that the A. Queue
insertion and deletion operation are B. Circular queue
carried out using REAR and FRONT as C. Dequeue
array index variables, respectively. Initially, D. Priority queue
REAR = FRONT = 0. The conditions to Ans : C
detect queue full and queue empty are
A. Full: (REAR+1) mod n == FRONT, 16. A normal queue, if implemented using
empty: REAR == FRONT an array of size MAX_SIZE, gets full when
B. Full: (REAR+1) mod n == FRONT, A. Rear = MAX_SIZE – 1
empty: (FRONT+1) mod n == REAR B Front = (rear + 1)mod MAX_SIZE
C. Full: REAR == FRONT, empty: C. Front = rear + 1
(REAR+1) mod n == FRONT D> Rear = front
D. Full: (FRONT+1) mod n == REAR, Ans : C
empty: REAR == FRONT
Ans : A Explanation: Condition for size of queue.

11. A linear list of elements in which 17. Queues serve major role in
deletion can be done from one end (front) A. Simulation of recursion
and insertion can take place only at the B. Simulation of arbitrary linked list
other end (rear) is known as a ? C. Simulation of limited resource allocation
A Queue D. All of the mentioned
B Stack Ans : C
C. Tree
D. Linked list Explanation: Rest all are implemented
Ans : A using other data structures.

12. The data structure required for Breadth 18. Which of the following is not the type
First Traversal on a graph is? of queue?
A. Stack A. Ordinary queue
B. Array B. Single ended queue
C. Queue C. Circular queue
D. Tree D. Priority queue
Ans : C Ans : B

13. A queue is a ? Explanation: Queue always has two ends.


A. FIFO (First In First Out) list
B. LIFO (Last In First Out) list 19. Which of the following properties is
C. Ordered array associated with a queue?
D. Linear tree A. First In Last Out
Ans : A B. First In First Out
C. Last In First Out
D. None of the mentioned
Ans : B

Explanation: Queue follows First In First


Out structure.

20. What does the following piece of code


do?

public Object function()


{
if(isEmpty())
return -999;
else
{
Object high;
high = q[front];
return high;
}
}

A. Dequeue
B. Enqueue
C. Return the front element
D. None of the mentioned
Ans : C

Explanation: q[front] gives the element at


the front of the queue, since we are not
moving the ‘front’ to the next element, it is
not a dequeue operation.
LINKED LIST 4. What would be the asymptotic time
1. What does the following function do for complexity to add a node at the end of
a given Linked List with first node as singly linked list, if the pointer is initially
head? pointing to the head of the list?
A. O(1)
void fun1(struct node* head) B. O(n)
{ C. θ (n)
if(head == NULL) D. θ (1)
return; Ans : C
fun1(head->next);
printf("%d ", head->data); 5. What is the output of following function
} for start pointing to first node of following
linked list? 1->2->3->4->5->6
A. Prints all nodes of linked lists
B. Prints all nodes of linked list in reverse void fun(struct node* start)
order {
C. Prints alternate nodes of Linked List if(start == NULL)
D. Prints alternate nodes in reverse order return;
Ans : B printf("%d ", start->data);
if(start->next != NULL )
Explanation: fun1() prints the given Linked fun(start->next->next);
List in reverse manner. For Linked List 1- printf("%d ", start->data);
>2->3->4->5, fun1() prints 5->4->3->2->1. }

2. A linear collection of data elements A. 1 4 6 6 4 1


where the linear node is given by means B. 1 3 5 1 3 5
of pointer is called? C. 1 2 3 5
A. linked list D. 1 3 5 5 3 1
B. node list Ans : D
C. primitive list
D. None of these Explanation:fun() prints alternate nodes of
Ans : A the given Linked List, first from head to
end, and then from end to head. If Linked
Explanation: A linear collection of data List has even number of nodes, then skips
elements where the linear node is given by the last node.
means of pointer is called linked list.
6. What is the functionality of the following
3. What is the time complexity to count the piece of code?
number of elements in the linked list?
A. O(1) public int function(int data)
B. O(n) {
C. O(logn) Node temp = head;
D. None of the mentioned int var = 0;
Ans : B while(temp != null)
{
Explanation: To count the number of if(temp.getData() == data)
elements, you have to traverse through {
the entire list, hence complexity is O(n). return var;
}
var = var+1;
temp = temp.getNext();
}
return Integer.MIN_VALUE;
}
A. Find and delete a given element in the C. Three pointer
list D. None
B. Find and return the given element in the Ans : B
list
C. Find and return the position of the given Explanation: In circular linked list, insertion
element in the list of node requires modification of Two
D. Find and insert a new element in the list pointer.
Ans : C
11. Consider an implementation of
Explanation: When temp is equal to data, unsorted singly linked list. Suppose it has
the position of data is returned. its representation with a head pointer only.
Given the representation, which of the
7. Linked lists are not suitable to for the following operation can be implemented in
implementation of? O(1) time?
A. Insertion sort i) Insertion at the front of the linked list
B. Radix sort ii) Insertion at the end of the linked list
C. Polynomial manipulation iii) Deletion of the front node of the linked
D. Binary search list
Ans : D iv) Deletion of the last node of the linked
list
Explanation: Linked lists are not suitable to A. I and II
for the implementation of Binary search. B. I and III
C. I, II and III
8. In the worst case, the number of D. I, II and IV
comparisons needed to search a singly Ans : B
linked list of length n for a given element is
A. log 2 n 12. In linked list each node contain
B. n/2 minimum of two fields. One field is data
C. log 2 n – 1 field to store the data second field is?
D. n A. Pointer to character
View Answer B. Pointer to integer
Ans : D C. Pointer to node
D. Node
Explanation: In the worst case, the Ans : C
element to be searched has to be
compared with all elements of linked list. 13. What would be the asymptotic time
complexity to find an element in the linked
9. Which of these is an application of list?
linked lists? A. O(1)
A. To implement file systems B. O(n)
B. For separate chaining in hash-tables C. O(n2)
C. To implement non-binary trees D. None of the mentioned
D. All of the mentioned Ans : B
View Answer
Ans : D 14. The concatenation of two list can
performed in O(1) time. Which of the
Explanation: Linked lists can be used to following variation of linked list can be
implement all of the above mentioned used?
applications. A. Singly linked list
B. Doubly linked list
10. In circular linked list, insertion of node C. Circular doubly linked list
requires modification of? D. Array implementation of list
A. One pointer Ans : C
B. Two pointer
15. Consider the following definition in c 19. In Linked List implementation, a node
programming language.Which of the carries information regarding
following c code is used to create new A. Data
node? B. Link
C. Data and Link
struct node D. None of the mentioned
{ Ans : B
int data;
struct node * next; 20. Linked list data structure offers
} considerable saving in
typedef struct node NODE; A. Computational Time
NODE *ptr; B. Space Utilization
C. Space Utilization and Computational
A. ptr = (NODE*)malloc(sizeof(NODE)); Time
B. ptr = (NODE*)malloc(NODE); D. None of the mentioned
C. ptr = (NODE*)malloc(sizeof(NODE*)); Ans : C
D. ptr = (NODE)malloc(sizeof(NODE));
Ans :A Explanation: Linked lists saves both space
and time.
Explanation: As it represents the right way
to create a node. 21. Which of the following points is/are
true about Linked List data structure when
16. What kind of linked list is best to it is compared with array
answer question like "What is the item at A. Arrays have better cache locality that
position n"? can make them better in terms of
A. Singly linked list performance
B. Doubly linked list B. It is easy to insert and delete elements
C. Circular linked list in Linked List
D. Array implementation of linked list C. Random access is not allowed in a
Ans : D typical implementation of Linked Lists
D. All of the mentioned
17. Linked lists are not suitable to for the Ans : D
implementation of?
A. Insertion sort 22. Which of the following sorting
B. Radix sort algorithms can be used to sort a random
C. Polynomial manipulation linked list with minimum time complexity?
D. Binary search A. Insertion Sort
Ans : D B. Quick Sort
C. Heap Sort
Explanation: It cannot be implemented D. Merge Sort
using linked lists. View Answer
Ans : D
18. Linked list is considered as an
example of ___________ type of memory Explanation: Both Merge sort and Insertion
allocation. sort can be used for linked lists. The slow
A. Dynamic random-access performance of a linked
B. Static list makes other algorithms (such as
C. Compile time quicksort) perform poorly, and others
D. None of the mentioned (such as heapsort) completely impossible.
Ans : A Since worst case time complexity of Merge
Sort is O(nLogn) and Insertion sort is
Explanation: As memory is allocated at the O(n2), merge sort is preferred.
run time.
head pointer now starts pointing to the last
23. Given pointer to a node X in a singly node.
linked list. Only one pointer is given,
pointer to head node is not given, can we 25. he following C function takes a single-
delete the node X from given linked list? linked list of integers as a parameter and
A. Possible if X is not last node rearranges the elements of the list.
B. Possible if size of linked list is even The function is called with the list
C. Possible if size of linked list is odd containing the integers 1, 2, 3, 4, 5, 6, 7 in
D. Possible if X is not first node the given order. What will be the contents
Ans : A of the list after the function completes
execution?
Explanation: Following are simple steps.
struct node *temp = X->next; struct node
X->data = temp->data; {
X->next = temp->next; int value;
free(temp); struct node *next;
};
24. The following function reverse() is void rearrange(struct node *list)
supposed to reverse a singly linked list. {
There is one line missing at the end of the struct node *p, * q;
function.What should be added in place of int temp;
"/*ADD A STATEMENT HERE*/", so that if ((!list) || !list->next)
the function correctly reverses a linked list. return;
p = list;
struct node q = list->next;
{ while(q)
int data; {
struct node* next; temp = p->value;
}; p->value = q->value;
static void reverse(struct node** head_ref) q->value = temp;
{ p = q->next;
struct node* prev = NULL; q = p?p->next:0;
struct node* current = *head_ref; }
struct node* next; }
while (current != NULL)
{ A. 1, 2, 3, 4, 5, 6, 7
next = current->next; B. 2, 1, 4, 3, 6, 5, 7
current->next = prev; C. 1, 3, 2, 5, 4, 7, 6
current = next; D. 2, 3, 4, 5, 6, 7, 1
} Ans : B
/*ADD A STATEMENT HERE*/
} Explanation: The function rearrange()
exchanges data of every node with its next
A. *head_ref = prev; node. It starts exchanging data from the
B. *head_ref = current; first node itself.
C. *head_ref = next;
D. *head_ref = NULL;
View Answer
Ans : A

Explanation: *head_ref = prev; At the end


of while loop, the prev pointer points to the
last node of original linked list.
We need to change *head_ref so that the
TREE
1. The no of external nodes in a full binary 5.The difference between the external
tree with n internal nodes is? path length and the internal path length of
A. n a binary tree with n internal nodes is?
B. n+1 A. 1
C. 2n B. n
D. 2n + 1 C. n + 1
Ans : B D. 2n
Ans : D
Explanation: The no of external nodes in a
full binary tree with n internal nodes is Explanation:The difference between the
n+1. external path length and the internal path
length of a binary tree with n internal
2. Which of the following is a true about nodes is 2n.
Binary Trees?
A. Every binary tree is either complete or 6. In a complete k-ary tree, every internal
full. node has exactly k children or no child.
B. Every complete binary tree is also a full The number of leaves in such a tree with n
binary tree. internal nodes is:
C. Every full binary tree is also a complete A. nk
binary tree. B. (n – 1) k+ 1
D. No binary tree is both complete and full. C. n( k – 1) + 1
E. None of the above D. n(k – 1)
Ans : E Ans : C

Explanation: A full binary tree (sometimes Explanation: For an k-ary tree where each
proper binary tree or 2-tree or strictly node has k children or no children,
binary tree) is a tree in which every node following relation holds L = (k-1)*n + 1
other than the leaves has two children. A Where L is the number of leaf nodes and n
complete binary tree is a binary tree in is the number of internal nodes.
which every level, except possibly the last,
is completely filled, and all nodes are as 7.Height of Height of a binary tree is
far left as possible. A) is incorrect. A. MAX( Height of left Subtree, Height of
right subtree)+1
3. A Binary Tree can have B. MAX( Height of left Subtree, Height of
A. Can have 2 children right subtree)
B. Can have 1 children C. MAX( Height of left Subtree, Height of
C. Can have 0 children right subtree)-1
D. All of the above D. None of the above
Ans : D Ans : A

Explanation: A Binary Tree can have 0, 1, Explanation: Height of Height of a binary


2 children tree is MAX( Height of left Subtree, Height
of right subtree)+1.
4.Which of the following is not an
advantage of trees? 8. Which of the following options is an
A. Hierarchical structure application of splay trees ?
B. Faster search A. cache Implementation
C. Router algorithms B. networks
D. Undo/Redo operations in a notepad C. send values
Ans : D D. receive values
Ans : A
Explanation: This is an application of
stack.
Explanation: Splay trees can be used for
faster access to recently accessed items
and hence used for cache
implementations.

9. Suppose a complete binary tree has


height h>0. The minimum no of leaf nodes
possible in term of h is?
A. 2h -1
B. 2h -1 + 1
C. 2h -1
D. 2h +1
Ans : C

Explanation: Suppose a complete binary


tree has height h>0. The minimum no of
leaf nodes possible in term of h is 2h -1.

10. A weight-balanced tree is a binary tree


in which for each node. The number of
nodes in the left sub tree is at least half
and at most twice the number of nodes in
the right sub tree. The maximum possible
height (number of nodes on the path from
the root to the farthest leaf) of such a tree
on n nodes is best described by which of
the following?
A. log2 n
B. log4/3 n
C. log3 n
D. log3/2 n
Ans : D
Sorting algorithm, then use median as pivot. What
1. What is recurrence for worst case of will be the worst case time complexity of
QuickSort and what is the time complexity this modified QuickSort.
in Worst case? A. O(n^2 Logn)
A. Recurrence is T(n) = T(n-2) + O(n) and B. O(n^2)
time complexity is O(n^2) C. O(n Logn Logn)
B. Recurrence is T(n) = T(n-1) + O(n) and D. O(nLogn)
time complexity is O(n^2) Ans : D
C. Recurrence is T(n) = 2T(n/2) + O(n)
and time complexity is O(nLogn) Explanation:If we use median as a pivot
D. Recurrence is T(n) = T(n/10) + T(9n/10) element, then the recurrence for all cases
+ O(n) and time complexity is O(nLogn) becomes T(n) = 2T(n/2) + O(n) The above
Ans : B recurrence can be solved using Master
Method. It falls in case 2 of master
method.
2. Which of the following is not a stable
sorting algorithm? 6. Which of the following is not an in-place
A. Insertion sort sorting algorithm?
B. Selection sort A. Selection sort
C. Bubble sort B. Heap sort
D. Merge sort C. Quick sort
Ans : B D. Merge sort
Ans : D
Explanation:Selection sort is not a stable
sorting algorithm. Explanation: Merge sort is not an in-place
sorting algorithm.
3. What is an external sorting algorithm?
A. Algorithm that uses tape or disk during 7. What is the advantage of bubble sort
the sort over other sorting techniques?
B. Algorithm that uses main memory A. It is faster
during the sort B. Consumes less memory
C. Algorithm that involves swapping C. Detects whether the input is already
D. Algorithm that are considered ‘in place’ sorted
Ans : A D. All of the mentioned
Ans : C
Explanation: As the name suggests,
external sorting algorithm uses external Explanation: Bubble sort is one of the
memory like tape or disk. simplest sorting techniques and perhaps
the only advantage it has over other
4. If the number of records to be sorted is techniques is that it can detect whether the
small, then …… sorting can be efficient. input is already sorted.
A. Merge
B. Heap 8.The complexity of sorting algorithm
C. Selection measures the …… as a function of the
D. Bubble number n of items to be sorter.
Ans : C A. average time
B. running time
Explanation:Selection sorting can be C. average-case complexity
efficient. D. case-complexity
View Answer
5.Suppose we have a O(n) time algorithm Ans : B
that finds median of an unsorted array.
Now consider a QuickSort implementation Explanation:The complexity of sorting
where we first find median using the above algorithm measures the running time as a
function of the number n of items to be 12. What is the worst case complexity of
sorter. selection sort?
A. O(nlogn)
9. Suppose we are sorting an array of B. O(logn)
eight integers using quicksort, and we C. O(n)
have just finished the first partitioning with D. O(n2)
the array looking like this: Ans :DC
2 5 1 7 9 12 11 10
Which statement is correct? Explanation: Selection sort creates a sub-
A. The pivot could be either the 7 or the 9. list, LHS of the ‘min’ element is already
B. The pivot could be the 7, but it is not the sorted and RHS is yet to be sorted.
9 Starting with the first element the ‘min’
C. The pivot is not the 7, but it could be element moves towards the final element.
the 9
D. Neither the 7 nor the 9 is the pivot. 13. What is the advantage of selection sort
Ans : A over other sorting techniques?
a) It requires no additional storage space
Explanation:7 and 9 both are at their b) It is scalable
correct positions (as in a sorted array). c) It works best for inputs which are
Also, all elements on left of 7 and 9 are already sorted
smaller than 7 and 9 respectively and on d) It is faster than any other sorting
right are greater than 7 and 9 respectively. technique
Ans : A
10.Consider the situation in which
assignment operation is very costly. Which Explanation: Since selection sort is an in-
of the following sorting algorithm should be place sorting algorithm, it does not require
performed so that the number of additional storage.
assignment operations is minimized in
general? 14. What is the average case complexity
A. Insertion sort of selection sort?
B. Selection sort A. O(nlogn)
C. Heap sort B. O(logn)
D. None C. O(n)
Ans : B D. O(n2)
Ans : D
Explanation:Selection sort.
Explanation: In the average case, even if
11. In the following scenarios, when will the input is partially sorted, selection sort
you use selection sort? behaves as if the entire array is not sorted.
A. The input is already sorted Selection sort is insensitive to input.
B. A large file has to be sorted
C. Large values need to be sorted with 15. What is the disadvantage of selection
small keys sort?
D. Small values need to be sorted with A. It requires auxiliary memory
large keys B. It is not scalable
View Answer C. It can be used for small keys
Ans : C D. None of the mentioned
Ans : B
Explanation: Selection is based on keys,
hence a file with large values and small Explanation: As the input size increases,
keys can be efficiently sorted with the performance of selection sort
selection sort. decreases.
16. The given array is arr = {3,4,5,2,1}. Explanation: As the name suggests,
The number of iterations in bubble sort internal sorting algorithm uses internal
and selection sort respectively are, main memory.
A. 5 and 4
B. 4 and 5 20.What is the worst case complexity of
C. 2 and 4 bubble sort?
D. 2 and 5 A. O(nlogn)
Ans : A B. O(logn)
C. O(n)
Explanation: Since the input array is not D. O(n2)
sorted, bubble sort takes 5 iterations and Ans : D
selection sort takes 4(n-1) iterations.
Explanation: Bubble sort works by starting
17. The given array is arr = {1,2,3,4,5}. from the first element and swapping the
(bubble sort is implemented with a flag elements if required in each iteration.
variable)The number of iterations in
selection sort and bubble sort respectively 21. What is the average case complexity
are, of bubble sort?
A. 5 and 4 A. O(nlogn)
B. 1 and 4 B. O(logn)
C. 0 and 4 C. O(n)
D. 4 and 1 D. O(n2)
Ans : B Ans : D

Explanation: Selection sort is insensitive to Explanation: Bubble sort works by starting


input, hence 4(n-1) iterations. Whereas from the first element and swapping the
bubble sort iterates only once to set the elements if required in each iteration even
flag to 0 as the input is already sorted. in the average case.

18.What is the best case complexity of 22. The given array is arr = {1,2,4,3}.
selection sort? Bubble sort is used to sort the array
A. O(nlogn) elements. How many iterations will be
B. O(logn) done to sort the array?
C. O(n) A. 4
D. O(n2) B. 2
Ans : D C. 1
D. 0
Explanation: The best, average and worst Ans : A
case complexities of selection sort is
O(n2). Explanation: Even though the first two
(n-1) + (n-2) + (n-3) + …. + 1 = (n(n-1))/2 ~ elements are already sorted, bubble sort
(n2)/2. needs 4 iterations to sort the given array.

19. What is an internal sorting algorithm? 23.What is the best case efficiency of
A. Algorithm that uses tape or disk during bubble sort in the improvised version?
the sort A. O(nlogn)
B. Algorithm that uses main memory B. O(logn)
during the sort C. O(n)
C. Algorithm that involves swapping D. O(n2)
D. Algorithm that are considered ‘in place’ Ans : B
Ans : B
Explanation: Only 2 elements in the given
array are not sorted, hence only 2
iterations are required to sort them.
24. QuickSort can be categorized into
which of the following?
A. Brute Force technique
B. Divide and conquer
C. Greedy algorithm
D. Dynamic programming
Ans : B

Explanation: First you divide(partition) the


array based on the pivot element and sort
accordingly.

25. What is a randomized QuickSort?


A. The leftmost element is chosen as the
pivot
B. The rightmost element is chosen as the
pivot
C. Any element in the array is chosen as
the pivot
D. A random number is generated which is
used as the pivot
Ans : C

Explanation: QuickSort is randomized by


placing the input data in the randomized
fashion in the array or by choosing a
random element in the array as a pivot.
Hashing Explanation:Hashing technique which
1. What is a hash table? allocates fixed number of buckets is
A. A structure that maps values to keys classified as external hashing.
B. A structure that maps keys to values
C. A structure used for storage 5.If several elements are competing for the
D. A structure used to implement stack same bucket in the hash table, what is it
and queue called?
Ans : B A. Diffusion
B. Replication
Explanation: A hash table is used to C. Collision
implement associative arrays which has a D. None of the mentioned
key-value pair, so the has table maps keys Ans : C
to values.
Explanation:If several elements are
2. How many different insertion sequences competing for the same bucket in the hash
of the key values using the same hash table, is it called Collision.
function and linear probing will result in the
hash table shown above? 6. Consider a hash table of size seven,
A. 10 with starting index zero, and a hash
B. 20 function (3x + 4)mod7. Assuming the hash
C. 30 table is initially empty, which of the
D. 40 following is the contents of the table when
Ans : C the sequence 1, 3, 8, 10 is inserted into
the table using closed hashing? Note that
Explanation: In a valid insertion sequence, ‘_’ denotes an empty location in the table.
the elements 42, 23 and 34 must appear A. 8, _, _, _, _, _, 10
before 52 and 33, and 46 must appear B. 1, 8, 10, _, _, _, 3
before 33. C. 1, _, _, _, _, _,3
Total number of different sequences = 3! x D. 1, 10, 8, _, _, _, 3
5 = 30 Ans : B
In the above expression, 3! is for elements
42, 23 and 34 as they can appear in any Explanation: hashing and probing. Let us
order, and 5 is for element 46 as it can put values 1, 3, 8, 10 in the hash of size 7.
appear at 5 different places. Initially, hash table is empty
-------
3. If ' h ' is a hashing function and it is 0123456
used to hash ' n ' keys into a table of size ' The value of function (3x + 4)mod 7 for 1
m ' where n <= m . What is the expected is 0, so let us put the value at 0
number of collisions involving a particular 1------
key ' x ' ? 0123456
A. less than 1. The value of function (3x + 4)mod 7 for 3
B. less than n. is 6, so let us put the value at 6
C. less than m. 1-----3
D. less than n / 2. 0123456
Ans : A The value of function (3x + 4)mod 7 for 8
is 0, but 0 is already occupied, let us put
4.Hashing technique which allocates fixed the value(8) at next available space(1)
number of buckets is classified as 18----3
A. dynamic hashing 0123456
B. static hashing The value of function (3x + 4)mod 7 for 10
C. external hashing is 6, but 6 is already occupied, let us put
D. internal hashing the value(10) at next available space(2)
Ans : C 1 8 10 - - - 3
0123456
7. What is the advantage of using a Ans : A
dynamic set in direct addressing?
A. It saves time Explanation: Direct addressing is possible
B. It saves space only when we can afford to allocate an
C. It saves both time and space array that has one position for every
D. None of the mentioned possible key.
Ans : B
12. What is the search complexity in direct
Explanation: Using a dynamic set, the size addressing?
of the array is restricted to the number of A. O(n)
keys, hence saves space. B. O(logn)
C. O(nlogn)
8. In linear hashing, formula used to D. O(1)
calculate number of records if blocking Ans : D
factor, loading factor and file buckets are
known is as Explanation: Since every key has a unique
A. r =l + bfr + N array position, searching takes a constant
B. r =l - bfr - N time.
C. r =l + bfr - N
D. r =l * bfr * N 13. What is a hash function?
Ans : D A. A function has allocated memory to
keys
9. What is the load factor? B. A function that computes the location of
A. Average array size the key in the array
B. Average key size C. A function that creates an array
C. Average chain length D. None of the mentioned
D. None of the mentioned Ans : B
Ans : C
Explanation: In a hash table, there are
Explanation:In simple chaining, load factor fewer array positions than the keys, so the
is the average number of elements stored position of the key in the array has to be
in a chain, and is given by the ratio of computed, this is done using the hash
number of elements stored to the number function.
of slots in the array. .
14. What can be the techniques to avoid
10. Given a hash table T with 25 slots that collision?
stores 2000 elements, the load factor α for A. Make the hash function appear random
T is __________ B. Use the chaining method
A. 80 C. Use uniform hashing
B. 0.0125 D. All of the mentioned
C. 8000 Ans : D
D. 1.25
Ans : A Explanation: Making the hash function
random is not really a good choice,
Explanation:load factor = (no. of elements) although it is considered one of the
/ (no. of table slots) = 2000/25 = 80. techniques to avoid collisions along with
chaining and simple uniform hashing.
11. What is direct addressing?
A. Distinct array position for every possible
key
B. Fewer array positions than keys
C. Fewer keys than array positions
D. None of the mentioned
15. What is simple uniform hashing? 19. Given the following input (4322, 1334,
A. Every element has equal probability of 1471, 9679, 1989, 6171, 6173, 4199) and
hashing into any of the slots the hash function x mod 10, which of the
B. A weighted probabilistic method is used following statements are true?
to hash elements into the slots i. 9679, 1989, 4199 hash to the same
C. All of the mentioned value
D. None of the mentioned ii. 1471, 6171 hash to the same value
Ans : A iii. All elements hash to the same value
iv. Each element hashes to a different
Explanation: In simple uniform hashing, value
any given element is equally likely to hash
into any of the slots available in the array. A. i only
B. ii only
16. In simple uniform hashing, what is the C. i and ii only
search complexity? D. iii or iv
A. O(n) Ans : C
B. O(logn)
C. O(nlogn) Hash function given is mod(10).
D. O(1) 9679, 1989 and 4199 all these give same
View Answer hash value i.e 9
Ans : D 1471 and 6171 give hash value 1

Explanation: There are two cases, once


when the search is successful and when it
is unsuccessful, but in both the cases, the
complexity is O(1+alpha) where 1 is to
compute the hash function and alpha is
the load factor.

17. In simple chaining, what data structure


is appropriate?
A. Singly linked list
B. Doubly linked list
C. Circular linked list
D. Binary trees
Ans : B

Explanation: Deletion becomes easier with


doubly linked list, hence it is appropriate.

18.Which of these are core interfaces in


the collection framework. Select the one
correct answer.
A. Tree
B. Stack
C. Queue
D. Map
E. LinkedList
Ans : D
Algorithm
1. ___________ is a step-by-step 5. An algorithm should have __________
procedure, which defines a set of well-defined outputs
instructions to be executed in a certain A. 0
order to get the desired output. B. 1
A. Code C. 0 or more
B. Algorithm D. 1 or more
C. Program Ans : D
D. All of the above
Ans : B Explanation: An algorithm should have 1
or more well-defined outputs, and should
Explanation: Algorithm is a step-by-step match the desired output.
procedure, which defines a set of
instructions to be executed in a certain 6. Which of the following is a theoretical
order to get the desired output. analysis of an algorithm?
A. Posterior Analysis
2. Which of the following are B. Priori Analysis
characteristics of an algorithm? C. Simple Analysis
A. Algorithm should be clear D. Preori Analysis
B. Algorithm should be unambiguous Ans : B
C. Algorithms must terminate after a finite
number of steps Explanation: A Priori Analysis : This is a
D. All of the above theoretical analysis of an algorithm.
Ans : D Efficiency of an algorithm is measured by
assuming that all other factors, for
Explanation: All of the above are example, processor speed, are constant
Characteristics of an Algorithm and have no effect on the implementation.

3. Not all procedures can be called an 7. _________ is measured by counting the


algorithm number of key operations such as
A. TRUE comparisons in the sorting algorithm.
B. FALSE A. Space
C. Can be true or false B. Lines
D. Can not say C. Time
Ans : A D. None of the above
Ans : C
Explanation: True, Not all procedures can
be called an algorithm. Explanation: Time is measured by
counting the number of key operations
4. An algorithm should have _______ well- such as comparisons in the sorting
defined inputs. algorithm.
A. 0
B. 1 8. The complexity of an algorithm f(n)
C. 0 or more gives the running time and/or the storage
D. 1 or more space required by the algorithm in terms of
Ans : C n as the size of input data.
A. Yes
Explanation: An algorithm should have 0 B. No
or more well-defined inputs. C. Can be yes or no
D. Can not say
Ans : A

Explanation: Yes, The complexity of an


algorithm f(n) gives the running time
and/or the storage space required by the
algorithm in terms of n as the size of input
data.

9. The space required by an algorithm is


equal to the sum of ________
components.
A. 1
B. 2
C. 3
D. 4
Ans : B

Explanation: The space required by an


algorithm is equal to the sum of the
following two components : fixed part and
variable part.

10. Space complexity S(P) of any


algorithm P is S(P) = C + SP(I), where C is
the?
A. fixed part
B. variable part
C. space complexity
D. None of the above
Ans : A

Explanation: Space complexity S(P) of any


algorithm P is S(P) = C + SP(I), where C is
the fixed part and S(I) is the variable part
of the algorithm, which depends on
instance characteristic I.

You might also like