0% found this document useful (0 votes)
12 views74 pages

DS SPT Lecture SK

Uploaded by

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

DS SPT Lecture SK

Uploaded by

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

Technical SPT

Data Structure

Samir Kariya
Que-1
Following is C like pseudo code of a function that takes a number as an
argument, and uses a stack S to do processing.
void fun(int n)
{
Stack S; // Say it creates an empty stack S
while (n > 0)
{ // This line pushes the value of n%2 to stack S
push(&S, n%2);
n = n/2;
} // Run while Stack S is not empty
while (!isEmpty(&S))
printf("%d ", pop(&S)); // pop an element from S and print it
}
What does the above function do in general?
(A) Prints binary representation of n in reverse order
(B) Prints binary representation of n
(C) Prints the value of Log n
(D) Prints the value of Log n in reverse order
Que-1 Ans
Following is C like pseudo code of a function that takes a number as an
argument, and uses a stack S to do processing.
void fun(int n)
{
Stack S; // Say it creates an empty stack S
while (n > 0)
{ // This line pushes the value of n%2 to stack S
push(&S, n%2);
n = n/2;
} // Run while Stack S is not empty
while (!isEmpty(&S))
printf("%d ", pop(&S)); // pop an element from S and print it
}
What does the above function do in general?
(A) Prints binary representation of n in reverse order
(B) Prints binary representation of n
(C) Prints the value of Log n
(D) Prints the value of Log n in reverse order
Que-2
Which of the following is true about linked list
implementation of stack?
(A) In push operation, if new nodes are inserted at the
beginning of linked list, Then in pop operation, nodes
must be removed from end.
(B) In push operation, if new nodes are inserted at the end,
then in pop operation, nodes must be removed from the
beginning.
(C) Both of the above
(D) None of the above
Que-2 Ans
Which of the following is true about linked list
implementation of stack?
(A) In push operation, if new nodes are inserted at the
beginning of linked list, Then in pop operation, nodes
must be removed from end.
(B) In push operation, if new nodes are inserted at the end,
then in pop operation, nodes must be removed from the
beginning.
(C) Both of the above
(D) None of the above
Que-3
The following postfix expression with single digit operands
is evaluated using a stack:
931^/23*+51*-
Note that ^ is the exponentiation operator. The top two
elements of the stack after the first * is evaluated are:

(A) 3,6
(B) 9, 5
(C) 9, 6
(D) 3,5
Que-3 Ans
The following postfix expression with single digit operands
is evaluated using a stack:
931^/23*+51*-
Note that ^ is the exponentiation operator. The top two
elements of the stack after the first * is evaluated are:

(A) 3,6
(B) 9, 5
(C) 9, 6
(D) 3,5
Que-4
• 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:

(A) 1
(B) 2
(C) 3
(D) 4
Que-4 Ans
• 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:

(A) 1
(B) 2
(C) 3
(D) 4
Que-5
• Here is an infix expression: 6 + 5 * ( 8 * 5 – 14 ). 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?

(A) 1
(B) 2
(C) 3
(D) 4
Que-5 Ans
• Here is an infix expression: 6 + 5 * ( 8 * 5 – 14 ). 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?

(A) 1
(B) 2
(C) 3
(D) 4
Que-6
• What should be the growing direction of two stacks while
implementing them in a similar array so as to reduce the
overflow chances?

(A) Forward
(B) Backward
(C) Opposite
(D) None of the above
Que-6 Ans
• What should be the growing direction of two stacks while
implementing them in a similar array so as to reduce the
overflow chances?

(A) Forward
(B) Backward
(C) Opposite
(D) None of the above
Que-7
What is the postfix form of the following prefix *+ab-cd

(A) Abcd+*-
(B) Ab+*cd-
(C) Ab+cd-*
(D) Ab+-cd*
Que-7 Ans
What is the postfix form of the following prefix *+ab-cd

(A) Abcd+*-
(B) Ab+*cd-
(C) Ab+cd-*
(D) Ab+-cd*
Que-8
• Which of the following permutation can be obtained
in the output (in the same order) using a stack
assuming that the input is the sequence1, 2, 3, 4, 5 in
that order?

(A) 3, 4, 5, 1, 2
(B) 1, 5, 2, 3, 4
(C) 5, 4, 3, 1, 2
(D) 3, 4, 2, 5, 1
Que-8 Ans
• Which of the following permutation can be obtained
in the output (in the same order) using a stack
assuming that the input is the sequence1, 2, 3, 4, 5 in
that order?

(A) 3, 4, 5, 1, 2
(B) 1, 5, 2, 3, 4
(C) 5, 4, 3, 1, 2
(D) 3, 4, 2, 5, 1
Que-9
• The following sequence of operations is performed
on a stack : PUSH (1), PUSH (2), POP, PUSH (1), PUSH
(2), POP, POP, POP, PUSH (2), POP.
• The sequence of values popped out is:

(A) 2, 1, 2, 1, 2
(B) 2, 2, 1, 1, 2
(C) 1, 2,2,1,2
(D) 2, 2, 1, 2, 1
(E) None of the above
Que-9 Ans
• The following sequence of operations is performed
on a stack : PUSH (1), PUSH (2), POP, PUSH (1), PUSH
(2), POP, POP, POP, PUSH (2), POP.
• The sequence of values popped out is:

(A) 2, 1, 2, 1, 2
(B) 2, 2, 1, 1, 2
(C) 1, 2, 2, 1, 2
(D) 2, 2, 1, 2, 1
(E) None of the above
Que-10
• Suppose one character at a time comes as an input
from a string of letters. There is an option either to
(i) print the incoming letter or to
(ii) put the incoming letter on to a stack.
• Also a letter from top of the stack can be popped out
at any time and printed.
• The total number of total distinct words that can be
formed out of a string of three letters in this fashion,
is A B C.
(A) 3
(B) 4
(C) 5
(D) 6
Que-10 Ans
• Suppose one character at a time comes as an input
from a string of letters. There is an option either to
(i) print the incoming letter or to
(ii) put the incoming letter on to a stack.
• Also a letter from top of the stack can be popped out
at any time and printed.
• The total number of total distinct words that can be
formed out of a string of three letters in this fashion,
is A B C.
(A) 3
(B) 4
(C) 5 (ABC, ACB, BCA, BAC, CBA)
(D) 6
Que-11
The seven elements A, B, C, D, E, F and G are pushed
onto a stack in reverse order, i.e., starting from G.
The stack is popped five times and each element is
inserted into a queue.
Two elements are deleted from the queue and
pushed back onto the stack. Now, one element is
popped from the stack. The popped item is
________.

(A) F
(B) B
(C) C
(D) E
Que-11 Ans
The seven elements A, B, C, D, E, F and G are pushed
onto a stack in reverse order, i.e., starting from G.
The stack is popped five times and each element is
inserted into a queue.
Two elements are deleted from the queue and
pushed back onto the stack. Now, one element is
popped from the stack. The popped item is
________.

(A) F
(B) B
(C) C
(D) E
Que-12
• For Circular Queue of Length 4, front=1, rear=2 and
queue = _A_, _B_, ___, ____
Give front, rear and queue after the following operations.
Insert C, Delete, Insert D, Delete, Insert E, Insert F, Delete

(A) front = 1, rear = 3 and queue = _A_, _B_, __E_, _____


(B) front = 3, rear = 2 and queue = _E_, ___, _C_, __D_
(C) front =4 , rear = 2 and queue = _E_, _F_, ____, _D_
(D) front = 2, rear = 4 and queue = ____,_E_, _F_, _D__
Que-12 Ans
• For Circular Queue of Length 4, front=1, rear=2 and
queue = _A_, _B_, ___, ____
Give front, rear and queue after the following operations.
Insert C, Delete, Insert D, Delete, Insert E, Insert F, Delete

(A) front = 1, rear = 3 and queue = _A_, _B_, __E_, _____


(B) front = 3, rear = 2 and queue = _E_, ___, _C_, __D_
(C) front =4 , rear = 2 and queue = _E_, _F_, ____, _D_
(D) front = 2, rear = 4 and queue = ____,_E_, _F_, _D__
Que-13
• The following C function takes a singly-linked list of integers as
a parameter and rearranges the elements of the list. The
function is called with the list containing the integers
1,2,3,4,5,6,7 in the given order. What will be the contents of
the list after the function completes execution?
void rearrange (struct node *list) {
Struct node {
struct node *p, *q; int temp;
int value;
if (!list || !list -> next) return;
struct node *nexr;
p = list; q = list -> next;
}
while (q) {
temp = p -> value;
p -> value =q -> value;
q -> value = temp;
p = q->next; (A) 1,2,3,4,5,6,7
q = p ? -> next : 0; (B) 2,1,4,3,6,5,7
} (C) 1,3,2,5,4,7,6
(D) 2,3,4,5,6,7,1
Que-13 Ans
• The following C function takes a singly-linked list of integers as
a parameter and rearranges the elements of the list. The
function is called with the list containing the integers
1,2,3,4,5,6,7 in the given order. What will be the contents of
the list after the function completes execution?
void rearrange (struct node *list) {
Struct node {
struct node *p, *q;
int value;
int temp;`
struct node *nexr;
if (!list || !list -> next) return;
}
p = list; q = list -> next;
while (q) {
temp = p -> value; p -> value =q -> value;
q -> value = temp; p = q->next;
q = p ? -> next : 0; (A) 1,2,3,4,5,6,7
} (B) 2,1,4,3,6,5,7
} (C) 1,3,2,5,4,7,6
(D) 2,3,4,5,6,7,1
Que-14
• Circularly linked list is used to represent a Queue. A
single variable p is used to access the Queue. To which
node should p point such that both the operations
enQueue and deQueue can be performed in constant
time?

(A) Rear node


(B) Front node
(C) Not possible with a single pointer
(D) Node next to front
Que-14 Ans
• Circularly linked list is used to represent a Queue. A
single variable p is used to access the Queue. To which
node should p point such that both the operations
enQueue and deQueue can be performed in constant
time?

(A) Rear node


(B) Front node
(C) Not possible with a single pointer
(D) Node next to front
Que-15
• The maximum number of binary trees that can be
formed with three unlabeled nodes is:

(A) 1
(B) 3
(C) 4
(D) 5
Que-15 Ans
• The maximum number of binary trees that can be
formed with three unlabeled nodes is:

(A) 1
(B) 3
(C) 4
(D) 5
Que-16
• Consider a node X in a Binary Tree. Given that X has two
children, let Y be Inorder successor of X. Which of the
following is true about Y?

(A) Y has no right child


(B) Y has no left child
(C) Y has both children
(D) None of the above
Que-16 Ans
• Consider a node X in a Binary Tree. Given that X has two
children, let Y be Inorder successor of X. Which of the
following is true about Y?

(A) Y has no right child


(B) Y has no left child
(C) Y has both children
(D) None of the above
Que-17
• The height of a binary tree is the maximum number of
edges in any root to leaf path. The maximum number of
nodes in a binary tree of height h is:

(A) 2^h -1
(B) 2^h-1 -1
(C) 2^h+1 -1
(D) 2^h+1
Que-17 Ans
• The height of a binary tree is the maximum number of
edges in any root to leaf path. The maximum number of
nodes in a binary tree of height h is:

(A) 2^h -1
(B) 2^h-1 -1
(C) 2^h+1 -1
(D) 2^h+1
Que-18
• The height of a tree is the length of the longest root-to-
leaf path in it. The maximum and minimum number of
nodes in a binary tree of height 5 are

(A) 63 and 6, respectively


(B) 64 and 5,
(C) 32 and 6
(D) 31 and 5
Que-18 Ans
• The height of a tree is the length of the longest root-to-
leaf path in it. The maximum and minimum number of
nodes in a binary tree of height 5 are

(A) 63 and 6, respectively


(B) 64 and 5,
(C) 32 and 6
(D) 31 and 5
Que-19
• Postorder traversal of a given binary search tree, T
produces the following sequence of keys 10, 9, 23, 22,
27, 25, 15, 50, 95, 60, 40, 29 Which one of the following
sequences of keys can be the result of an in-order
traversal of the tree T? (GATE CS 2005)

(A) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95
(B) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
(C) 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95
(D) 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29
Que-19 Ans
• Postorder traversal of a given binary search tree, T
produces the following sequence of keys 10, 9, 23, 22,
27, 25, 15, 50, 95, 60, 40, 29 Which one of the following
sequences of keys can be the result of an in-order
traversal of the tree T?

(A) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95
(B) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
(C) 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95
(D) 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29
Que-20
• The following three are known to be the preorder, inorder
and postorder sequences of a binary tree. But it is not
known which is which.
MBCAFHPYK
KAMCBYPFH
MABCKYFPH
Pick the true statement from the following.

(A) I and II are preorder and inorder sequences, respectively


(B) I and III are preorder and postorder sequences,
respectively
(C) II is the inorder sequence, but nothing more can be said
about the other two sequences
(D) II and III are the preorder and inorder sequences,
respectively
Que-20 Ans
• The following three are known to be the preorder, inorder
and postorder sequences of a binary tree. But it is not
known which is which.
MBCAFHPYK
KAMCBYPFH
MABCKYFPH
Pick the true statement from the following.

(A) I and II are preorder and inorder sequences, respectively


(B) I and III are preorder and postorder sequences,
respectively
(C) II is the inorder sequence, but nothing more can be said
about the other two sequences
(D) II and III are the preorder and inorder sequences,
respectively
Que-21
• Draw a binary tree with node labels a, b, c, d, e,
f and g for which the inorder and postorder traversals
result in the following sequences:
• Inorder afbcdge
• Postorder a f c g e d b
Que-22
• A binary search tree contains the values 1, 2, 3, 4, 5, 6, 7,
8. The tree is traversed in pre-order and the values are
printed out. Which of the following sequences is a valid
output?

(A) 53124786
(B) 53126487
(C) 53241678
(D) 53124768
Que-22 Ans
• A binary search tree contains the values 1, 2, 3, 4, 5, 6, 7,
8. The tree is traversed in pre-order and the values are
printed out. Which of the following sequences is a valid
output?

(A) 53124786
(B) 53126487
(C) 53241678
(D) 53124768
Que-23
• The in-order and pre-order traversal of a binary tree are
d b e a f c g and a b d e c f g respectively. The post order
traversal of a binary tree is

(A) e d b g f c a
(B) e d b f g c a
(C) d e b f g c a
(D) d e f g b c a
Que-23 Ans
• The in-order and pre-order traversal of a binary tree are
d b e a f c g and a b d e c f g respectively. The post order
traversal of a binary tree is

(A) e d b g f c a
(B) e d b f g c a
(C) d e b f g c a
(D) d e f g b c a
Que-24
• Find the inorder and postorder of the binary tree with the given
preorder: 60, 40, 20, 10, 30, 33, 50, 44, 51, 90, 70, 65, 80, 110,
100, 95, 99, 120.

(A) In order: 110, 100, 99, 90, 80, 70, 65, 60, 51, 50, 44, 40, 33, 30,
20, 10. Postorder: 110, 120, 100, 95, 99, 70, 80, 65, 60, 40, 50,
51, 44, 20, 30, 33, 10
(B) Inorder: 10, 20, 30, 33, 40, 44, 50, 51, 60, 65, 70, 80, 90, 95, 99,
100, 110, 120 Postorder: 10, 33, 30, 20, 44, 51, 50, 40, 65, 80,
70, 99, 95, 100, 120, 110, 90, 60
(C) In order: 10, 33, 30, 20, 44, 51, 50, 40, 60, 65, 80, 70, 99, 95,
100, 120, 110, Postorder: 10, 20, 30, 33, 40, 44, 50, 51, 60, 65,
70, 80, 90, 95, 99, 100, 110
(D) In order: 10, 33, 30, 20, 44, 51, 60, 65, 80, 70, 99, 95, 100, 120,
110, Postorder: 110, 100, 99, 90, 80, 70, 65, 60, 51, 50, 44, 40,
33, 30, 20, 10
Que-24 Ans
• Find the inorder and postorder of the binary tree with the given
preorder: 60, 40, 20, 10, 30, 33, 50, 44, 51, 90, 70, 65, 80, 110,
100, 95, 99, 120.

(A) In order: 110, 100, 99, 90, 80, 70, 65, 60, 51, 50, 44, 40, 33, 30,
20, 10. Postorder: 110, 120, 100, 95, 99, 70, 80, 65, 60, 40, 50,
51, 44, 20, 30, 33, 10
(B) Inorder: 10, 20, 30, 33, 40, 44, 50, 51, 60, 65, 70, 80, 90, 95, 99,
100, 110, 120 Postorder: 10, 33, 30, 20, 44, 51, 50, 40, 65, 80,
70, 99, 95, 100, 120, 110, 90, 60
(C) In order: 10, 33, 30, 20, 44, 51, 50, 40, 60, 65, 80, 70, 99, 95,
100, 120, 110, Postorder: 10, 20, 30, 33, 40, 44, 50, 51, 60, 65,
70, 80, 90, 95, 99, 100, 110
(D) In order: 10, 33, 30, 20, 44, 51, 60, 65, 80, 70, 99, 95, 100, 120,
110, Postorder: 110, 100, 99, 90, 80, 70, 65, 60, 51, 50, 44, 40,
33, 30, 20, 10
Que-25
• A binary search tree is generated by inserting in order the
following integers:
50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24
The number of nodes in the left subtree and right subtree
of the root is respectively is

(A) (4, 7)
(B) (7, 4)
(C) (8, 3)
(D) (3, 8)
Que-25 Ans
• A binary search tree is generated by inserting in order the
following integers:
50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24
The number of nodes in the left subtree and right subtree
of the root is respectively is

(A) (4, 7)
(B) (7, 4)
(C) (8, 3)
(D) (3, 8)
Que-26
• How is an insertion of a node into an AVL tree carried
out?

(A) By treating an AVL tree as a binary search tree


(B) By updating the balance factors working upward from
insertion point to the root
(C) Both a and b
(D) None of the above
Que-26 Ans
• How is an insertion of a node into an AVL tree carried
out?

(A) By treating an AVL tree as a binary search tree


(B) By updating the balance factors working upward from
insertion point to the root
(C) Both a and b
(D) None of the above
Que-27
• Which of the following is TRUE?

(A) The cost of searching an AVL tree is θ(log n) but that of a


complete binary tree is θ(n log n)

(B) The cost of searching a binary search tree is O(log n ) but


that of an AVL tree is θ(n)

(C) The cost of searching an AVL tree is θ(n log n) but that of
a binary search tree is O(n)

(D) The cost of searching an AVL tree is θ(log n) but that of a


binary search tree is O(n)
Que-27 Ans
• Which of the following is TRUE?

(A) The cost of searching an AVL tree is θ(log n) but that of a


complete binary tree is θ(n log n)

(B) The cost of searching a binary search tree is O(log n ) but


that of an AVL tree is θ(n)

(C) The cost of searching an AVL tree is θ(n log n) but that of
a binary search tree is O(n)

(D) The cost of searching an AVL tree is θ(log n) but that of


a binary search tree is O(n)
Que-28
In the balanced binary tree in Fig. given below, how
many nodes will become unbalanced when a node is
inserted as a child of the node “g”?

(A) 1
(B) 3
(C) 7
(D) 8
Que-28 Ans
In the balanced binary tree in Fig. given below, how
many nodes will become unbalanced when a node is
inserted as a child of the node “g”?

(A) 1
(B) 3
(C) 7
(D) 8
Que-29
• The following insertions are made to an initially empty B-
tree of order 5.
1,12 ,8, 2, 25, 5, 14, 28, 17
now the root node contains the element/elements

(A) 8
(B) 1
(C) 8, 17
(D) 12
Que-29 Ans
• The following insertions are made to an initially empty B-
tree of order 5.
1,12 ,8, 2, 25, 5, 14, 28, 17
now the root node contains the element/elements

(A) 8
(B) 1
(C) 8, 17
(D) 12
Que-30
• The number of interchanges required to sort 5,1,6,2,4 in
ascending order using Bubble Sort is

(A) 5
(B) 6
(C) 7
(D) 8
Que-30 Ans
• The number of interchanges required to sort 5,1,6,2,4 in
ascending order using Bubble Sort is

(A) 5
(B) 6
(C) 7
(D) 8
Que-31
• The minimum number of interchanges needed to convert
the array
89, 19, 40, 17, 12, 10, 2, 5, 7, 11, 6, 9, 70 into a heap with
the maximum element at the root node is

(A) 0
(B) 1
(C) 2
(D) 3
Que-31 Ans
• The minimum number of interchanges needed to convert
the array
89, 19, 40, 17, 12, 10, 2, 5, 7, 11, 6, 9, 70 into a heap with
the maximum element at the root node is

(A) 0
(B) 1
(C) 2
(D) 3
Que-32
• Consider a binary max-heap implemented using an array.
Which one of the following array represents a binary max-
heap?

(A) { 25, 12, 16, 13, 10, 8, 14 }


(B) { 25, 14, 13, 16, 10, 8, 12 }
(C) { 25, 14, 16, 13, 10, 8, 12 }
(D) { 25, 14, 12, 13, 10, 8, 16 }
Que-32 Ans
• Consider a binary max-heap implemented using an array.
Which one of the following array represents a binary max-
heap?

(A) { 25, 12, 16, 13, 10, 8, 14 }


(B) { 25, 14, 13, 16, 10, 8, 12 }
(C) { 25, 14, 16, 13, 10, 8, 12 }
(D) { 25, 14, 12, 13, 10, 8, 16 }
Que-33
• Suppose that we have numbers between 1 and 100 in a
binary search tree and want to search for the number 55.
Which of the following sequences CANNOT be the
sequence of nodes examined?

(A) {10, 75, 64, 43, 60, 57, 55}


(B) {90, 12, 68, 34, 62, 45, 55}
(C) {79, 14, 72, 56, 16, 53, 55}
(D) {9, 85, 47, 68, 43, 57, 55}
Que-33 Ans
• Suppose that we have numbers between 1 and 100 in a
binary search tree and want to search for the number 55.
Which of the following sequences CANNOT be the
sequence of nodes examined?

(A) {10, 75, 64, 43, 60, 57, 55}


(B) {90, 12, 68, 34, 62, 45, 55}
(C) {79, 14, 72, 56, 16, 53, 55}
(D) {9, 85, 47, 68, 43, 57, 55}
Que-34
• The Breadth First Search algorithm has been
implemented using the queue data structure. One
possible order of visiting the nodes of the following graph
is

(A) MNOPQR
(B) NQMPOR
(C) QMNPRO
(D) QMNPOR
Que-34 Ans
• The Breadth First Search algorithm has been
implemented using the queue data structure. One
possible order of visiting the nodes of the following graph
is

(A) MNOPQR
(B) NQMPOR
(C) QMNPRO
(D) QMNPOR
Que-35
Consider following graph

• Among the
following sequences:
(i) a b e g h f
(ii) a b f e h g
(iii) a b f h g e
(iv) a f g h b e
• Which are depth first traversals of the above graph?
(A) I, II and IV only (B) I and IV only
(C) II, III and IV only (D) I, III and IV only
Que-36
• Suppose we are sorting an array of eight integers using
quicksort, and we have just finished the first partitioning
with the array looking like this:
2 5 1 7 9 12 11 10
Which statement is correct?

(A) The pivot could be either the 7 or the 9


(B) The pivot could be the 7, but it is not the 9
(C) The pivot is not the 7, but it could be the 9
(D) Neither the 7 nor the 9 is the pivot
Que-37
• What is the best time complexity of bubble sort?

(A) N^2
(B) N log N
(C) N
(D) N (log N)^2
Que-38
• Let P be a QuickSort Program to sort numbers in
ascending order using the first element as pivot. Let t1
and t2 be the number of comparisons made by P for the
inputs {1, 2, 3, 4, 5} and {4, 1, 5, 3, 2} respectively. Which
one of the following holds?

(A) T1 = 5
(B) T1 < T2
(C) T1 > T2
(D) T1 = T2
Que-39
• The worst case running times of Insertion sort, Merge sort
and Quick sort, respectively, are:

(A) Θ(n log n), Θ(n log n) and Θ(n2)


(B) Θ(n2), Θ(n2) and Θ(n Log n)
(C) Θ(n2), Θ(n log n) and Θ(n log n)
(D) Θ(n2), Θ(n log n) and Θ(n2)
Que-40
• Consider an array of elements arr[5]= {5,4,3,2,1} , what
are the steps of insertions done while doing insertion sort
in the array.

(A) 4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5
(B) 5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5
(C) 4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2
(D) 4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy