Ds
Ds
{ Explanation
B - 1 → B, 2 → C, 3 → A
Answer: Option A
Both selection sort and insertion sort
maintains two sublists and then checks 15. The smallest element of an array's index is
unsorted list for next sorted element. called
A. Lower bound
Q 10 - Project scheduling is an example of
B. Upper bound
A - greedy programming C. Range
} Answer: d
}
10. What are the disadvantages of arrays?
a) 3 and 5 a) We must know before hand how many
b) 5 and 3 elements will be there in the array
c) 2 and 4 b) There are chances of wastage of memory
d) 4 and 2 space if elements inserted in an array are lesser
View Answer than than the allocated size
c) Insertion and deletion becomes tedious
Answer: a
d) All of the mentioned
6. What is the output of the following piece of
View Answer
code?
Answer: d
public class array
11. Assuming int is of 4bytes, what is the size
{ of int arr[15];?
a) 15
public static void main(String args[])
b) 19
{ c) 11
d) 60
int []arr = {1,2,3,4,5}; View Answer
System.out.println(arr[5]); Answer: d
} 1. Process of inserting an element in stack is called
____________
} a) Create
b) Push
a) 4
c) Evaluation
b) 5
d) Pop
c) ArrayIndexOutOfBoundsException
View Answer
d) InavlidInputException
View Answer Answer: b
Answer: c
ArrayIndexOutOfBoundsException. 2. Process of removing an element from stack
7. When does the is called __________
ArrayIndexOutOfBoundsException occur? a) Create
a) Compile-time b) Push
c) Evaluation
d) Pod during the computation?
View Answer a) 1
b) 2
Answer: d
c) 3
3. In a stack, if a user tries to remove an
d) 4 or more
element from empty stack it is called
View Answer
_________
a) Underflow Answer: b
b) Empty collection 9. What is the value of the postfix expression 6
c) Overflow 3 2 4 + – *:
d) Garbage Collection a) Something between -5 and -15
View Answer b) Something between 5 and -5
c) Something between 5 and 15
Answer: a
d) Something between 15 and 100
4. Pushing an element into stack already having
View Answer
five elements and stack size of 5 , then stack
becomes Answer: d
a) Overflow 10. Here is an infix expression: 4 + 3*(6*3-12).
b) Crash Suppose that we are using the usual stack
c) Underflow algorithm to convert the expression from infix
d) User flow to postfix notation.
View Answer The maximum number of symbols that will
appear on the stack AT ONE TIME during the
Answer: a
conversion of this expression?
5. Entries in a stack are “ordered”. What is the
a) 1
meaning of this statement?
b) 2
a) A collection of stacks is sortable
c) 3
b) Stack entries may be compared with the ‘<‘
d) 4
operation
View Answer
c) The entries are stored in a linked list
d) There is a Sequential entry that is one by one Answer: d
View Answer 1. The postfix form of the expression (A+ B)*(C*D-
E)*F / G is?
Answer : d a) AB+ CD*E – FG /**
6. Which of the following applications may use b) AB + CD* E – F **G /
a stack? c) AB + CD* E – *F *G /
a) A parentheses balancing program d) AB + CDE * – * F *G /
b) Tracking of local variables at run time View Answer
c) Compiler Syntax Analyzer
d) All of the mentioned Answer: a.
View Answer
2. The data structure required to check whether
Answer: d an expression contains balanced parenthesis is?
7. Consider the usual algorithm for determining a) Stack
whether a sequence of parentheses is balanced. b) Queue
The maximum number of parentheses that c) Array
appear on the stack AT ANY ONE TIME when d) Tree
the algorithm analyzes: (()(())(())) are: View Answer
a) 1
Answer: a
b) 2
3. What data structure would you mostly likely
c) 3
see in a non recursive implementation of a
d) 4 or more
recursive algorithm?
View Answer
a) Linked List
Answer: c b) Stack
8. Consider the usual algorithm for determining c) Queue
whether a sequence of parentheses is balanced. d) Tree
Suppose that you run the algorithm on a View Answer
sequence that contains 2 left parentheses and 3
Answer: b
right parentheses (in some order).
The maximum number of parentheses that
appear on the stack AT ANY ONE TIME
4. The process of accessing data stored in a Answer: b
serial access memory is similar to manipulating
1. The result of evaluating the postfix
data on a ________
expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is?
a) Heap
a) 600
b) Binary Tree
b) 350
c) Array
c) 650
d) Stack
d) 588
View Answer
View Answer
Answer: d
Answer: b
Explanation: None.
2. Convert the following infix expressions into
5. The postfix form of A*B+C/D is? its equivalent postfix expressions
a) *AB/CD+ (A + B ⋀D)/(E – F)+G
b) AB*CD/+ a) (A B D ⋀ + E F – / G +)
c) A*BC+/D b) (A B D +⋀ E F – / G +)
d) ABCD+/* c) (A B D ⋀ + E F/- G +)
View Answer d) None of the mentioned
View Answer
Answer: b
Answer: a
6. Which data structure is needed to convert
3. Convert the following Infix expression to
infix notation to postfix notation?
Postfix form using a stack
a) Branch
x + y * z + (p * q + r) * s, Follow usual
b) Tree
precedence rule and assume that the expression
c) Queue
is legal.
d) Stack
a) xyz*+pq*r+s*+
View Answer
b) xyz*+pq*r+s+*
Answer: d c) xyz+*pq*r+s*+
7. The prefix form of A-B/ (C * D ^ E) is? d) None of the mentioned
a) -/*^ACBDE View Answer
b) -ABCD*^DE
Answer: a
c) -A/B*C^DE
d) -A/BC*^DE
View Answer 4. Which of the following statement(s) about
stack data structure is/are NOT correct?
Answer: c
a) Linked List are used for implementing
8. What is the result of the following operation
Stacks
Top (Push (S, X))
b) Top of the Stack always contain the new
a) X
node
b) Null
c) Stack is the FIFO data structure
c) S
d) Null link is present in the last node at the
d) None of the mentioned
bottom of the stack
View Answer
View Answer
Answer: a
Answer: c
9. The prefix form of an infix expression p + q
– r * t is?
a) + pq – *rt 5. Consider the following operation performed
b) – +pqr * t on a stack of size 5.
c) – +pq * rt Push(1);
d) – + * pqrt Pop();
View Answer Push(2);
Push(3);
Answer: c
Pop();
10. Which data structure is used for
Push(4);
implementing recursion?
Pop();
a) Queue
Pop();
b) Stack
Push(5);
c) Array
After the completion of all operation, the
d) List
number of elements present in stack are
View Answer
a) 1 parenthesis is?
b) 2
c) 3 a) Stack
d) 4 b) Queue
View Answer c) Array
d) Tree
Answer: a
ANSWER: a) Stack
6. Which of the following is not an inherent
application of stack? 3. What data structure would you mostly
a) Reversing a string likely see in a non recursive implementation
b) Evaluation of postfix expression of a recursive algorithm?
c) Implementation of recursion
d) Job scheduling a) LinkList
View Answer b) Stack
c) Queue
Answer: d
d) Tree
7. The type of expression in which operator
ANSWER: b) Stack
succeeds its operands is?
a) Infix Expression 4. The process of accessing data stored in a
b) Prefix Expression serial access memory is similar to
c) Postfix Expression manipulating data on a ------?
d) None of the mentioned
View Answer a) Heap
b) Binary Tree
Answer: c
c) Array
Explanation: None.
d) Stack
8. Assume that the operators +,-, X are left ANSWER: d) Stack
associative and ^ is right associative. 5. The postfix form of A*B+C/D is?
The order of precedence (from highest to
lowest) is ^, X, +, -. The postfix expression for a) *AB/CD+
the infix expression a + b X c – d ^ e ^ f is b) AB*CD/+
a) abc X+ def ^^ – c) A*BC+/D
b) abc X+ de^f^ – d) ABCD+/*
c) ab+c Xd – e ^f^ ANSWER: b) AB*CD/+
d) -+aXbc^ ^def
6. Which data structure is needed to convert
View Answer
infix notation to postfix notation?
Answer: a
9. If the elements “A”, “B”, “C” and “D” are a) Branch
placed in a stack and are deleted one at a time, b) Tree
what is the order of removal? c) Queue
a) ABCD d) Stack
b) DCBA ANSWER: d) Stack
c) DCAB
7. The prefix form of A-B/ (C * D ⋀ E) is?
d) ABDC
View Answer
a) -/*⋀ACBDE
Answer: b b) -ABCD*⋀DE
c) -A/B*C⋀DE
1. The postfix form of the expression (A+ d) -A/BC*⋀DE
B)*(C*D- E)*F / G is?
ANSWER: c) -A/B*C⋀DE
a) AB+ CD*E - FG /** 8. What is the result of the following
b) AB + CD* E - F **G / operation
c) AB + CD* E - *F *G / Top (Push (S, X))
d) AB + CDE * - * F *G /
a) X
b) Null
ANSWER: a) AB+ CD*E - FG /** c) S
2. The data structure required to check d) None
whether an expression contains balanced ANSWER: a) X
9. The prefix form of an infix expression p + ANSWER: c) Stack is the FIFO data
q - r * t is? structure
15. Consider the linked list implementation
a) + pq - *rt of a stack. Which of the following node is
b) - +pqr * t considered as Top of the stack?
c) - +pq * rt
d) - + * pqrt a) First node
ANSWER: c) - +pq * rt b) Last node
c) Any node
10. Which data structure is used for d) Middle node
implementing recursion?
ANSWER: a) First node
16. Consider the following operation
a) Queue
performed on a stack of size 5.
b) Stack
Push(1);
c) Array
Pop();
d) List
Push(2);
ANSWER: b) Stack Push(3);
11. The result of evaluating the postfix Pop();
expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is? Push(4);
Pop();
a) 600 Pop();
b) 350 Push(5);
c) 650
d) 588 After the completion of all operation, the no of
ANSWER: b) 350 element present on stack are
12. Convert the following infix expressions a) 1
into its equivalent postfix expressions b) 2
(A + B ⋀D)/(E - F)+G c) 3
d) 4
a) (A B D ⋀ + E F - / G +) ANSWER: a) 1
b) (A B D +⋀ E F - / G +)
c) (A B D ⋀ + E F/- G +) 17. Which of the following is not an inherent
d) None application of stack?
ANSWER: a) (A B D ⋀ + E F - / G +)
a) Reversing a string
13. Convert the following Infix expression to b) Evaluation of postfix expression
Postfix form using a stack c) Implementation of recursion
d) Job scheduling
x + y * z + (p * q + r) * s, Follow usual ANSWER: d) Job scheduling
precedence rule and assume that the expression
is legal. 18. Which of the following operation take
worst case linear time in the array
a) xyz*+pq*r+s*+ implementation of stack?
b) xyz*+pq*r+s+*
c) xyz+*pq*r+s*+ a) Push
d) none b) Pop
ANSWER: a) xyz*+pq*r+s*+ c) IsEmpty
d) None
14. Which of the following statement(s) ANSWER: d) None
about stack data structure is/are NOT
correct? 19. The type of expression in which operator
succeeds its operands is?
a) Stack data structure can be implemented
using linked list a) Infix Expression
b) New node can only be added at the top of b) pre fix Expression
the stack c) postfix Expression
c) Stack is the FIFO data structure d) None
d) The last node at the bottom of the stack has a ANSWER: c) postfix Expression
NULL link
20. Which of the following application 25. Consider the usual implementation of
generally use a stack? parentheses balancing program using stack.
What is the maximum number of
a) Parenthesis balancing program parentheses that will appear on stack at any
b) Syntax analyzer in compiler instance of time during the analysis of ( ( ) ( (
c) Keeping track of local variables at run time ) ) ( ( ) ) )?
d) All of the above
ANSWER: d) All of the above a) 1
b) 2
21. Consider the following array c) 3
implementation of stack: d) 4
ANSWER: c) 3
#define MAX 10
Struct STACK
{
Int arr [MAX]; 1. A linear list of elements in which
Int top = -1; deletion can be done from one end
} (front) and insertion can take place
only at the other end (rear) is known
If the array index starts with 0, the maximum as a ?
value of top which does not cause stack
overflow is? a) Queue
b) Stack
a) 8 c) Tree
b) 9 d) Linked list
c) 10
d) 11
ANSWER: a) 8
ANSWER: a) Queue
22. What is the minimum number of stacks
of size n required to implement a queue of
size n?
2. The data structure required for
a) One Breadth First Traversal on a graph is?
b) Two
c) Three a) Stack
d) Four b) Array
ANSWER: b) Two c) Queue
23. Assume that the operators +,-, X are left d) Tree
associative and ⋀ is right associative. The
order of precedence (from highest to lowest)
is ⋀, X, +, -. The postfix expression ANSWER: c) Queue
corresponding to the infix expression a + b X
c – d ⋀ e ⋀ f is
ANSWER: d) None
a) At the head of link list 11. If the MAX_SIZE is the size of the
array used in the implementation of is?
circular queue, array index start with
0, front point to the first element in the a) Queue
queue, and rear point to the last b) Circular queue
element in the queue. Which of the c) Dequeue
following condition specify that d) Priority queue
circular queue is FULL?
a) Rear=MAX_SIZE-1
b) Front=(rear+1)mod MAX_SIZE
13. If the MAX_SIZE is the size of the c) Front=rear+1
array used in the implementation of d) Rear=front
circular queue, array index start with
0, front point to the first element in the
queue, and rear point to the last ANSWER: a) Rear=MAX_SIZE-1
element in the queue. Which of the
following condition specify that
circular queue is EMPTY?
17. In linked list implementation of a
a) Front=rear=0 queue, front and rear pointers are
b) Front= rear=-1 tracked. Which of these pointers will
c) Front=rear+1 change during an insertion into
d) Front=(rear+1)%MAX_SIZE EMPTY queue?
Answer: b main()
{
8. What will be output if the following char str[]="san foundry";
sequence of operations are executed?
Push(a,s); int len = strlen(str);
Push(b,s); int i;
Pop(b);
Push(c,s);
a) abc for(i=0;i<len;i++)
b) b
c) ac push(str[i]); // pushes an element into
d) acb stack
View Answer
Answer: b
for(i=0;i<len;i++)
9. What are the set of functions that are to be
executed to get the following output? pop(); //pops an element from the stack
cat
a) push(c, s); push(a, s); push(t, s); }
pop(s); pop(s); pop(s); a) sanfoundry
b) push(c,s); pop(s); push(a,s); b) san foundry
pop(s);push(t,s);pop(s); c) yrdnuof nas
c) pop(c ); pop(a); pop(t); d) foundry nas
d) push(c,s); push(a,s); pop(t); View Answer
View Answer
Answer: c
Answer: b
1. What data structure is used when converting
an infix notation to prefix notation?
10. How will your stack look like if the word a) Stack
‘java’ is pushed? b) Queue
c) B-Trees
d) Linked-list
View Answer
Answer: a
2. What would be the Prefix notation for the
a) b) c) d) given equation?
View Answer
A+(B*C)
Answer: a
11. Find the error (if any) in the following code a) +A*CB
snippet for pop operation. b) *B+AC
c) +A*BC
void pop() //removing an element from a stack
d) *A+CB a) |&-+ab/cdef
View Answer b) &|-+ab/cdef
c) |&-ab+/cdef
Answer: c
d) |&-+/abcdef
3. What would be the Prefix notation for the
View Answer
given equation?
Answer: a
(A*B)+(C*D)
advertisement
a) +*AB*CD
9. What would be the Prefix notation for the
b) *+AB*CD
given equation?
c) **AB+CD
d) +*BA*CD (a+(b/c)*(d^e)-f)
View Answer
a) -+a*/^bcdef
Answer: a b) -+a*/bc^def
4. What would be the Prefix notation for the c) -+a*b/c^def
given equation? d) -a+*/bc^def
View Answer
A+B*C^D
Answer: b
a) +A*B^CD
10. What would be the Prefix notation for the
b) +A^B*CD
given equation?
c) *A+B^CD
d) ^A*B+CD A+B+C
View Answer
a) ++ABC and AB+C+
Answer: a b) AB+C+ and ++ABC
5. Out of the following operators (^, *, +, &, $), c) ABC++ and AB+C+
the one having highest priority is _________ d) ABC+ and ABC+
a) + View Answer
b) $
Answer: a
c) ^
11. What would be the Prefix notation for the
d) &
given equation?
View Answer
a|b&c
Answer: c
a) a|&bc
b) |ab&c
6. Out of the following operators (|, *, +, &, $),
c) |abc&
the one having lowest priority is ________
d) ab&|c
a) +
View Answer
b) $
c) | Answer: b
d) &
View Answer 1. When an operand is read, which of the
following is done?
Answer: b a) It is placed on to the output
7. What would be the Prefix notation for the b) It is placed in operator stack
given equation? c) It is ignored
d) Operator stack is emptied
A^B^C^D
View Answer
a) ^^^ABCD
Answer: a
b) ^A^B^CD
Explanation: While converting an infix
c) ABCD^^^
expression to a postfix expression, when an
d) AB^C^D
operand is read, it is placed on to the output.
View Answer
When an operator is read, it is placed in the
Answer: a operator stack.
8. What would be the Prefix notation for the
2. What should be done when a left parenthesis
given equation?
‘(‘ is encountered?
a+b-c/d&e|f a) It is ignored
b) It is placed in the output
c) It is placed in the operator stack Answer: a
d) The contents of the operator stack is emptied 8. What is the postfix expression for the infix
View Answer expression?
Answer: c a-b-c
Explanation: When a left parenthesis is
a) -ab-c
encountered, it is placed on to the operator
b) abc–
stack. When the corresponding right
c) –abc
parenthesis is encountered, the stack is popped
d) -ab-c
until the left parenthesis and remove both the
View Answer
parenthesis.
Answer: d
3. Which of the following is an infix
9. What is the postfix expression for the
expression?
following infix expression?
a) (a+b)*(c+d)
b) ab+c* a/b^c-d
c) +ab
d) abc+* a) abc^/d-
View Answer b) ab/cd^-
c) ab/^cd-
Answer: a d) abcd^/-
Explanation: (a+b)*(c+d) is an infix View Answer
expression. +ab is a prefix expression and
ab+c* is a postfix expression. Answer: a
10. Which of the following statement is
4. What is the time complexity of an infix to incorrect with respect to infix to postfix
postfix conversion algorithm? conversion algorithm?
a) O(N log N) a) operand is always placed in the output
b) O(N) b) operator is placed in the stack when the
c) O(N2) stack operator has lower precedence
d) O(M log N) c) parenthesis are included in the output
View Answer d) higher and equal priority operators follow
the same condition
Answer: b
View Answer
Explanation: The time complexity of an infix to
postfix expression conversion algorithm is Answer: c
mathematically found to be O(N). 11. In infix to postfix conversion algorithm, the
operators are associated from?
5.What is the postfix expression for the
a) right to left
corresponding infix expression?
b) left to right
a+b*c+(d*e) c) centre to left
d) centre to right
a) abc*+de*
Answer: b
b) abc+*de*
12. What is the corresponding postfix
c) a+bc*de+*
expression for the given infix expression?
d) abc*+(de)*
View Answer a*(b+c)/d
Answer: a a) ab*+cd/
6. Parentheses are simply ignored in the b) ab+*cd/
conversion of infix to postfix expression. c) abc*+/d
a) True d) abc+*d/
b) False View Answer
View Answer
Answer: d
Answer: b 13. What is the corresponding postfix
7. It is easier for a computer to process a expression for the given infix expression?
postfix expression than an infix expression.
a+(b*c(d/e^f)*g)*h)
a) True
b) False a) ab*cdef/^*g-h+
View Answer b) abc*def^/g*-h*+
c) abcd*^ed/g*-h*+
d) abc*de^fg/*-*h+
View Answer a) Deleting a node whose location in given
b) Searching of an unsorted list for a given item
Answer: b
c) Inverting a node after the node with given
14. What is the correct postfix expression for
location
the following expression?
d) Traversing a list to process each node
a+b*(c^d-e)^(f+g*h)-i ANSWER: A
a) abc^de-fg+*^*+i- 4. Consider an implementation of unsorted
b) abcde^-fg*+*^h*+i- singly linked list. Suppose it has its
c) abcd^e-fgh*+^*+i- representation with a head and tail pointer.
d) ab^-dc*+ef^gh*+i- Given the representation, which of the
View Answer following operation can be implemented in
O(1) time?
Answer: c
15. From the given Expression tree, identify the i) Insertion at the front of the linked list
correct postfix expression from the list of ii) Insertion at the end of the linked list
options. iii) Deletion of the front node of the linked list
iv) Deletion of the last node of the linked list
a) I and II
b) I and III
c) I,II and III
d) I,II and IV
ANSWER: C
5. Consider an implementation of unsorted
a) ab*cd*+ singly linked list. Suppose it has its
b) ab*cd-+ representation with a head pointer only.
c) abcd-*+ Given the representation, which of the
d) ab*+cd- following operation can be implemented in
View Answer O(1) time?
a) 25 a) 3
b) 49 b) 6
c) 99 c) 8
d) 101 d) 11
ANSWER: C ANSWER: D
8. Which type of traversal of binary 13. In a full binary tree, every internal
search tree outputs the value in node has exactly two children. A full
sorted order? binary tree with 2n+1 nodes contains
a) 2h+1 a) (4, 7)
b) 2h b) (7, 4)
c) 2h -1 c) (8, 3)
d) 2h-1 d) (3, 8)
ANSWER: B ANSWER: B
1. Which of the following is not a d) O(n2)
stable sorting algorithm? ANSWER: C
a) O(n2) a) θ (n)
b) O(nlogn) b) θ (nlogn)
c) O(nloglogn) c) θ (n2)
d) O(n) d) θ (n(logn) 2)
ANSWER: B ANSWER: A
6. Which of the following is not a 12. Given a number of elements in the
noncomparison sort? range [0….n3]. which of the following
sorting algorithms can sort them in
a) Counting sort O(n) time?
b) Bucket sort
c) Radix sort a) Counting sort
d) Shell sort b) Bucket sort
ANSWER: D c) Radix sort
7. The time complexity of heap sort in d) Quick sort
worst case is ANSWER: C
a) O(logn)
b) O(n)
c) O(nlogn)
13. Which of the following algorithms
has lowest worst case time
complexity? 19. The radix sort does not work
correctly if each individual digit is
a) Insertion sort sorted using
b) Selection sort
c) Quick sort a) Insertion sort
d) Heap sort b) Counting sort
ANSWER: D c) Selection sort
14. Which of the following sorting d) Bubble sort
algorithms is/are stable ANSWER: C
Answer: d preorder(root.right);
Explanation: The three orders of traversal that }
can be applied to a binary tree are in-order, pre-
order and post order traversal. b)
12. If binary trees are represented in arrays, public void preorder(Tree root)
what formula can be used to locate a left child, {
if the node has an index i?
a) 2i+1 preorder(root.left);
b) 2i+2 System.out.println(root.data);
c) 2i
d) 4i preorder(root.right);
View Answer
}
Answer: a
c)
Explanation: If binary trees are represented in
arrays, left children are located at indices 2i+1 public void preorder(Tree root)
and right children at 2i+2.
{
13. Using what formula can a parent node be
located in an array? System.out.println(root.data);
a) (i+1)/2 preorder(root.right);
b) (i-1)/2
c) i/2 preorder(root.left);
d) 2i/2 }
View Answer
d) None of the mentioned
Answer: b View Answer
1. For the tree below, write the pre-order Answer: a
traversal. Explanation: Pre-order traversal follows
a) 2, 7, 2, 6, 5, 11, 5, 9, 4 NLR(Node-Left-Right).
b) 2, 7, 5, 2, 6, 9, 5, 11, 4
c) 2, 5, 11, 6, 7, 4, 9, 5, 2 4. Select the code snippet which performs post-
d) 2, 7, 5, 6, 11, 2, 5, 4, 9 order traversal.
View Answer a)
Answer: a public void postorder(Tree root)
Explanation: Pre order traversal follows {
NLR(Node-Left-Right).
System.out.println(root.data); 9. To obtain a prefix expression, which of the
tree traversals is used?
postorder(root.left);
a) Level-order traversal
postorder(root.right); b) Pre-order traversal
c) Post-order traversal
} d) In-order traversal
b) View Answer