250+ TOP MCQs on Singly Linked List and Answers

Data Structure Multiple Choice Questions on “Singly Linked List”.

1. Which of the following is not a disadvantage to the usage of array?
a) Fixed size
b) There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size
c) Insertion based on position
d) Accessing elements at specified positions
Answer: d
Clarification: Array elements can be accessed in two steps. First, multiply the size of the data type with the specified position, second, add this value to the base address. Both of these operations can be done in constant time, hence accessing elements at a given index/position is faster.

2. What is the time complexity of inserting at the end in dynamic arrays?
a) O(1)
b) O(n)
c) O(logn)
d) Either O(1) or O(n)
Answer: d
Clarification: Depending on whether the array is full or not, the complexity in dynamic array varies. If you try to insert into an array that is not full, then the element is simply stored at the end, this takes O(1) time. If you try to insert into an array which is full, first you will have to allocate an array with double the size of the current array and then copy all the elements into it and finally insert the new element, this takes O(n) time.

3. What is the time complexity to count the number of elements in the linked list?
a) O(1)
b) O(n)
c) O(logn)
d) O(n2)
Answer: b
Clarification: To count the number of elements, you have to traverse through the entire list, hence complexity is O(n).

4. Which of the following performs deletion of the last element in the list? Given below is the Node class.

class Node
{
	protected Node next;
	protected Object ele;
	Node(Object e,Node n)
	{
		ele = e;
		next = n;
	}
	public void setNext(Node n)
	{
		next = n;
	}
	public void setEle(Object e)
	{
		ele = e;
	}
	public Node getNext()
	{
		return next;
	}
	public Object getEle()
	{
		return ele;
	}
}
class SLL 
{
	Node head;
	int size;
	SLL()
	{
		size = 0;
	}
}

a)

public Node removeLast()
{
	if(size == 0)
	return null;
	Node cur;
	Node temp;
	cur = head;
	while(cur.getNext() != null)
	{
		 temp = cur;
		 cur = cur.getNext();
        }
	temp.setNext(null);
	size--;
	return cur;
}

b)

public void removeLast()
{
	if(size == 0)
	return null;
	Node cur;
	Node temp;
	cur = head;
	while(cur != null)
	{
		temp = cur;
		cur = cur.getNext();
        }
	temp.setNext(null);
	return cur;
}

c)

public void removeLast()
{
	if(size == 0)
	    return null;
	Node cur;
	Node temp;
	cur = head;
	while(cur != null)
	{
		cur = cur.getNext();
		temp = cur;
	 }
	temp.setNext(null);
	return cur;
}

d)

public void removeLast()
{
	if(size == 0)
		return null;
	Node cur;
	Node temp;
	cur = head;
	while(cur.getNext() != null)
	{
		cur = cur.getNext();
		temp = cur;
	}
	temp.setNext(null);
	return cur;
}

View Answer

Answer: a
Clarification: Since you have to traverse to the end of the list and delete the last node, you need two reference pointers. ‘cur’ to traverse all the way and find the last node, and ‘temp’ is a trailing pointer to ‘cur’. Once you reach the end of the list, setNext of ‘temp’ to null, ‘cur’ is not being pointed to by any node, and hence it is available for garbage collection.

 
 

5. What is the functionality of the following code?

public void function(Node node)
{
	if(size == 0)
		head = node;
	else
	{
		Node temp,cur;
		for(cur = head; (temp = cur.getNext())!=null; cur = temp);
		cur.setNext(node);
	}
	size++;
}

a) Inserting a node at the beginning of the list
b) Deleting a node at the beginning of the list
c) Inserting a node at the end of the list
d) Deleting a node at the end of the list
Answer: c
Clarification: The for loop traverses through the list and then inserts a new node as cur.setNext(node);

6. What is the space complexity for deleting a linked list?
a) O(1)
b) O(n)
c) Either O(1) or O(n)
d) O(logn)
Answer: a
Clarification: You need a temp variable to keep track of current node, hence the space complexity is O(1).

7. How would you delete a node in the singly linked list? The position to be deleted is given.
a)

public void delete(int pos)
{
	if(pos < 0)
	pos = 0;
	if(pos > size)
	pos = size;
	if( size == 0)
	return;
	if(pos == 0)
	head = head.getNext();
	else
	{
	    Node temp = head;
	    for(int i=1; i<pos; i++)
            {
		temp = temp.getNext();
            }
	    temp.setNext(temp.getNext().getNext());
	}
	    size--;
}

b)

public void delete(int pos)
{
	if(pos < 0)
	pos = 0;
	if(pos > size)
	pos = size;
	if( size == 0)
	return;
	if(pos == 0)
	head = head.getNext();
	else
	{
	    Node temp = head;
	    for(int i=1; i<pos; i++)
	    {
		temp = temp.getNext();
	    }
	    temp.setNext(temp.getNext());
	}
	    size--;
}

c)

public void delete(int pos)
{
        if(pos < 0)
	pos = 0;
	if(pos > size)
	pos = size;
	if( size == 0)
	return;
	if(pos == 0)
	head = head.getNext();
	else
	{
	    Node temp = head;
	    for(int i=1; i<pos; i++)
	    {
		temp = temp.getNext().getNext();
            }
	    temp.setNext(temp.getNext().getNext());
	}
	    size--;
}

d)

public void delete(int pos)
{
        if(pos < 0)
        pos = 0;
        if(pos > size)
        pos = size;
        if( size == 0)
	return;
	if(pos == 0)
	head = head.getNext();
	else
	{
	    Node temp = head;
	    for(int i=0; i<pos; i++)
	    {
		temp = temp.getNext();
	    }
	    temp.setNext(temp.getNext().getNext());
	}
	size--;
}

View Answer

Answer: a
Clarification: Loop through the list to get into position one behind the actual position given. temp.setNext(temp.getNext().getNext()) will delete the specified node.

 
 

8. Which of these is not an application of a linked list?
a) To implement file systems
b) For separate chaining in hash-tables
c) To implement non-binary trees
d) Random Access of elements
Answer: d
Clarification: To implement file system, for separate chaining in hash-tables and to implement non-binary trees linked lists are used. Elements are accessed sequentially in linked list. Random access of elements is not an applications of linked list.

9. Which of the following piece of code has the functionality of counting the number of elements in the list?
a)

public int length(Node head)
{
	int size = 0;
	Node cur = head;
	while(cur!=null)
	{
	    size++;
	    cur = cur.getNext();
	}
	return size;
}

b)

public int length(Node head)
{
        int size = 0;
	Node cur = head;
	while(cur!=null)
	{
	    cur = cur.getNext();
	    size++;
	}
	return size;
}

c)

public int length(Node head)
{
	int size = 0;
	Node cur = head;
	while(cur!=null)
	{
	    size++;
	    cur = cur.getNext();
	}
}

d)

public int length(Node head)
{
	int size = 0;
	Node cur = head;
	while(cur!=null)
	{
	    size++;
	    cur = cur.getNext().getNext();
	}
	return size;
}

View Answer

Answer: a
Clarification: ‘cur’ pointer traverses through list and increments the size variable until the end of list is reached.

 
 

10. How do you insert an element at the beginning of the list?
a)

public void insertBegin(Node node)
{
	node.setNext(head);
	head = node;
	size++;
}

b)

public void insertBegin(Node node)
{
	head = node;
	node.setNext(head);
	size++;
}

c)

public void insertBegin(Node node)
{
	Node temp = head.getNext()
	node.setNext(temp);
	head = node;
	size++;
}

d)

public void insertBegin(Node node)
{
	Node temp = head.getNext()
	node.setNext(temp);
	node = head;
	size++;
}

View Answer

Answer: a
Clarification: Set the ‘next’ pointer point to the head of the list and then make this new node as the head.

 
 

11. What is the functionality of the following piece of code?

public int function(int data)
{
	Node temp = head;
	int var = 0;
	while(temp != null)
	{
		if(temp.getData() == data)
		{
			return var;
		}
		var = var+1;
		temp = temp.getNext();
	}
	return Integer.MIN_VALUE;
}

a) Find and delete a given element in the list
b) Find and return the given element in the list
c) Find and return the position of the given element in the list
d) Find and insert a new element in the list
Answer: c
Clarification: When temp is equal to data, the position of data is returned.

250+ TOP MCQs on Infix to Postfix Conversion and Answers

Data Structures & Algorithms Multiple Choice Questions on “Infix to Postfix Conversion”.

1. When an operand is read, which of the following is done?
a) It is placed on to the output
b) It is placed in operator stack
c) It is ignored
d) Operator stack is emptied

Answer: a
Clarification: While converting an infix expression to a postfix expression, when an operand is read, it is placed on to the output. When an operator is read, it is placed in the operator stack.

2. What should be done when a left parenthesis ‘(‘ is encountered?
a) It is ignored
b) It is placed in the output
c) It is placed in the operator stack
d) The contents of the operator stack is emptied

Answer: c
Clarification: When a left parenthesis is encountered, it is placed on to the operator stack. When the corresponding right parenthesis is encountered, the stack is popped until the left parenthesis and remove both the parenthesis.

3. Which of the following is an infix expression?
a) (a+b)*(c+d)
b) ab+c*
c) +ab
d) abc+*

Answer: a
Clarification: (a+b)*(c+d) is an infix expression. +ab is a prefix expression and ab+c* is a postfix expression.

4. What is the time complexity of an infix to postfix conversion algorithm?
a) O(N log N)
b) O(N)
c) O(N2)
d) O(M log N)

Answer: b
Clarification: The time complexity of an infix to postfix expression conversion algorithm is mathematically found to be O(N).

5.What is the postfix expression for the corresponding infix expression?

a) abc*+de*+
b) abc+*de*+
c) a+bc*de+*
d) abc*+(de)*+

Answer: a
Clarification: Using the infix to postfix expression conversion algorithm, the corresponding postfix expression is found to be abc*+de*+.

6. Parentheses are simply ignored in the conversion of infix to postfix expression.
a) True
b) False

Answer: b
Clarification: When a parenthesis is encountered, it is placed on the operator stack. When the corresponding parenthesis is encountered, the stack is popped until the other parenthesis is reached and they are discarded.

7. It is easier for a computer to process a postfix expression than an infix expression.
a) True
b) False

Answer: a
Clarification: Computers can easily process a postfix expression because a postfix expression keeps track of precedence of operators.

8. What is the postfix expression for the infix expression?

a) -ab-c
b) ab – c –
c) – -abc
d) -ab-c

Answer: b
Clarification: The corresponding postfix expression for the given infix expression is found to be ab-c- and not abc- -.

9. What is the postfix expression for the following infix expression?

a) abc^/d-
b) ab/cd^-
c) ab/^cd-
d) abcd^/-

Answer: a
Clarification: Using the infix to postfix conversion algorithm, the corresponding postfix expression for the infix expression is found to be abc^/d-.

10. Which of the following statement is incorrect with respect to infix to postfix conversion algorithm?
a) operand is always placed in the output
b) operator is placed in the stack when the stack operator has lower precedence
c) parenthesis are included in the output
d) higher and equal priority operators follow the same condition

Answer: c
Clarification: Parentheses are not included in the output. They are placed in the operator stack and then discarded.

11. In infix to postfix conversion algorithm, the operators are associated from?
a) right to left
b) left to right
c) centre to left
d) centre to right

Answer: b
Clarification: In infix, prefix and postfix expressions, the operators are associated from left to right and not right to left.

12. What is the corresponding postfix expression for the given infix expression?

a) ab*+cd/
b) ab+*cd/
c) abc*+/d
d) abc+*d/

Answer: d
Clarification: Using the infix to postfix conversion algorithm, the corresponding postfix expression is obtained as abc+*d/.

13. What is the corresponding postfix expression for the given infix expression?

a) ab*cdef/^*g-h+
b) abcdef^/*g*h*+
c) abcd*^ed/g*-h*+
d) abc*de^fg/*-*h+

Answer: b
Clarification: Using the infix to postfix expression conversion algorithm using stack, the corresponding postfix expression is found to be abcdef^/*g*h*+.

14. What is the correct postfix expression for the following expression?

a) abc^de-fg+*^*+i-
b) abcde^-fg*+*^h*+i-
c) abcd^e-fgh*+^*+i-
d) ab^-dc*+ef^gh*+i-

Answer: c
Clarification: The postfix expression for the given infix expression is found to be abcd^e-fgh*+^*+i- when we use infix to postfix conversion algorithm.

250+ TOP MCQs on Number of Jumps to Reach End-array Operation and Answers

Data Structures & Algorithms Multiple Choice Questions on “Number of Jumps to Reach End-array Operation”.

1. What will be the minimum number of jumps required to reach the end of the array arr[] = {1,3,6,3,6,8,5}?
a) 1
b) 2
c) 3
d) not possible to reach the end
Answer: c
Clarification: Each element of the array represents the maximum number of steps that can be taken forward from that element. If the first element is 0 then it is not possible to reach the end.

2. What will be the minimum number of jumps required to reach the end of the array arr[] ={0,1,3,6,3,6,8,5}?
a) 1
b) 2
c) 3
d) not possible to reach the end
Answer: d
Clarification: Each element of the array represents the maximum number of steps that can be taken forward from that element. So as the first element here is 0 so we cannot move any further from the first element. Thus, it is not possible to reach the end of the array.

3. What will be the output of the following code?

#include  
using namespace std; 
 
int func(int arr[], int s, int e) 
{
   if (s == e) 
	return 0; 
   if (arr[s] == 0) 
	return INT_MAX; 
 
int min = INT_MAX; 
for (int i = s + 1; i <= e && i <= s + arr[s]; i++) 
{ 
	int jumps = func(arr, i, e); 
	if(jumps != INT_MAX && jumps + 1 < min) 
		min = jumps + 1; 
} 
return min; 
}
 
int main() 
{ 
	int arr[] = {1, 3, 6, 3, 8, 5}; 
	int n = sizeof(arr)/sizeof(arr[0]); 
	cout << func(arr, 0, n-1); 
	return 0; 
}

a) 1
b) 2
c) 3
d) error
Answer: c
Clarification: The given code finds the minimum number of steps required to reach the end of the array by using recursion. So the output will be 3.

4. What will be the output of the following code?

#include  
using namespace std; 
 
int min(int x, int y) 
{ return (x < y)? x: y; } 
 
int func(int arr[], int n) 
{ 
 
	int *jump = new int[n]; 
	int i, j; 
 
	if (n == 0 || arr[0] == 0) 
		return INT_MAX; 
 
	jump[0] = 0; 
 
	for (i = 1; i < n; i++) 
	{ 
		jump[i] = INT_MAX; 
		for (j = 0; j < i; j++) 
		{ 
			if (i <= j + arr[j] && jumps[j] != INT_MAX) 
			{ 
				jump[i] = min(jump[i], jump[j] + 1); 
				break; 
			} 
		} 
	} 
	return jump[n-1]; 
} 
 
int main() 
{ 
	int arr[] = {1, 3, 6, 1, 9,7}; 
	int size = sizeof(arr)/sizeof(int); 
	cout<< func(arr,size); 
	return 0; 
}

a) 1
b) 2
c) 3
d) error
Answer: c
Clarification: The given code finds the minimum number of steps required to reach the end of the array by using dynamic programming. So the output will be 3.

5. What will be the time complexity of the following code?

#include  
using namespace std; 
 
int min(int x, int y) 
{ return (x < y)? x: y; } 
 
int func(int arr[], int n) 
{ 
 
	int *jump = new int[n]; 
	int i, j; 
 
	if (n == 0 || arr[0] == 0) 
		return INT_MAX; 
 
	jump[0] = 0; 
 
	for (i = 1; i < n; i++) 
	{ 
		jump[i] = INT_MAX; 
		for (j = 0; j < i; j++) 
		{ 
			if (i <= j + arr[j] && jumps[j] != INT_MAX) 
			{ 
				jump[i] = min(jump[i], jump[j] + 1); 
				break; 
			} 
		} 
	} 
	return jump[n-1]; 
} 
 
int main() 
{ 
	int arr[] = {1, 3, 6, 1, 9,7}; 
	int size = sizeof(arr)/sizeof(int); 
	cout<< func(arr,size); 
	return 0; 
}

a) O(n log n)
b) O(n)
c) O(n1/2)
d) O(n2)
Answer: d
Clarification: The given code finds the minimum number of steps required to reach the end of an array by using dynamic programming. As there is a nested loop in the code so the time complexity will be O(n2).

6. What will be the minimum number of jumps required to reach the end of the array arr[] = {1,2,0,0,3,6,8,5}?
a) 1
b) 2
c) 3
d) not possible to reach the end
Answer: d
Clarification: Each element of the array represents the maximum number of steps that can be taken forward from that element. So we cannot move any further after reaching the second element hence it is impossible to reach the end of the array.

7. It is not possible to find the minimum number of steps to reach the end of an array in linear time.
a) true
b) false
Answer: b
Clarification: It is possible to find the minimum number of steps to reach the end of an array in O(n) time complexity. So it is the fastest possible method of finding the minimum number of steps to reach the end of an array.

8. In how many different ways we can reach the end of the array arr[]={1,3,5,8,9}?
a) 1
b) 2
c) 3
d) 4
Answer: d
Clarification: There are 4 possible ways in which we can reach the end of the array. The possible paths are – 1->3->5->8->9, 1->3->5->9, 1->3->8->9, 1->3->9.

9. What will be the output of the following code?

#include  
using namespace std; 
 
void func(int arr[], int n) 
{  
	int count[n]; 
	memset(count, 0, sizeof(count)); 
 
	for (int i=n-2; i>=0; i--) 
	{ 
		if (arr[i] >= n - i - 1) 
			count[i]++; 
 
		for (int j=i+1; j < n-1 && j <= arr[i] + i; j++) 
 
			if (count[j] != -1) 
				count[i] += count[j]; 
 
		if (count[i] == 0) 
			count[i] = -1; 
	} 
 
	for (int i=0; i<n; i++) 
		cout << count[i] << " "; 
} 
 
int main() 
{ 
	int arr[] = {1, 3, 5, 8, 9}; 
	int n = sizeof(arr) / sizeof(arr[0]); 
	func(arr, n); 
	return 0; 
}

a) 3
b) 4
c) 4 4 2 1 0
d) 4 2 2 0 1
Answer: c
Clarification: The given code finds the number of possible ways to reach the end of an array from each element. So the output will be 4 4 2 1 0.

10. What will be the worst case time complexity of the following code?

#include  
using namespace std; 
 
void func(int arr[], int n) 
{  	
	int count[n]; 
	memset(count, 0, sizeof(count)); 
 
	for (int i=n-2; i>=0; i--) 
	{ 
		if (arr[i] >= n - i - 1) 
			count[i]++; 
 
		for (int j=i+1; j < n-1 && j <= arr[i] + i; j++) 
 
			if (count[j] != -1) 
				count[i] += count[j]; 
 
		if (count[i] == 0) 
			count[i] = -1; 
	} 
 
	for (int i=0; i<n; i++) 
		cout << count[i] << " "; 
} 
 
 
int main() 
{ 
	int arr[] = {1, 3, 5, 8, 9}; 
	int n = sizeof(arr) / sizeof(arr[0]); 
	func(arr, n); 
	return 0; 
}

a) O(n1/2)
b) O(n)
c) O(n3/2)
d) O(n2)
Answer: d
Clarification: The given code finds the number of possible ways to reach the end of an array from each element. By observing the nested loop in the code we can say that the worst case time complexity will be O(n2).

11. : It is not possible to reach the end of an array if starting element of the array is 0.
a) true
b) false
Answer: a
Clarification: If the first element of an array is 0 then it is not possible to reach the end. However, if 0 is present at other positions then we may/may not be able to reach the end.

12. What is the minimum possible time complexity to find the number of steps to reach the end of an array?
a) O(n)
b) O(n2)
c) O(n3/2)
d) O(1)
Answer: a
Clarification: The minimum possible time complexity to reach the end of an array is O(n). So a linear time complexity is possible.

250+ TOP MCQs on AA Tree and Answers

Data Structures & Algorithms Multiple Choice Questions on “AA Tree”.

1. AA Trees are implemented using?
a) Colors
b) Levels
c) Node size
d) Heaps

Answer: b
Clarification: AA Trees are implemented using levels instead of colors to overcome the disadvantages of Red-Black trees.

2. Which of the following is the correct definition for a horizontal link?
a) connection between node and a child of equal levels
b) connection between two nodes
c) connection between two child nodes
d) connection between root node and leaf node

Answer: a
Clarification: A horizontal link is a connection between a node and a child of equal levels.

3. How will you remove a left horizontal link in an AA-tree?
a) by performing right rotation
b) by performing left rotation
c) by deleting both the elements
d) by inserting a new element

Answer: a
Clarification: A left horizontal link is removed by right rotation. A right horizontal link is removed by left rotation.

4. What are the two different operations done in an AA-Tree?
a) shift and color
b) skew and split
c) zig and zag
d) enqueue and dequeue

Answer: b
Clarification: A skew removes a left horizontal link by right rotation and a split removes a right horizontal link by left rotation.

5. In an AA-tree, we process split first, followed by a skew.
a) True
b) False

Answer: b
Clarification: In an AA-tree, skew is processed first followed by a split.

6. How many different shapes does maintenance of AA-Tree need to consider?
a) 7
b) 5
c) 2
d) 3

Answer: c
Clarification: An AA-Tree needs to consider only two shapes unlike a red-black tree which needs to consider seven shapes of transformation.

7. What is the prime condition of AA-tree which makes it simpler than a red-black tree?
a) Only right children can be red
b) Only left children can be red
c) Right children should strictly be black
d) There should be no left children

Answer: a
Clarification: The prime condition of AA-Tree is that only the right children can be red to eliminate possible restructuring cases.

8. Which of the following trees is similar to that of an AA-Tree?
a) Splay Tree
b) B+ Tree
c) AVL Tree
d) Red-Black Tree

Answer: d
Clarification: AA- Tree is a small variation of Red-Black tree. AA-Trees overcome the complexity faced in performing insertion and deletion in Red-Black Trees.

9. What is the worst case analysis of an AA-Tree?
a) O(N)
b) O(log N)
c) O( N log N)
d) O(N2)

Answer: b
Clarification: The worst case analysis of an AA-Tree is mathematically found to be O(log N).

10. AA-Trees makes more rotations than a red-black tree.
a) True
b) False

Answer: a
Clarification: AA- trees make more rotations than a red-black tree since only two shapes are considered for an AA-Tree whereas seven shapes are considered in Red-Black trees.

11. Who is the inventor of AA-Tree?
a) Arne Anderson
b) Daniel Sleator
c) Rudolf Bayer
d) Jon Louis Bentley

Answer: a
Clarification: AA-tree is invented by Arne Anderson. Daniel Sleator invented Splay Tree. Rudolf Bayer invented a Red-Black tree. Jon Louis Bentley invented K-d tree.

12. What should be the condition for the level of a left node?
a) It should be less than or equal to that of its parent
b) It should be greater than that of its parent
c) It should be strictly less than that of its parent
d) The level should be equal to one

Answer: c
Clarification: The level of a left node should be strictly less than that of its parent. The level of a right node is less than or equal to that of its parent.

13. Of the following rules that are followed by an AA-tree, which of the following is incorrect?
1- Only right children can be red
2- Procedures are coded recursively
3- Instead of storing colors, the level of a node is stored
4- There should not be any left children
a) 1
b) 2
c) 3
d) 4

Answer: d
Clarification: In an AA-Tree, both left and right children can be present. The only condition is that only right children can be red.

14. Comparing the speed of execution of Red-Black trees and AA-trees, which one has the faster search time?
a) AA-tree
b) Red-Black tree
c) Both have an equal search time
d) It depends

Answer: a
Clarification: Since an AA-tree tends to be flatter, AA-tree has a faster search time than a Red-Black tree.

250+ TOP MCQs on K-ary Tree and Answers

Data Structures & Algorithms Multiple Choice Questions on “K-ary Tree – 1”.

1. How many child nodes does each node of K-ary Tree contain?
a) 2
b) 3
c) more than k
d) at most k

Answer: d
Clarification: Each node of K-ary tree contains at most k nodes. While tree with 2 nodes is called Binary tree and tree with 3 nodes is called Ternary tree.

2. Which of the following is the name of the node having child nodes?
a) Brother
b) Sister
c) Mother
d) Parent

Answer: d
Clarification: Parent node is the node having child nodes and child nodes may contain references to their parents. Parent node is a node connected by a directed edge to its child.

3. What is the depth of the root node of K-ary tree?
a) 2
b) 1
c) 0
d) 3

Answer: c
Clarification: Depth is defined as the length of the path from root to the node. So the depth of root node in K-ary tree is 0.

4. What is the Height of the root node of K-ary tree?
a) 1
b) 2
c) 3
d) 0

Answer: d
Clarification: Height of K-ary tree is defined as the length of path from root to deepest node in tree. Therefore, height of root node in K-ary tree is 0.

250+ TOP MCQs on Skew Heap and Answers

Data Structures & Algorithms Multiple Choice Questions on “Skew Heap”.

1. ___________ is a self-adjusting version of a leftist heap.
a) Rightist heap
b) Skew heap
c) d-heap
d) Binary heap

Answer: b
Clarification: A skew heap is a self-adjusting version of a leftist heap and it is simpler to implement.

2. The worst case running time of all operations in a skew heap is given as?
a) O(N)
b) O(N log N)
c) O(N2)
d) O(M log N)

Answer: a
Clarification: The worst case running time of all operations in a skew heap is mathematically found to be O(N).

3. What is the amortized cost per operation of a skew heap?
a) O(N)
b) O(N log N)
c) O(N2)
d) O(log N)

Answer: d
Clarification: The amortized cost per operation of a skew heap is O(log N) since the worst case analysis of skew heap is O(N) and splay tree is O(M log N).

4. The relationship of skew heaps to leftist heaps is analogous to that of?
a) Splay tree and AVL tree
b) Red black tree and AVL tree
c) Binary tree and Splay tree
d) Binary tree and Red black tree

Answer: a
Clarification: Splay tree is a self -adjusting version of AVL tree. Similarly, skew heap is a self-adjusting version of leftist heap.

5. What is the fundamental operation performed in skew heaps?
a) intersection
b) difference
c) merging
d) sorting

Answer: c
Clarification: The fundamental operation of skew heaps is merging. Hence, it is similar to that of a leftist heap.

6. What is the time per operation of merging, insertion and deletion operations in a skew heap?
a) O(N)
b) O(log N)
c) O(N log N)
d) O(N2)

Answer: b
Clarification: Skew heaps support merging, insertion and deletion all effectively in O(log N) time per operation.

7. Why would a recursive implementation fail in skew heaps?
a) skew heaps are self adjusting
b) efficiency gets reduced
c) lack of stack space
d) time complexity

Answer: c
Clarification: In skew heaps, a recursive implementation could fail because of lack of stack space even though performance is acceptable.

8. Which of the following is difficult to determine the right path length?
a) Skew heaps
b) Binomial tree
c) Leftist heap
d) d-heap

Answer: a
Clarification: It is an open problem to determine precisely the expected right path length of both leftist and skew heaps and comparatively, the latter is difficult.

9. The worst case analysis for a naïve merge is given as?
a) O(N)
b) O( log N)
c) O( N log N)
d) O(N2)

Answer: a
Clarification: The worst-case analysis for the naïve merge is an insertion in a right heavy tree. So, insertion takes O(N).

10. How many types of the merge are available in skew heaps?
a) 1
b) 2
c) 3
d) 4

Answer: b
Clarification: Two kinds of the merge are available in skew heaps- naïve merge and skew merge.

11. Naïve merge cannot be done in a skew merge.
a) true
b) false

Answer: b
Clarification: One way of doing skew merge is to begin with naïve merge and then swapping the left and right children of the tree.

12. What is the amortized efficiency of skew merge?
a) O(N)
b) O( log N)
c) O( N log N)
d) O(N2)

Answer: b
Clarification: The amortized efficiency of a skew heap is mathematically found to be O( log N).

13. In skew heaps, certain constraints are to be met in order to perform swapping.
a) true
b) false

Answer: b
Clarification: In skew heaps, swaps are unconditional. It is done with the exception that the largest of all nodes does not have its children swapped.