GateAI
Linear Structures, Trees and Heaps

GATE CSE 2023 · Q13

MCQ1 markEasy

Time

Let SLLdel be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to the head of the list. Similarly, let DLLdel be another function that deletes a node in a doubly-linked list given a pointer to the node and a pointer to the head of the list. Let nn denote the number of nodes in each of the linked lists. Which one of the following choices is TRUE about the worst-case time complexity of SLLdel and DLLdel?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) SLLdel is O(n) and DLLdel is O(1)

Linear Structures, Trees and Heaps

To delete a node from a linked list:

  1. Singly-Linked List (SLLdel):

    • To delete a given node, we must update the next pointer of its predecessor node to bypass it.

    • Since each node in a singly-linked list only has a pointer to its successor, we cannot access the predecessor directly.

    • In the worst case (such as when the node to delete is the last node), we must traverse the list starting from the head pointer to locate the predecessor node. This takes O(n)O(n) time.

  2. Doubly-Linked List (DLLdel):

    • Each node contains direct pointers to both its predecessor (prev) and successor (next).

    • Given a pointer to the target node, we can directly update the adjacent pointers:

      node→prev→next=node→next\text{node}\to\text{prev}\to\text{next} = \text{node}\to\text{next}
      node→next→prev=node→prev\text{node}\to\text{next}\to\text{prev} = \text{node}\to\text{prev}
    • This requires only a constant number of pointer operations and does not require traversing from the head. Hence, the worst-case time complexity is O(1)O(1).

Therefore, SLLdelis $O(n)$ andDLLdelis $O(1)$, which corresponds to option(D).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Linear Structures, Trees and Heaps previous year question is Q13 of the GATE CSE 2023 paper. Find more GATE CSE PYQs on Linear Structures, Trees and Heaps in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Linear Structures, Trees and Heaps PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Linear Structures, Trees and Heaps in GATE CSE

Linear Structures, Trees and Heaps has 14 GATE CSE PYQs across 12 papers from 2012 to 2026. 7 of them are 1-mark MCQs like this one, and GATE CSE 2023 has 2.

How GATE tests Linear Structures, Trees and Heaps

More from GATE CSE 2023

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2023 · Q13 · MCQ

Let SLLdel be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to the head of the list. Similarly, let DLLdel be another function that deletes a node in a doubly-linked list given a pointer to the node and a pointer to the head of the list. Let n denote the number of nodes in each of the linked lists. Which one of the following choices is TRUE about the worst-case time complexity of SLLdel and DLLdel ?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.