Data Structures MCQ's Questions Set 2
Q.1. With what data structure can a priority queue be implemented?
- Array
- List
- Heap
- Tree
Answer:- (4)
Q.2. 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:- (3)
Q.3. 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:- (1)
Q.4. What is the functionality of the following piece of code?
public void function(Object item)
{
Node temp=new Node(item,trail);
if(isEmpty())
{
head.setNext(temp);
temp.setNext(trail);
}
else
{
Node cur=head.getNext();
while(cur.getNext()!=trail)
{
cur=cur.getNext();
}
cur.setNext(temp);
}
size++;
} |
- 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:- (2)
Q.5. What is the functionality of the following piece of code?
public void fun(int x)
{
q1.offer(x);
} |
- Perform push() with push as the costlier operation
- Perform push() with pop as the costlier operation
- Perform pop() with push as the costlier operation
- Perform pop() with pop as the costlier operation
Answer:- (2)
Q.6. How many stacks are required for evaluation of prefix expression?
- one
- two
- three
- four
Answer:- (2)
Q.7. In the given C snippet, find the statement number that has error.
//C code to push an element into a stack
1.void push( struct stack *s, int x)
2. {
3. if(s->top==MAX-1)
4. {
5. printf(“stack overflow”);
6. }
7. else
8. {
9. s->items[++s->top]=x;
10. s++;
11. }
12.}
|
- 1
- 9
- 10
- 11
Answer:- (3)
Q.8. What is the other name for a postfix expression?
- Normal polish Notation
- Reverse polish Notation
- Warsaw notation
- Infix notation
Answer:- (2)
Q.9. While evaluating a postfix expression, when an operator is encountered, what is the correct operation to be performed?
- push it directly on to the stack
- pop 2 operands, evaluate them and push the result on to the stack
- pop the entire stack
- ignore the operator
Answer:- (2)
Q.10. In infix to postfix conversion algorithm, the operators are associated from?
- right to left
- left to right
- centre to left
- centre to right
Answer:- (2)
Q.11. The time complexity of converting a prefix notation to infix notation is _________
- O(n) where n is the length of the equation
- O(n) where n is number of operands
- O(1)
- O(logn) where n is length of the equation
Answer:- (1)
Q.12. The result of the postfix expression 5 3 * 9 + 6 / 8 4 / + is _____________
- 8
- 6
- 10
- 9
Answer:- (2)
Q.13. What is the time complexity of reversing a word using stack algorithm?
- O (N log N)
- O (N2)
- O (N)
- O (M log N)
Answer:- (3)
Q.14. Find the error (if any) in the following code snippet for pop operation.
void pop() //removing an element from a stack
{
printf(“%s”, stack[top++]);
} |
- run time error
- compile time error
- pop operation is performed, but top moved in wrong direction
- pop operation is performed properly
Answer:- (3)
Q.15. How will you implement dynamic arrays in Java?
- Set
- Map
- HashMap
- List
Answer:- (4)
Q.16. Which of the following is a disadvantage of dynamic arrays?
- Locality of reference
- Data cache utilization
- Random access
- Memory leak
Answer:- (4)
Q.17. In a complete k-ary tree, every internal node has exactly k children or no child. The number of leaves in such a tree with n internal nodes is:
- nk
- (n-1)k + 1
- n(k-1) + 1
- n(k-1)
Answer:- (3)
Q.18. Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?
- Insertion Sort
- Quick Sort
- Heap Sort
- Merge Sort
Answer:- (4)
Q.19. 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:
- 2h - 1
- 2h-1 - 1
- 2h+1 - 1
- 2*(h+1)
Answer:- (3)
Q.20. The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is:
- n/2
- (n-1)/3
- (n-1)/2
- (2n+1)/3
Answer:- (4)
Data Structures Interview Questions Set 1 Click here
For more Technical MCQ's and Interview Questions Click here