Explore topic-wise MCQs in Technical Programming.

This section includes 721 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.

601.

In case of insertion into a linked queue, a node borrowed from the __________ list is inserted in the queue.

A. AVAIL
B. FRONT
C. REAR
D. None of the mentioned
Answer» B. FRONT
602.

 In linked list implementation of a queue, front and rear pointers are tracked. Which of these pointers will change during an insertion into EMPTY queue?

A. Only front pointer
B. Only rear pointer
C. Both front and rear pointer
D. None of the mentioned
Answer» D. None of the mentioned
603.

In linked list implementation of a queue, front and rear pointers are tracked. Which of these pointers will change during an insertion into a NONEMPTY queue?

A. Only front pointer
B. Only rear pointer
C. Both front and rear pointer
D. None of the mentioned
Answer» C. Both front and rear pointer
604.

In linked list implementation of a queue, where does a new element be inserted?

A. At the head of link list
B. At the centre position in the link list
C. At the tail of the link list
D. None of the mentioned
Answer» D. None of the mentioned
605.

In linked list implementation of queue, if only front pointer is maintained, which of the following operation take worst case linear time?

A. Insertion
B. Deletion
C. To empty a queue
D. Both Insertion and To empty a queue
Answer» E.
606.

What is the output of the following piece of code?

public class CircularQueue
{
	protected static final int CAPACITY = 100;
	protected int size,front,rear;
	protected Object q[];
	int count = 0;
 
	public CircularQueue()
	{
		this(CAPACITY);
	}
	public CircularQueue (int n)
	{
		size = n;
		front = 0;
		rear = 0;
		q = new Object[size];
	}
 
 
	public void enqueue(Object item)
	{
		if(count == size)
		{
			System.out.println("Queue overflow");
				return;
		}
		else
		{
			q[rear] = item;
			rear = (rear+1)%size;
			count++;
		}
	}
	public Object dequeue()
	{
		if(count == 0)
		{
			System.out.println("Queue underflow");
			return 0;
		}
		else
		{
			Object ele = q[front];
			q[front] = null;
			front = (front+1)%size;
			count--;
			return ele;
		}
	}
	public Object frontElement()
	{
		if(count == 0)
		return -999;
		else
		{
			Object high;
			high = q[front];
			return high;
		}
	}
	public Object rearElement()
	{
		if(count == 0)
		return -999;
		else
		{
			Object low;
			rear = (rear-1)%size;
			low = q[rear];
			rear = (rear+1)%size;
			return low;
		}
	}
}
public class CircularQueueDemo
{
	public static void main(String args[])
	{
		Object var;
		CircularQueue myQ = new CircularQueue();
		myQ.enqueue(10);
		myQ.enqueue(3);
		var = myQ.rearElement();
		myQ.dequeue();
		myQ.enqueue(6);
		var = mQ.frontElement();
		System.out.println(var+" "+var);
	}
}

A. 3 3
B. 3 6
C. 6 6
D. 10 6
Answer» B. 3 6
607.

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

A. O(n)
B. O(nlogn)
C. O(logn)
D. O(1)
Answer» B. O(nlogn)
608.

What is the need for a circular queue?

A. effective usage of memory
B. easier computations
C. all of the mentioned
D. none of the mentioned
Answer» B. easier computations
609.

What does the following piece of code do?

public Object function()
{
	if(isEmpty())
	return -999;
	else
	{
		Object high;
		high = q[front];
		return high;
	}
}

A. Dequeue
B. Enqueue
C. Return the front element
D. None of the mentioned
Answer» D. None of the mentioned
610.

 What is the time complexity of enqueue operation?

A. O(logn)
B. O(nlogn)
C. O(n)
D. O(1)
Answer» E.
611.

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

A. overflow
B. underflow
C. null pointer exception
D. all of the mentioned
Answer» B. underflow
612.

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

A. rear++
B. (rear+1) % CAPACITY
C. (rear % CAPACITY)+1
D. rear–
Answer» C. (rear % CAPACITY)+1
613.

 Which of the following properties is associated with a queue?

A. First In Last Out
B. First In First Out
C. Last In First Out
D. None of the mentioned
Answer» C. Last In First Out
614.

Minimum number of queues to implement stack is __________

A. 3
B. 4
C. 1
D. 2
Answer» D. 2
615.

Which of the following data structures can be used for parentheses matching?

A. n-ary tree
B. queue
C. priority queue
D. stack
Answer» E.
616.

Consider these functions:
push() : push an element into the stack
pop() : pop the top-of-the-stack element
top() : returns the item stored in top-of-the-stack-node
What will be the output after performing these sequence of operations

push(20);
push(4);
top();
pop();
pop();
pop();
push(5);
top();

A. 20
B. 4
C. stack underflow
D. 5
Answer» E.
617.

What does ‘stack overflow’ refer to?

A. accessing item from an undefined stack
B. adding items to a full stack
C. removing items from an empty stack
D. index out of bounds exception
Answer» C. removing items from an empty stack
618.

Which of the following statements are correct with respect to Singly Linked List(SLL) and Doubly Linked List(DLL)?

A. Complexity of Insertion and Deletion at known position is O(n) in SLL and O(1) in DLL
B. SLL uses lesser memory per node than DLL
C. DLL has more searching power than SLL
D. All of the mentioned
Answer» E.
619.

What is the complexity of searching for a particular element in a Singly Linked List?

A. O(n)
B. O(1)
C. logn
D. nlogn
Answer» B. O(1)
620.

Which of the following array element will return the top-of-the-stack-element for a stack of size N elements(capacity of stack > N).

A. S[N-1].
B. S[N].
C. S[N-2].
D. S[N+1].
Answer» B. S[N].
621.

Array implementation of Stack is not dynamic’, which of the following statements supports this argument?

A. space allocation for array is fixed and cannot be changed during run-time
B. user unable to give the input for stack operations
C. a runtime exception halts execution
D. all of the mentioned
Answer» B. user unable to give the input for stack operations
622.

What happens when you pop from an empty stack while implementing using the Stack ADT in Java?

A. Undefined error
B. Compiler displays a warning
C. EmptyStackException is thrown
D. NoStackException is thrown
Answer» D. NoStackException is thrown
623.

Which of the following array position will be occupied by a new element being pushed for a stack of size N elements(capacity of stack > N).

A. S[N-1].
B. S[N].
C. S[1].
D. S[0].
Answer» C. S[1].
624.

What is the time complexity of pop() operation when the stack is implemented using an array?

A. O(1)
B. O(n)
C. O(logn)
D. O(nlogn)
Answer» B. O(n)
625.

What is the output of the following program?

public class Stack
{
	protected static final int CAPACITY = 100;
	protected int size,top = -1;
	protected Object stk[];
 
	public Stack()
	{
		stk = new Object[CAPACITY];
	}
 
	public void push(Object item)
	{
		if(size_of_stack==size)
		{
			System.out.println("Stack overflow");
				return;
		}
		else
		{
			top++;
			stk[top]=item;
		}
	}
	public Object pop()
	{
		if(top<0)
		{
			return -999;
		}
		else
		{
			Object ele=stk[top];
			top--;
			size_of_stack--;
			return ele;
		}
	}
}
 
public class StackDemo
{
	public static void main(String args[])
	{
		Stack myStack = new Stack();
		myStack.push(10);
		Object element1 = myStack.pop();
		Object element2 = myStack.pop();
		System.out.println(element2);
	}
}

A. stack is full
B. 20
C. 0
D. none of the mentioned
Answer» E.
626.

What does ‘stack underflow’ refer to?

A. accessing item from an undefined stack
B. adding items to a full stack
C. removing items from an empty stack
D. index out of bounds exception
Answer» D. index out of bounds exception
627.

What does the following function check for? (all necessary headers to be included and function is called from main)

   #define MAX 10
 
   typedef struct stack
   {
        int top;
	int item[MAX];
   }stack;
 
   int function(stack *s)
   {
        if(s->top == -1)
	    return 1;
	 else return 0;
   }

A. full stack
B. invalid index
C. empty stack
D. infinite stack
Answer» D. infinite stack
628.

Which of the following real world scenarios would you associate with a stack data structure?

A. piling up of chairs one above the other
B. people standing in a line to be serviced at a counter
C. offer services based on the priority of the customer
D. all of the mentioned
Answer» B. people standing in a line to be serviced at a counter
629.

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

A. Keep one node as head and traverse another temp node till the end to check if its ‘next points to head
B. 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
C. Cannot determine, you have to pre-define if the list contains cycles
D. None of the mentioned
Answer» C. Cannot determine, you have to pre-define if the list contains cycles
630.

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

A. Every node has a successor
B. Time complexity of inserting a new node at the head of the list is O(1)
C. Time complexity for deleting the last node is O(n)
D. None of the mentioned
Answer» C. Time complexity for deleting the last node is O(n)
631.

What is the functionality of the following code? Choose the most appropriate answer.

public int function()
{
	if(head == null)
		return Integer.MIN_VALUE;
	int var;
	Node temp = head;
	Node cur;
	while(temp.getNext() != head)
	{
		cur = temp;
		temp = temp.getNext();
	}
	if(temp == head)
	{
		var = head.getItem();
		head = null;
		return var;
	}
	var = temp.getItem();
	cur.setNext(head);
	return var;
}

A. Return data from the end of the list
B. Returns the data and deletes the node at the end of the list
C. Returns the data from the beginning of the list
D. Returns the data and deletes the node from the beginning of the list
Answer» C. Returns the data from the beginning of the list
632.

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

A. Undo operation in a text editor
B. Recursive function calls
C. Allocating CPU to resources
D. All of the mentioned
Answer» D. All of the mentioned
633.

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

A. O(n)
B. O(nlogn)
C. O(1)
D. None of the mentioned
Answer» B. O(nlogn)
634.

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

A. You cannot have the ‘next’ pointer point to null in a circular linked list
B. It is faster to traverse the circular linked list
C. You may or may not have the ‘next’ pointer point to null in a circular linked list
D. All of the mentioned
Answer» D. All of the mentioned
635.

Consider the following doubly linked list: head-1-2-3-4-5-tail
What will be the list after performing the given sequence of operations?

	Node temp = new Node(6,head,head.getNext());
	head.setNext(temp);
	temp.getNext().setPrev(temp);
	Node temp1 = tail.getPrev();
	tail.setPrev(temp1.getPrev());
	temp1.getPrev().setNext(tail);

A. head-6-1-2-3-4-5-tail
B. head-6-1-2-3-4-tail
C. head-1-2-3-4-5-6-tail
D. head-1-2-3-4-5-tail
Answer» C. head-1-2-3-4-5-6-tail
636.

What is the functionality of the following piece of code?

public int function()
{
	Node temp = tail.getPrev();
	tail.setPrev(temp.getPrev());
	temp.getPrev().setNext(tail);
	size--;
	return temp.getItem();
}

A. Return the element at the tail of the list but do not remove it
B. Return the element at the tail of the list and remove it from the list
C. Return the last but one element from the list but do not remove it
D. Return the last but one element at the tail of the list and remove it from the list
Answer» C. Return the last but one element from the list but do not remove it
637.

Consider the following doubly linked list: head-1-2-3-4-5-tail
What will be the list after performing the given sequence of operations?

	Node temp = new Node(6,head,head.getNext());
	Node temp1 = new Node(0,tail.getPrev(),tail);
	head.setNext(temp);
	temp.getNext().setPrev(temp);
	tail.setPrev(temp1);
	temp1.getPrev().setNext(temp1);

A. head-0-1-2-3-4-5-6-tail
B. head-1-2-3-4-5-6-tail
C. head-6-1-2-3-4-5-0-tail
D. head-0-1-2-3-4-5-tail
Answer» D. head-0-1-2-3-4-5-tail
638.

What is the time complexity of inserting a node in a doubly linked list?

A. O(nlogn)
B. O(logn)
C. O(n)
D. O(1)
Answer» D. O(1)
639.

How do you calculate the pointer difference in a memory efficient double linked list?

A. head xor tail
B. pointer to previous node xor pointer to next node
C. pointer to previous node – pointer to next node
D. pointer to next node – pointer to previous node
Answer» C. pointer to previous node – pointer to next node
640.

 What is a memory efficient double linked list?

A. Each node has only one pointer to traverse the list back and forth
B. The list has breakpoints for faster traversal
C. An auxiliary singly linked list acts as a helper list to traverse through the doubly linked list
D. None of the mentioned
Answer» B. The list has breakpoints for faster traversal
641.

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

A. We can navigate in both the directions
B. It requires more space than a singly linked list
C. The insertion and deletion of a node take a bit longer
D. None of the mentioned
Answer» E.
642.

Which of these is an application of linked lists?

A. To implement file systems
B. For separate chaining in hash-tables
C. To implement non-binary trees
D. All of the mentioned
Answer» E.
643.

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» B. O(n)
644.

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. None of the mentioned
Answer» C. O(logn)
645.

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» E.
646.

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

A. Fixed size
B. You know the size of the array prior to allocation
C. Insertion based on position
D. Accessing elements at specified positions
Answer» E.
647.

You are given pointers to first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list?

A. Delete the first element
B. Insert a new element as a first element
C. Delete the last element of the list
D. Add a new element at the end of the list
Answer» D. Add a new element at the end of the list
648.

Given pointer to a node X in a singly linked list. Only one pointer is given, pointer to head node is not given, can we delete the node X from given linked list?

A. Possible if X is not last node
B. Possible if size of linked list is even
C. Possible if size of linked list is odd
D. Possible if X is not first node
Answer» B. Possible if size of linked list is even
649.

 In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is

A. log 2 n
B. n⁄2
C. log 2 n – 1
D. n
Answer» E.
650.

The following C function takes a single-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?

struct node 
{
    int value;
    struct node *next;
};
void rearrange(struct node *list)
{
    struct node *p, * q;
    int temp;
    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?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
Answer» C. 1, 3, 2, 5, 4, 7, 6