0% found this document useful (0 votes)
43 views68 pages

Data Structures MCQs: Arrays & Lists

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

Data Structures MCQs: Arrays & Lists

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

CD3291 Data Structures

(MCQ) UNIT I
1. Which of these best describes an array?
A data structure that shows a hierarchical behaviour

Container of objects of similar types

Arrays are immutable once initialised

Array is not a data structure

Answer: b

How do you initialize an array in C?

int arr[3] = (1,2,3);

int arr(3) = {1,2,3};

int arr[3] = {1,2,3};

int arr(3) = (1,2,3);

Answer: c

3. How do you instantiate an array in Java?

int arr[] = new int(3);

int arr[];

int arr[] = new int[3];

int arr() = new int(3);

Answer: c

4. Which of the following is a correct way to declare a multidimensional array in Java?

int[] arr;

int arr[[]];

int[][]arr;
d) int[[]] arr;

Answer: c

5. a) 3 and 5

5 and 3

2 and 4

4 and 2

Answer: a

6. a) 4

ArrayIndexOutOfBoundsException

InavlidInputException

Answer: c

7. When does the ArrayIndexOutOfBoundsException occur?

Compile-time

Run-time

Not an error

Not an exception at all

Answer: b

8. Which of the following concepts make extensive use of arrays?

Binary trees

Scheduling of processes

Caching

Spatial locality

Answer: d

9. What are the advantages of arrays?

a) Objects of mixed data types can be stored


Elements in an array cannot be sorted

Index of first element of an array is 1

Easier to store elements of same data type

Answer: d

10. What are the disadvantages of arrays?

Data structure like queue or stack cannot be implemented

There are chances of wastage of memory space if elements inserted in an array are lesser than the
allocated size

Index value of an array can be negative

Elements are sequentially accessed

Answer: b

Assuming int is of 4bytes, what is the size of int arr[15];?

15

19

11

60

Answer: d

12. In general, the index of the first element in an array is

-1

Answer: a

13. Elements in an array are accessed

randomly

sequentially

exponentially
d) logarithmically

Answer: a

14. Which of the following is not a disadvantage to the usage of array?

Fixed size

There are chances of wastage of memory space if elements inserted in an array are lesser than the
allocated size

Insertion based on position

Accessing elements at specified positions

Answer: d

15. What is the time complexity of inserting at the end in dynamic arrays?

O(1)

O(n)

O(logn)

Either O(1) or O(n)

Answer: d

16. What is the time complexity to count the number of elements in the linked list?

O(1)

O(n)

O(logn)

O(n2)

Answer: b

17. a) Inserting a node at the beginning of the list

Deleting a node at the beginning of the list

Inserting a node at the end of the list

Deleting a node at the end of the list

Answer: c
18. What is the space complexity for deleting a linked list?

O(1)

O(n)

Either O(1) or O(n)

O(logn)

Answer: a

19. Which of these is not an application of linked list?

To implement file systems

For separate chaining in hash-tables

To implement non-binary trees

Random Access of elements

Answer: d

20. a) Find and delete a given element in the list

Find and return the given element in the list

Find and return the position of the given element in the list

Find and insert a new element in the list

Answer: c

21. Which of the following is false about a doubly linked list?

We can navigate in both the directions

It requires more space than a singly linked list

The insertion and deletion of a node take a bit longer

Implementing a doubly linked list is easier than singly linked list

Answer: d

22. What is the worst case time complexity of inserting a node in a doubly linked list?

O(nlogn)

O(logn)

O(n)

5
d) O(1)

Answer: c

23. a) head-0-1-2-3-4-5-6-tail

head-1-2-3-4-5-6-tail

head-6-1-2-3-4-5-0-tail

head-0-1-2-3-4-5-tail

Answer: c

a) Return the element at the tail of the list but do not remove it

Return the element at the tail of the list and remove it from the list

Return the last but one element from the list but do not remove it

Return the last but one element at the tail of the list and remove it from the list

Answer: b

25. a) head-6-1-2-3-4-5-tail

head-6-1-2-3-4-tail

head-1-2-3-4-5-6-tail

head-1-2-3-4-5-tail

Answer: b

26. What differentiates a circular linked list from a normal linked list?

You cannot have the ‘next’ pointer point to null in a circular linked list

It is faster to traverse the circular linked list

You may or may not have the ‘next’ pointer point to null in a circular linked list

Head node is known in circular linked list

Answer: c

27. a) Print success if a particular element is not found

Print fail if a particular element is not found

Print success if a particular element is equal to 1


⤀ĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀȀ⤀ĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀȀ⤀ĀᜀĀ
ᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀȀ⤀ĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀ
d) Print fail if the list is empty

Answer: b

28. What is the time complexity of searching for an element in a circular linked list?

O(n)

O(nlogn)

O(1)

O(n2)

Answer: a

29. Which of the following application makes use of a circular linked list?

Undo operation in a text editor

Recursive function calls

Allocating CPU to resources

Implement Hash Tables

Answer: c

30. a) Return data from the end of the list

Returns the data and deletes the node at the end of the list

Returns the data from the beginning of the list

Returns the data and deletes the node from the beginning of the list

Answer: d

31. a) Return data from the end of the list

Returns the data and deletes the node at the end of the list

Returns the data from the beginning of the list

Returns the data and deletes the node from the beginning of the list

Answer: b

32. Which of the following is false about a circular linked list?

a) Every node has a successor


Time complexity of inserting a new node at the head of the list is O(1)

Time complexity for deleting the last node is O(n)

We can traverse the whole circular linked list by starting from any point

Answer: b

33. Consider a small circular linked list. How to detect the presence of cycles in this list effectively?

Keep one node as head and traverse another temp node till the end to check if its ‘next points to head

Have fast and slow pointers with the fast pointer advancing two nodes at a time and slow pointer
advancing by one node at a time

Cannot determine, you have to pre-define if the list contains cycles

Circular linked list itself represents a cycle. So no new cycles cannot be generated

Answer: b

34. A linear collection of data elements where the linear node is given by means of pointer is called?

Linked list

Node list

Primitive list

Unordered list

Answer: a

Consider an implementation of unsorted singly linked list. Suppose it has its representation with a
head pointer only.

Given the representation, which of the following operation can be implemented in O(1) time?

Insertion at the front of the linked list

Insertion at the end of the linked list

Deletion of the front node of the linked list

Answer: b

In linked list each node contain minimum of two fields. One field is data field to store the data
second field is?

Pointer to character

Pointer to integer
Pointer to node

Node

Answer: c

What would be the asymptotic time complexity to add a node at the end of singly linked list, if the
pointer is initially pointing to the head of the list?

O(1)

O(n)

θ(n)

θ(1)

Answer: c

What would be the asymptotic time complexity to insert an element at the front of the linked list
(head is known)?

O(1)

O(n)

O(n2)

O(n3)

Answer: a

39. What would be the asymptotic time complexity to find an element in the linked list?

O(1)

O(n)

O(n2)

O(n4)

Answer: b

What would be the asymptotic time complexity to insert an element at the second position in the
linked list?

O(1)

O(n)

O(n2)

9
d) O(n3)

Answer: a

The concatenation of two list can performed in O(1) time. Which of the following variation of
linked list can be used?

ᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀȀ⤀ĀĀĀĀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀ Singly linked list

ᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀȀ⤀ĀĀĀĀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀ Doubly linked list

ᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀȀ⤀ĀĀĀĀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀ Circular doubly linked list

ᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀȀ⤀ĀĀĀĀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀ Array implementation of list

Answer: c

42. Which of the following c code is used to create new node?

ptr = (NODE*)malloc(sizeof(NODE));

ptr = (NODE*)malloc(NODE);

ptr = (NODE*)malloc(sizeof(NODE*));

ptr = (NODE)malloc(sizeof(NODE));

Answer: a
CS8391 Data Structures
Anna University :: Regulations 2017 Multiple Choice Questions
(MCQ) UNIT II LINEAR DATA STRUCTURES – STACKS,
QUEUES
1. Process of inserting an element in stack is called

Create

Push

Evaluation

Pop

Answer: b

2. Process of removing an element from stack is called

Create

Push

Evaluation

Pop

Answer: d

3. In a stack, if a user tries to remove an element from empty stack it is called

Underflow

Empty collection

Overflow

Garbage Collection

Answer: a

4. Pushing an element into stack already having five elements and stack size of 5, then stack becomes

Overflow

Crash

Underflow
d) User flow

Answer: a

Entries in a stack are “ordered”. What is the meaning of this statement?

ᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀȀЀĀȀ⤀ĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀ A collection of stacks is sortable

ᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀȀЀĀȀ⤀ĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀ Stack entries may be compared with the ‘<‘


operation

ᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀȀЀĀȀ⤀ĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀ The entries are stored in a linked list

ᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀȀЀĀȀ⤀ĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀ There is a Sequential entry that is one by one

Answer: d

6. Which of the following is not the application of stack?

A parentheses balancing program

Tracking of local variables at run time

Compiler Syntax Analyzer

Data Transfer between two asynchronous process

Answer: d

7. Consider the usual algorithm for determining whether a sequence of parentheses is balanced.

The maximum number of parentheses that appear on the stack AT ANY ONE TIME when the algorithm
analyzes: (()(())(())) are:

Answer: c

8. Consider the usual algorithm for determining whether a sequence of parentheses is balanced.

Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses
(in some order).

The maximum number of parentheses that appear on the stack AT ANY ONE TIME during the computation?

Answer: b
2
9. What is the value of the postfix expression 6 3 2 4 + – *?

40

74

-18

Answer: d

Here is an infix expression: 4 + 3*(6*3-12). Suppose that we are using the usual stack algorithm to
convert the expression from infix to postfix notation.

The maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this
expression?

Answer: d

11. The postfix form of the expression (A+ B)*(C*D- E)*F / G is?

AB+ CD*E – FG /**

AB+CD*E–F**G/

AB+CD*E–*F*G/

AB+CDE*–*F*G/

Answer: c

12. The data structure required to check whether an expression contains balanced parenthesis is?

Stack

Queue

Array

Tree

Answer: a
⤀ĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀȀ⤀ĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀȀ⤀ĀᜀĀ
ᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀЀĀȀ⤀ĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀĀᜀ
What data structure would you mostly likely see in a non recursive implementation of a recursive
algorithm?

Linked List

Stack

Queue

Tree

Answer: b

14. The process of accessing data stored in a serial access memory is similar to manipulating data on a

Heap

Binary Tree

Array

Stack

Answer: d

15. The postfix form of A*B+C/D is?

*AB/CD+

AB*CD/+

A*BC+/D

ABCD+/*

Answer: b

16. Which data structure is needed to convert infix notation to postfix notation?

Branch

Tree

Queue

Stack

Answer: d

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

a) -/*^ACBDE
-ABCD*^DE

-A/B*C^DE

-A/BC*^DE

Answer: c

18. What is the result of the following operation?

Top (Push (S, X))

X+S

Answer: a

19. The prefix form of an infix expression (p + q) – (r * t) is?

+ pq – *rt

– +pqr * t

– +pq * rt

– + * pqrt

Answer: c

20. Which data structure is used for implementing recursion?

Queue

Stack

Array

List

Answer: b

21. When an operand is read, which of the following is done?

It is placed on to the output

It is placed in operator stack

It is ignored

Operator stack is emptied


Answer: a

What should be done when a left parenthesis ‘(‘ is encountered?

It is ignored

It is placed in the output

It is placed in the operator stack

The contents of the operator stack is emptied

Answer: c

23. Which of the following is an infix expression?

(a+b)*(c+d)

ab+c*

+ab

abc+*

Answer: a

24. What is the time complexity of an infix to postfix conversion algorithm?

O(N log N)

O(N)

O(N2)

O(M log N)

Answer: b

25. a) abc*+de*+

abc+*de*+

a+bc*de+*

abc*+(de)*+

Answer: a

26. a) -ab-c

b) ab – c –

6
– -abc

-ab-c

Answer: b

27. a) abc^/d-

ab/cd^-

ab/^cd-

abcd^/-

Answer: a

28. Which of the following statement is incorrect with respect to infix to postfix conversion algorithm?

operand is always placed in the output

operator is placed in the stack when the stack operator has lower precedence

parenthesis are included in the output

higher and equal priority operators follow the same condition

Answer: c

29. In infix to postfix conversion algorithm, the operators are associated from?

right to left

left to right

centre to left

centre to right

Answer: b

30. a) ab*+cd/

ab+*cd/

abc*+/d

abc+*d/

Answer: d

31. a) ab*cdef/^*g-h+
abcdef^/*g*h*+

abcd*^ed/g*-h*+

abc*de^fg/*-*h+

Answer: b

32. a) abc^de-fg+*^*+i-

abcde^-fg*+*^h*+i-

abcd^e-fgh*+^*+i-

ab^-dc*+ef^gh*+i-

Answer: c

33. From the given Expression tree, identify the correct postfix expression from the list of options.

ab*cd*+

ab*cd-+

abcd-*+

Answer: b

A linear list of elements in which deletion can be done from one end (front) and insertion can take
place only at the other end (rear) is known as a ?

Queue

Stack

Tree

Linked list

Answer: a

35. The data structure required for Breadth First Traversal on a graph is?

Stack

Array

Queue

Tree

Answer: c

8
36. A queue follows

FIFO (First In First Out) principle

LIFO (Last In First Out) principle

Ordered array

Linear tree

Answer: a

37. Circular Queue is also known as

Ring Buffer

Square Buffer

Rectangle Buffer

Curve Buffer

Answer: a

If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what
order will they be removed?

ABCD

DCBA

DCAB

ABDC

Answer: a

A data structure in which elements can be inserted or deleted at/from both the ends but not in the
middle is?

Queue

Circular queue

Dequeue

Priority queue

Answer: c

40. A normal queue, if implemented using an array of size MAX_SIZE, gets full when
Rear = MAX_SIZE – 1

Front = (rear + 1)mod MAX_SIZE

Front = rear + 1

Rear = front

Answer: a

41. Queues serve major role in

Simulation of recursion

Simulation of arbitrary linked list

Simulation of limited resource allocation

Simulation of heap sort

Answer: c

42. Which of the following is not the type of queue?

Ordinary queue

Single ended queue

Circular queue

Priority queue

Answer: b

43. With what data structure can a priority queue be implemented?

Array

List

Heap

Tree

Answer: d

44. Which of the following is not an application of priority queue?

Huffman codes

Interrupt handling in operating system

Undo operation in text editors


d) Bayesian spam filter

Answer: c

45. What is the time complexity to insert a node based on key in a priority queue?

O(nlogn)

O(logn)

O(n)

O(n2)

Answer: c

46. a) Delete the second element in the list

Return but not delete the second element in the list

Delete the first element in the list

Return but not delete the first element in the list

Answer: c

47. What is not a disadvantage of priority scheduling in operating systems?

A low priority process might have to wait indefinitely for the CPU

If the system crashes, the low priority systems may be lost permanently

Interrupt handling

Indefinite blocking

Answer: c

48. Which of the following is not an advantage of priority queue?

Easy to implement

Processes with different priority can be efficiently handled

Applications with differing requirements

Easy to delete elements in any case

Answer: d

49. What is the time complexity to insert a node based on position in a priority queue?
O(nlogn)

O(logn)

O(n)

O(n2)

Answer: c

50. What is a dequeue?

A queue with insert/delete defined for both front and rear ends of the queue

A queue implemented with a doubly linked list

A queue implemented with both singly and doubly linked lists

A queue with insert/delete defined for front side of the queue

Answer: a

51. a) Insert at the front end of the dequeue

Insert at the rear end of the dequeue

Fetch the element at the rear end of the dequeue

Fetch the element at the front end of the dequeue

Answer: b

52. What are the applications of dequeue?

A-Steal job scheduling algorithm

Can be used as both stack and queue

To find the maximum of all sub arrays of size k

To avoid collision in hash tables

Answer: d

53. a) 10 30 10 15

20 30 40 15

20 30 40 10

10 30 40 15

Answer: d

12
54. Which of the following properties is associated with a queue?

First In Last Out

First In First Out

Last In First Out

Last In Last Out

Answer: b

55. In a circular queue, how do you increment the rear end of the queue?

rear++

(rear+1) % CAPACITY

(rear % CAPACITY)+1

rear–

Answer: b

56. What is the term for inserting into a full queue known as?

overflow

underflow

null pointer exception

program won’t be compiled

Answer: a

57. What is the time complexity of enqueue operation?

O(logn)

O(nlogn)

O(n)

O(1)

Answer: d

58. a) Dequeue

b) Enqueue

13
Return the front element

Return the last element

Answer: c

59. What is the need for a circular queue?

effective usage of memory

easier computations

to delete elements based on priority

implement LIFO principle in queues

Answer: a

60. What is the space complexity of a linear queue having n elements?

O(n)

O(nlogn)

O(logn)

O(1)

Answer: a

a) 3 3

36

66

10 6

Answer: a
CS8391 Data Structures
Anna University :: Regulations 2017 Multiple Choice Questions
(MCQ) UNIT III NON LINEAR DATA STRUCTURES – TREES

1. What is the maximum number of children that a binary tree node can have?

Answer: c

2. The following given tree is an example for?

Binary tree

Binary search tree

Fibonacci tree

Answer: a

3. How many common operations are performed in a binary tree?

Answer: c

4. What is the traversal strategy used in the binary tree?

depth-first traversal

breadth-first traversal
random traversal

1 Downloaded From: https://cse- 17.blogspot.com


d) Priority traversal

Answer: b

5. How many types of insertion are performed in a binary tree?

Answer: b

6. What operation does the following diagram depict?

inserting a leaf node

inserting an internal node

deleting a node with 0 or 1 child

Answer: c

7. How many bits would a succinct binary tree occupy?

n+O(n)

2n+O(n)

n/2

Answer: b

8. The average depth of a binary tree is given as?

O(N)

O(√N)

O(N2)

O(log N)

Answer: d

9. How many orders of traversal are applicable to a binary tree (In General)?
1

Answer: d

If binary trees are represented in arrays, what formula can be used to locate a left child, if the node
has an index i?

2i+1

2i+2

2i

4i

Answer: a

11. Using what formula can a parent node be located in an array?

(i+1)/2

(i-1)/2

i/2

2i/2

Answer: b

12. Which of the following properties are obeyed by all three tree – traversals?

Left subtrees are visited before right subtrees

Right subtrees are visited before left subtrees

Root node is visited before left subtree

Root node is visited before right subtree

Answer: a

13. Construct a binary tree using the following data.

The preorder traversal of a binary tree is 1, 2, 5, 3, 4. The inorder traversal of the same binary tree is 2, 5, 1,
4, 3.

a)
3
b)

c)

Answer: d

14. For the tree below, write the pre-order traversal.

2, 7, 2, 6, 5, 11, 5, 9, 4

2, 7, 5, 2, 6, 9, 5, 11, 4

2, 5, 11, 6, 7, 4, 9, 5, 2

Answer: a

15. For the tree below, write the post-order traversal.

2, 7, 2, 6, 5, 11, 5, 9, 4

2, 7, 5, 2, 6, 9, 5, 11, 4

2, 5, 11, 6, 7, 4, 9, 5, 2

Answer: c

16. What is the time complexity of pre-order traversal in the iterative fashion?

O(1)

O(n)

O(logn)

O(nlogn)

Answer: b

What is the space complexity of the post-order traversal in the recursive fashion? (d is the tree
depth and n is the number of nodes)

O(1)

O(nlogd)

O(logd)

O(d)

Answer: d
18. To obtain a prefix expression, which of the tree traversals is used?

Level-order traversal

Pre-order traversal

Post-order traversal

In-order traversal

Answer: b

Consider the following data. The pre order traversal of a binary tree is A, B, E, C, D. The in order
traversal of the same binary tree is B, E, A, D, C. The level order sequence for the binary tree is

A,C,D,B,E

A,B,C,D,E

A,B,C,E,D

D,B,E,A,C

Answer: b

Consider the following data and specify which one is Preorder Traversal Sequence, Inorder and
Postorder sequences.

S1: N, M, P, O, Q

S2: N, P, Q, O, M

S3: M, N, O, P, Q

a) S1 is preorder, S2 is inorder and S3 is postorder

Answer: c

What is the possible number of binary trees that can be created with 3 nodes, giving the sequence N,
M, L when traversed in post-order.

15

Answer: c
22. The post-order traversal of a binary tree is O P Q R S T. Then possible pre-order traversal will be

TQRSOP

TOQRPS

TQOPSR

TQOSPR

Answer: c

A binary search tree contains values 7, 8, 13, 26, 35, 40, 70, 75. Which one of the following is a valid post-
order sequence of the tree provided the pre-order sequence as 35, 13, 7, 8, 26, 70, 40 and 75?

7, 8, 26, 13, 75, 40, 70, 35

26, 13, 7, 8, 70, 75, 40, 35

7, 8, 13, 26, 35, 40, 70, 75

8, 7, 26, 13, 40, 75, 70, 35

Answer: d

Which of the following pair’s traversals on a binary tree can build the tree uniquely?

post-order and pre-order

post-order and in-order

post-order and level order

level order and preorder

Answer: b

25. A full binary tree can be generated using

post-order and pre-order traversal

pre-order traversal

post-order traversal

in-order traversal

Answer: a

The maximum number of nodes in a tree for which post-order and pre-order traversals may be
equal is
3

any number

Answer: b

The pre-order and in-order are traversals of a binary tree are T M L N P O Q and L M N T O P Q.
Which of following is post-order traversal of the tree?

LNMOQPT

NMOPOLT

LMNOPQT

OPLMNQT

Answer: a

28. Find the postorder traversal of the binary tree shown below.

PQRSTUVWX

WRSQPVTUX

SWTQXUVRP

Answer: c

29. For the tree below, write the in-order traversal.

6, 2, 5, 7, 11, 2, 5, 9, 4

6, 5, 2, 11, 7, 4, 9, 5, 2

2, 7, 2, 6, 5, 11, 5, 9, 4

Answer: a

30. For the tree below, write the level-order traversal.

2, 7, 2, 6, 5, 11, 5, 9, 4

2, 7, 5, 2, 11, 9, 6, 5, 4

2, 5, 11, 6, 7, 4, 9, 5, 2

Answer: b

7
What is the space complexity of the in-order traversal in the recursive fashion? (d is the tree depth
and n is the number of nodes)

O(1)

O(nlogd)

O(logd)

O(d)

Answer: d

32. What is the time complexity of level order traversal?

O(1)

O(n)

O(logn)

O(nlogn)

Answer: b

33. Which of the following graph traversals closely imitates level order traversal of a binary tree?

Depth First Search

Breadth First Search

Depth & Breadth First Search

Binary Search

Answer: b

In a binary search tree, which of the following traversals would print the numbers in the ascending
order?

Level-order traversal

Pre-order traversal

Post-order traversal

In-order traversal

Answer: d

35. The number of edges from the root to the node is called of the tree.
a) Height

b) Depth

c) Length

d) Width

Answer: b

36. The number of edges from the node to the deepest leaf is called of the tree.

a) Height

b) Depth

c) Length

d) Width

Answer: a

37. What is a full binary tree?

a) Each node has exactly zero or two children

b) Each node has exactly two children

c) All the leaves are at the same level

d) Each node has exactly one or two children

Answer: a

38. What is a complete binary tree?

Each node has exactly zero or two children

A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled
from right to left

A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled
from left to right

A tree In which all nodes have degree 2

Answer: c

39. What is the average case time complexity for finding the height of the binary tree?

h = O(loglogn)

h = O(nlogn)
h = O(n)

h = O(log n)

Answer: d

40. Which of the following is not an advantage of trees?

Hierarchical structure

Faster search

Router algorithms

Undo/Redo operations in a notepad

Answer: d

41. In a full binary tree if number of internal nodes is I, then number of leaves L are?

L=2*I

L=I+1

L=I–1

L=2*I–1

Answer: b

42. In a full binary tree if number of internal nodes is I, then number of nodes N are?

N=2*I

N=I+1

N=I–1

N=2*I+1

Answer: d

43. In a full binary tree if there are L leaves, then total number of nodes N are?

N=2*L

N=L+1

N=L–1

N=2*L–1

Answer: d

10
44. Which of the following is incorrect with respect to binary trees?

Let T be a binary tree. For every k ≥ 0, there are no more than 2k nodes in level k

Let T be a binary tree with λ levels. Then T has no more than 2λ – 1 nodes

Let T be a binary tree with N nodes. Then the number of levels is at least ceil(log (N + 1))

Let T be a binary tree with N nodes. Then the number of levels is at least floor(log (N + 1))

Answer: d

45. Construct a binary tree by using postorder and inorder sequences given below.

Inorder: N, M, P, O, Q

Postorder: N, P, Q, O, M

a)

b)

Answer: d

46. Construct a binary search tree by using postorder sequence given below.

Postorder: 2, 4, 3, 7, 9, 8, 5.

a)

b)

c)

Answer: b

47. Construct a binary tree using inorder and level order traversal given below.

Inorder Traversal: 3, 4, 2, 1, 5, 8, 9

Level Order Traversal: 1, 4, 5, 9, 8, 2, 3

a)

b)

Answer: a

48. Which of the following is false about a binary search tree?

a) The left child is always lesser than its parent


The right child is always greater than its parent

The left and right sub-trees should also be binary search trees

In order sequence gives decreasing order of elements

Answer: d

49. What is the speciality about the inorder traversal of a binary search tree?

It traverses in a non increasing order

It traverses in an increasing order

It traverses in a random fashion

It traverses based on priority of the node

Answer: b

50. a) Preorder traversal

Inorder traversal

Postorder traversal

Level order traversal

Answer: c

51. a) Preorder traversal

Inorder traversal

Postorder traversal

Level order traversal

Answer: a

52. What are the worst case and average case complexities of a binary search tree?

O(n), O(n)

O(logn), O(logn)

O(logn), O(n)

O(n), O(logn)

Answer: d

12
53. What are the conditions for an optimal binary search tree and what is its advantage?

The tree should not be modified and you should know how often the keys are accessed, it improves the
lookup cost

You should know the frequency of access of the keys, improves the lookup time

The tree can be modified and you should know the number of elements in the tree before hand, it improves
the deletion time

The tree should be just modified and improves the lookup time

Answer: a

54. Construct a binary search tree with the below information.

The preorder traversal of a binary search tree 10, 4, 3, 5, 11, 12.

a)

b)

c)

Answer: c

55. Which of the following is not the self balancing binary search tree?

AVL Tree

2-3-4 Tree

Red – Black Tree

Splay Tree

Answer: b

56. The binary tree sort implemented using a self – balancing binary search tree takes time is
worst case.

O(n log n)

O(n)

O(n2)

O(log n)

Answer: a

An AVL tree is a self – balancing binary search tree, in which the heights of the two child sub trees of
any node differ by
At least one

At most one

Two

At most two

Answer: b

58. Associative arrays can be implemented using

B-tree

A doubly linked list

A single linked list

A self balancing binary search tree

Answer: d

59. Which of the following is a self – balancing binary search tree?

2-3 tree

Threaded binary tree

AA tree

Treap

Answer: c

60. A self – balancing binary search tree can be used to implement

Priority queue

Hash table

Heap sort

Priority queue and Heap sort

Answer: a

In which of the following self – balancing binary search tree the recently accessed element can be
accessed quickly?

AVL tree

AA tree

14
Splay tree

Red – Black tree

Answer: c

62. The minimum height of self balancing binary search tree with n nodes is

log2(n)

2n + 1

2n – 1

Answer: a

63. What is an AVL tree?

a tree which is balanced and is a height balanced tree

a tree which is unbalanced and is a height balanced tree

a tree with three children

a tree with atmost 3 children

Answer: a

64. Why we need to a binary tree which is height balanced?

to avoid formation of skew trees

to save memory

to attain faster memory access

to simplify storing

Answer: a

65. Which of the below diagram is following AVL tree property?

i.

ii.

only i

only i and ii

Answer: b

15
66. What is the maximum height of an AVL tree with p nodes?

log(p)

log(p)/2

P⁄2

Answer: b

Given an empty AVL tree, how would you construct AVL tree when a set of numbers are given
without performing any rotations?

just build the tree with the given input

find the median of the set of elements given, make it as root and construct the tree

use trial and error

use dynamic programming to build the tree

Answer: b

68. What maximum difference in heights between the leafs of a AVL tree is possible?

log(n) where n is the number of nodes

n where n is the number of nodes

0 or 1

atmost 1

Answer: a

69. What is missing?

Height(w-left), x-height

Height(w-right), x-height

Height(w-left), x

Height(w-left)

Answer: a

70. Why to prefer red-black trees over AVL trees?


Because red-black is more rigidly balanced

AVL tree store balance factor in every node which costs space

AVL tree fails at scale

Red black is more efficient

Answer: b

71. Which of the following is the most widely used external memory data structure?

AVL tree

B-tree

Red-black tree

Both AVL tree and Red-black tree

Answer: b

72. B-tree of order n is a order-n multiway tree in which each non-root node contains

a) at most (n – 1)/2 keys

b) exact (n – 1)/2 keys

c) at least 2n keys

d) at least (n – 1)/2 keys

Answer: d

73. A B-tree of order 4 and of height 3 will have a maximum of keys.

a) 255

b) 63

c) 127

d) 188

Answer: a

Five node splitting operations occurred when an entry is inserted into a B-tree. Then how many
nodes are written?

14

17
11

Answer: c

75. trees are B-trees of order 4. They are an isometric of trees.

AVL

AA

2-3

Red-Black

Answer: d

76. Figure shown below is B-tree of order 5. What is the result of deleting 130 from the tree?

a)

b)

c)

Answer: c

77. What is the best case height of a B-tree of order n and which has k keys?

logn (k+1) – 1

nk

logk (n+1) – 1

klogn

Answer: a

78. Which of the following is true?

larger the order of B-tree, less frequently the split occurs

larger the order of B-tree, more frequently the split occurs

smaller the order of B-tree, more frequently the split occurs

smaller the order of B-tree, less frequently the split occurs

Answer: a
79. In a max-heap, element with the greatest key is always in the which node?

Leaf node

First node of left sub tree

root node

First node of right sub tree

Answer: c

80. What is the complexity of adding an element to the heap.

O(log n)

O(h)

O(log n) & O(h)

O(n)

Answer: c

81. The worst case complexity of deleting any arbitrary node value element from heap is

O(logn)

O(n)

O(nlogn)

O(n2)

Answer: a

82. Heap can be used as

Priority queue

Stack

A decreasing order array

Normal Array

Answer: a

83.

If we implement heap as min-heap, deleting root node (value 1)from the heap. What would be the value of
root node after second iteration if leaf node (value 100) is chosen to replace the root at start.
2

100

17

Answer: a

84.

If we implement heap as maximum heap , adding a new node of value 15 to the left most node of right
subtree . What value will be at leaf nodes of the right subtree of the heap.

15 and 1

25 and 1

3 and 1

Answer: a

An array consists of n elements. We want to create a heap using the elements. The time complexity of
building a heap will be in order of

O(n*n*logn)

O(n*logn)

O(n*n)

O(n *logn *logn)

Answer: b
CS8391 Data Structures
Anna University :: Regulations 2017 Multiple Choice Questions
(MCQ) UNIT IV NON LINEAR DATA STRUCTURES – GRAPHS

1. Which of the following statements for a simple graph is correct?

Every path is a trail

Every trail is a path

Every trail is a path as well as every path is a trail

Path and trail have no relation

Answer: a

2. In the given graph identify the cut vertices.

B and E

C and D

A and E

Answer: d

3. For the given graph(G), which of the following statements is true?

G is a complete graph

G is not a connected graph

The vertex connectivity of the graph is 2

Answer: c

What is the number of edges present in a complete graph having n vertices?

(n*(n+1))/2

(n*(n-1))/2

Information given is insufficient


Answer: b

5. The given Graph is regular.

a) True

b) False

Answer: a

6. A connected planar graph having 6 vertices, 7 edges contains regions.

a) 15

b) 3

c) 1

d) 11

Answer: b

If a simple graph G, contains n vertices and m edges, the number of edges in the Graph
G'(Complement of G) is

(n*n-n-2*m)/2

(n*n+n+2*m)/2

(n*n-n-2*m)/2

(n*n-n+2*m)/2

Answer: a

8. Which of the following properties does a simple graph not hold?

Must be connected

Must be unweighted

Must have no loops or multiple edges

Must have no multiple edges

Answer: a

9. What is the maximum number of edges in a bipartite graph having 10 vertices?

a) 24

2
21

25

16

Answer: c

10. Which of the following is true?

A graph may contain no edges and many vertices

A graph may contain many edges and no vertices

A graph may contain no edges and no vertices

A graph may contain no vertices and many edges

Answer: b

For a given graph G having v vertices and e edges which is connected and has no cycles, which of
the following statements is true?

v=e

v = e+1

v+1=e

v = e-1

Answer: b

For which of the following combinations of the degrees of vertices would the connected graph be
eulerian?

1,2,3

2,3,4

2,4,5

1,3,5

Answer: a

13. A graph with all vertices having equal degree is known as a

Multi Graph

Regular Graph

Simple Graph
d) Complete Graph

Answer: b

14. Which of the following ways can be used to represent a graph?

Adjacency List and Adjacency Matrix

Incidence Matrix

Adjacency List, Adjacency Matrix as well as Incidence Matrix

No way to represent

Answer: c

The number of possible undirected graphs which may have self loops but no multiple edges and
have n vertices is

2((n*(n-1))/2)

2((n*(n+1))/2)

2((n-1)*(n-1))/2)

2((n*n)/2)

Answer: d

Given a plane graph, G having 2 connected component, having 6 vertices, 7 edges and 4 regions.
What will be the number of connected components?

Answer: b

17. Number of vertices with odd degrees in a graph having a eulerian walk is

Can’t be predicted

either 0 or 2

Answer: d
4
18. How many of the following statements are correct?

All cyclic graphs are complete graphs.

All complete graphs are cyclic graphs.

All paths are bipartite.

All cyclic graphs are bipartite.

Answer: b

19. What is the number of vertices of degree 2 in a path graph having n vertices,here n>2.

n-2

Answer: a

20. Which of the following graphs are isomorphic to each other?

fig 1 and fig 2

fig 2 and fig 3

fig 1 and fig 3

Answer: d

21. In the given graph which edge should be removed to make it a Bipartite Graph?

A-C

B-E

C-D

Answer: a

What would the time complexity to check if an undirected graph with V vertices and E edges is
Bipartite or not given its adjacency matrix?

O(E*E)

O(V*V)

5
O(E)

O(V)

Answer: b

23. Which of the following is not a topological sorting of the given graph?

ABCDEF

ABFEDC

ABECFD

Answer: d

24. With V(greater than 1) vertices, how many edges at most can a Directed Acyclic Graph possess?

a) (V*(V-1))/2

b) (V*(V+1))/2

c) (V+1)C2

d) (V-1)C2

Answer: a

25. The topological sorting of any DAG can be done in time.

a) cubic

b) quadratic

c) linear

d) logarithmic

Answer: c

26. If there are more than 1 topological sorting of a DAG is possible, which of the following is true.

Many Hamiltonian paths are possible

No Hamiltonian path is possible

Exactly 1 Hamiltonian path is possible

Given information is insufficient to comment anything

Answer: b
27. What sequence would the BFS traversal of the given graph yield?

AFDBCE

CBAFED

ABDCEF

Answer: c

28. a) 0 2 3 1 4

03241

02341

03214

Answer: b

29. Which of the given statement is true?

All the Cyclic Directed Graphs have topological sortings

All the Acyclic Directed Graphs have topological sortings

All Directed Graphs have topological sortings

All the cyclic directed graphs hace non topological sortings

Answer: d

What is the value of the sum of the minimum in-degree and maximum out-degree of an Directed
Acyclic Graph?

Depends on a Graph

Will always be zero

Will always be greater than zero

May be zero or greater than zero

Answer: b
CS8391 Data Structures
Anna University :: Regulations 2017 Multiple Choice Questions
(MCQ) UNIT V SEARCHING, SORTING AND HASHING
TECHNIQUES

1. Where is linear searching used?

When the list has only a few elements

When performing a single search in an unordered list

Used all the time

When the list has only a few elements and When performing a single search in an unordered list

Answer: d

2. What is the best case for linear search?

O(nlogn)

O(logn)

O(n)

O(1)

Answer: d

3. What is the worst case for linear search?

O(nlogn)

O(logn)

O(n)

O(1)

Answer: c

4. What is the best case and worst case complexity of ordered linear search?

O(nlogn), O(logn)

O(logn), O(nlogn)
O(n), O(1)

O(1), O(n)

Answer: d

5. a) Print the duplicate elements in the array

Print the element with maximum frequency

Print the unique elements in the array

Prints the element with minimum frequnecy

Answer: a

6. Which of the following is a disadvantage of linear search?

Requires more space

Greater time complexities compared to other searching algorithms

Not easy to understand

Not easy to implement

Answer: b

7. What is the advantage of recursive approach than an iterative approach?

Consumes less memory

Less code and easy to implement

Consumes more memory

More code has to be written

Answer: b

8. Given an input arr = {2,5,7,99,899}; key = 899; What is the level of recursion?

Answer: c

2
Given an array arr = {45,77,89,90,94,99,100} and key = 99; what are the mid values(corresponding
array elements) in the first and second levels of recursion?

90 and 99

90 and 94

89 and 99

89 and 94

Answer: a

10. What is the worst case complexity of binary search using recursion?

O(nlogn)

O(logn)

O(n)

O(n2)

Answer: b

11. What is the average case time complexity of binary search using recursion?

O(nlogn)

O(logn)

O(n)

O(n2)

Answer: b

12. Which of the following is not an application of binary search?

To find the lower/upper bound in an ordered sequence

Union of intervals

Debugging

To search in unordered list

Answer: d

13. Binary Search can be categorized into which of the following?

a) Brute Force technique


Divide and conquer

Greedy algorithm

Dynamic programming

Answer: b

Given an array arr = {5,6,77,88,99} and key = 88; How many iterations are done until the element is
found?

Answer: d

Given an array arr = {45,77,89,90,94,99,100} and key = 100; What are the mid
values(corresponding array elements) generated in the first and second iterations?

90 and 99

90 and 100

89 and 94

94 and 99

Answer: a

16. What is the time complexity of binary search with iteration?

O(nlogn)

O(logn)

O(n)

O(n2)

Answer: b

17. What is an external sorting algorithm?

Algorithm that uses tape or disk during the sort

Algorithm that uses main memory during the sort

Algorithm that involves swapping


Algorithm that are considered ‘in place’

Answer: a

18. What is an internal sorting algorithm?

Algorithm that uses tape or disk during the sort

Algorithm that uses main memory during the sort

Algorithm that involves swapping

Algorithm that are considered ‘in place’

Answer: b

19. What is the worst case complexity of bubble sort?

O(nlogn)

O(logn)

O(n)

O(n2)

Answer: d

20. What is the average case complexity of bubble sort?

O(nlogn)

O(logn)

O(n)

O(n2)

Answer: d

Which of the following is not an advantage of optimised bubble sort over other sorting techniques in
case of sorted elements?

It is faster

Consumes less memory

Detects whether the input is already sorted

Consumes less time

Answer: c

5
The given array is arr = {1, 2, 4, 3}. Bubble sort is used to sort the array elements. How many
iterations will be done to sort the array?

Answer: a

23. What is the best case efficiency of bubble sort in the improvised version?

O(nlogn)

O(logn)

O(n)

O(n2)

Answer: c

The given array is arr = {1,2,4,3}. Bubble sort is used to sort the array elements. How many
iterations will be done to sort the array with improvised version?

Answer: b

25. What is an in-place sorting algorithm?

It needs O(1) or O(logn) memory to create auxiliary locations

The input is already sorted and in-place

It requires additional storage

It requires additional space

Answer: a

26. In the following scenarios, when will you use selection sort?
The input is already sorted

A large file has to be sorted

Large values need to be sorted with small keys

Small values need to be sorted with large keys

Answer: c

27. What is the worst case complexity of selection sort?

O(nlogn)

O(logn)

O(n)

O(n2)

Answer: d

28. What is the advantage of selection sort over other sorting techniques?

It requires no additional storage space

It is scalable

It works best for inputs which are already sorted

It is faster than any other sorting technique

Answer: a

29. What is the average case complexity of selection sort?

O(nlogn)

O(logn)

O(n)

O(n2)

Answer: d

30. What is the disadvantage of selection sort?

It requires auxiliary memory

It is not scalable

It can be used for small keys


d) It takes linear time to sort the elements

Answer: b

The given array is arr = {3,4,5,2,1}. The number of iterations in bubble sort and selection sort
respectively are,

5 and 4

4 and 5

2 and 4

2 and 5

Answer: a

The given array is arr = {1,2,3,4,5}. (bubble sort is implemented with a flag variable)The number of
iterations in selection sort and bubble sort respectively are,

5 and 4

1 and 4

0 and 4

4 and 1

Answer: d

33. What is the best case complexity of selection sort?

O(nlogn)

O(logn)

O(n)

O(n2)

Answer: d

34. Shell sort is also known as

diminishing decrement sort

diminishing increment sort

partition exchange sort

diminishing insertion sort

Answer: b
8
35. Statement 1: Shell sort is a stable sorting algorithm.

Statement 2: Shell sort is an in-place sorting algorithm.

Both statements are true

Statement 2 is true but statement 1 is false

Statement 2 is false but statement 1 is true

Answer: b

Shell sort is applied on the elements 27 59 49 37 15 90 81 39 and the chosen decreasing sequence of
increments is (5,3,1). The result after the first iteration will be

27 59 49 37 15 90 81 39

27 59 37 49 15 90 81 39

27 59 39 37 15 90 81 49

15 59 49 37 27 90 81 39

Answer: c

37. Which condition will correctly implement the while loop?

k >= j && y < elements[k- span]

k >= span || y < elements[k + span]

k >= j || y < elements[k + span]

k >= span && y < elements[k- span]

Answer: d

38. Shell sort is an improvement on

insertion sort

selection sort

binary tree sort

quick sort

Answer: a

39. An array that is first 7-sorted, then 5-sorted becomes


7-ordered

5-ordered

both 2-ordered and 5-ordered

both 7-ordered and 5-ordered

Answer: d

If Hibbard increments (h1= 1, h2= 3, h3= 7, …, hk = 2k–1) are used in a Shell sort implementation,
then the best case time complexity will be

O(nlogn)

O(n)

O(n2)

O(logn)

Answer: a

41. Records R1, R2, R3,.. RN with keys K1, K2, K3,.. KN are said to be h-ordered, if

Ki <= Ki+h for 1<= i*h <= N

Kh <= Ki+h for 1<= i <= N

Ki <= Kh for 1<= i <= h

Ki <= Ki+h for 1<= i <= N-h

Answer: d

42. Which of the following is true?

Shell sort’s passes completely sort the elements before going on to the next-smallest gap while Comb
sort’s passes do not completely sort the elements

Shell sort’s passes do not completely sort the elements before going on to the next-smallest gap like in
Comb sort

Comb sort’s passes completely sort the elements before going on to the next-smallest gap like in Shell sort

Shell sort’s passes do not completely sort the elements before going on to the next-smallest gap while
Comb sort’s passes completely sort the elements

Answer: a

43. Which of the following is the distribution sort?

a) Heap sort
Smooth sort

Quick sort

LSD radix sort

Answer: d

44. What is the worst case time complexity of LSD radix sort?

a) O(nlogn)

b) O(wn)

c) O(n)

d) O(n + w)

Answer: b

45. LSD radix sort requires passes to sort N elements.

a) (w/logR)

b) N(w/logR)

c) (w/log(RN))

d) (wN/log(N))

Answer: a

46. Which of the following is false?

LSD radix sort is an integer sorting algorithm

LSD radix sort is a comparison sorting algorithm

LSD radix sort is a distribution sort

LSD radix sort uses bucket sort

Answer: b

47. Which of the following sorting algorithm is stable?

Heap sort

Selection sort

In-place MSD radix sort

LSD radix sort


Answer: d

48. Which of the following should be used to sort a huge database on a fixed-length key field?

Insertion sort

Merge sort

LSD radix sort

Quick sort

Answer: c

49. Which of the following is a combination of LSD and MSD radix sorts?

Forward radix sort

3-way radix quick sort

Trie base radix sort

Flash sort

Answer: a

50. Which of the following is true for the LSD radix sort?

works best for variable length strings

accesses memory randomly

inner loop has less instructions

sorts the keys in left-to-right order

Answer: b

51. Which scheme uses a randomization approach?

hashing by division

hashing by multiplication

universal hashing

open addressing

Answer: c

52. Which hash function satisfies the condition of simple uniform hashing?
h(k) = lowerbound(km)

h(k)= upperbound(mk)

h(k)= lowerbound(k)

h(k)= upperbound(k)

Answer: a

53. a) 14963

14392

12784

14452

Answer: d

54. What is the hash function used in the division method?

h(k) = k/m

h(k) = k mod m

h(k) = m/k

h(k) = m mod k

Answer: b

55. What can be the value of m in the division method?

Any prime number

Any even number

2p – 1

2p

Answer: a

56. Which scheme provides good performance?

open addressing

universal hashing

hashing by division

hashing by multiplication
Answer: b

57. Using division method, in a given hash table of size 157, the key of value 172 be placed at position

19

72

15

17

Answer: c

58. How many steps are involved in creating a hash function using a multiplication method?

Answer: d

59. What is the hash function used in multiplication method?

h(k) = floor( m(kA mod 1))

h(k) = ceil( m(kA mod 1))

h(k) = floor(kA mod m)

h(k) = ceil( kA mod m)

Answer: a

60. What is the advantage of the multiplication method?

only 2 steps are involved

using constant

value of m not critical

simple multiplication

Answer: c
61. What is the table size when the value of p is 7 in multiplication method of creating hash functions?

14

128

49

127

Answer: b

62. What is the value of h(k) for the key 123456?

Given: p=14, s=2654435769, w=32

123

456

70

Answer: d

63. What is the average retrieval time when n keys hash to the same slot?

Theta(n)

Theta(n2)

Theta(nlog n)

Big-Oh(n2)

Answer: a

You might also like