Bird
Raised Fist0
DSA C#programming~20 mins

Delete from Beginning of Doubly Linked List in DSA C# - Practice Problems & Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Doubly Linked List Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output after deleting the first node from a doubly linked list
What is the printed state of the doubly linked list after deleting the first node?
DSA C#
using System;

class Node {
    public int data;
    public Node prev, next;
    public Node(int d) { data = d; prev = next = null; }
}

class DoublyLinkedList {
    public Node head;

    public void Push(int new_data) {
        Node new_node = new Node(new_data);
        new_node.next = head;
        if (head != null) head.prev = new_node;
        head = new_node;
    }

    public void DeleteFromBeginning() {
        if (head == null) return;
        head = head.next;
        if (head != null) head.prev = null;
    }

    public void PrintList() {
        Node temp = head;
        while (temp != null) {
            Console.Write(temp.data + " <-> ");
            temp = temp.next;
        }
        Console.WriteLine("null");
    }
}

class Program {
    static void Main() {
        DoublyLinkedList dll = new DoublyLinkedList();
        dll.Push(3);
        dll.Push(2);
        dll.Push(1);
        dll.DeleteFromBeginning();
        dll.PrintList();
    }
}
A3 <-> 2 <-> 1 <-> null
B1 <-> 2 <-> 3 <-> null
C2 <-> 3 <-> null
Dnull
Attempts:
2 left
💡 Hint
Remember that deleting from the beginning removes the head node and updates the head pointer.
❓ Predict Output
intermediate
2:00remaining
Resulting list after deleting from an empty doubly linked list
What is the output when deleting from the beginning of an empty doubly linked list and then printing it?
DSA C#
using System;

class Node {
    public int data;
    public Node prev, next;
    public Node(int d) { data = d; prev = next = null; }
}

class DoublyLinkedList {
    public Node head;

    public void DeleteFromBeginning() {
        if (head == null) return;
        head = head.next;
        if (head != null) head.prev = null;
    }

    public void PrintList() {
        Node temp = head;
        while (temp != null) {
            Console.Write(temp.data + " <-> ");
            temp = temp.next;
        }
        Console.WriteLine("null");
    }
}

class Program {
    static void Main() {
        DoublyLinkedList dll = new DoublyLinkedList();
        dll.DeleteFromBeginning();
        dll.PrintList();
    }
}
Anull
BEmpty list
CThrows NullReferenceException
D0 <-> null
Attempts:
2 left
💡 Hint
Check what happens if the list is empty before deletion.
🔧 Debug
advanced
2:00remaining
Identify the error in deleting the first node of a doubly linked list
What error does the following code produce when deleting the first node from a doubly linked list?
DSA C#
public void DeleteFromBeginning() {
    if (head == null) return;
    head = head.next;
    head.prev = null;
}
ANullReferenceException when list has only one node
BNo error, works correctly
CCompilation error due to invalid syntax
DLogical error: does not update head pointer
Attempts:
2 left
💡 Hint
Consider the order of operations and what happens when head.next is null.
🧠 Conceptual
advanced
1:30remaining
Effect of deleting the first node on the previous pointer of the new head
After deleting the first node from a doubly linked list, what should be the value of the previous pointer of the new head node?
AIt should point to the old head node
BIt should point to the next node
CIt should point to itself
DIt should be null
Attempts:
2 left
💡 Hint
Think about the start of the list and what previous means for the head node.
❓ Predict Output
expert
2:30remaining
Output after multiple deletions from the beginning of a doubly linked list
What is the printed state of the doubly linked list after deleting the first node twice in a row?
DSA C#
using System;

class Node {
    public int data;
    public Node prev, next;
    public Node(int d) { data = d; prev = next = null; }
}

class DoublyLinkedList {
    public Node head;

    public void Push(int new_data) {
        Node new_node = new Node(new_data);
        new_node.next = head;
        if (head != null) head.prev = new_node;
        head = new_node;
    }

    public void DeleteFromBeginning() {
        if (head == null) return;
        head = head.next;
        if (head != null) head.prev = null;
    }

    public void PrintList() {
        Node temp = head;
        while (temp != null) {
            Console.Write(temp.data + " <-> ");
            temp = temp.next;
        }
        Console.WriteLine("null");
    }
}

class Program {
    static void Main() {
        DoublyLinkedList dll = new DoublyLinkedList();
        dll.Push(4);
        dll.Push(3);
        dll.Push(2);
        dll.Push(1);
        dll.DeleteFromBeginning();
        dll.DeleteFromBeginning();
        dll.PrintList();
    }
}
A2 <-> 3 <-> 4 <-> null
B3 <-> 4 <-> null
C1 <-> 2 <-> 3 <-> 4 <-> null
D4 <-> null
Attempts:
2 left
💡 Hint
Each deletion removes the current head and updates the head pointer.

Practice

(1/5)
1. What happens to the head pointer when you delete the first node from a doubly linked list?
easy
A. It becomes null immediately
B. It remains unchanged
C. It points to the last node
D. It moves to the second node in the list

Solution

  1. Step 1: Understand the role of head pointer

    The head pointer always points to the first node in the doubly linked list.
  2. Step 2: Effect of deleting the first node

    When the first node is deleted, the head pointer must move to the next node, which becomes the new first node.
  3. Final Answer:

    It moves to the second node in the list -> Option D
  4. Quick Check:

    Head points to new first node after deletion [OK]
Hint: Head always points to the first node after deletion [OK]
Common Mistakes:
  • Assuming head becomes null even if list has more nodes
  • Not updating head pointer after deletion
  • Pointing head to last node mistakenly
2. Which of the following is the correct syntax to delete the first node in a doubly linked list in C#?
easy
A. head = head.next; head.prev = null;
B. head = head.prev; head.next = null;
C. head.next = null; head.prev = null;
D. head = null; head.next = null;

Solution

  1. Step 1: Move head to next node

    To delete the first node, assign head to head.next to point to the second node.
  2. Step 2: Remove backward link

    Set head.prev to null to disconnect the previous first node.
  3. Final Answer:

    head = head.next; head.prev = null; -> Option A
  4. Quick Check:

    Correct syntax updates head and prev pointer [OK]
Hint: Set head to next and prev of new head to null [OK]
Common Mistakes:
  • Setting head.prev instead of head.next
  • Not nullifying prev pointer of new head
  • Setting head to null prematurely
3. Given the doubly linked list: 10 <-> 20 <-> 30 <-> null, what will be the list after deleting the first node?
medium
A. 10 <-> 30 <-> null
B. 20 <-> 30 <-> null
C. 30 <-> null
D. null

Solution

  1. Step 1: Identify the first node

    The first node has value 10, which will be removed.
  2. Step 2: Update head to second node

    Head moves to node with value 20, and its prev pointer is set to null.
  3. Final Answer:

    20 <-> 30 <-> null -> Option B
  4. Quick Check:

    First node removed, list starts at 20 [OK]
Hint: After deletion, head points to second node [OK]
Common Mistakes:
  • Removing wrong node (like 20 or 30)
  • Not updating prev pointer of new head
  • Leaving old head in the list
4. Consider this code snippet to delete the first node from a doubly linked list:
if (head != null) {
    head = head.next;
    head.prev = null;
}
What error can occur here?
medium
A. Logical error: head should not be updated
B. Syntax error due to missing semicolon
C. NullReferenceException if list has only one node
D. No error, code is correct

Solution

  1. Step 1: Analyze when list has one node

    If list has one node, head.next is null after assignment.
  2. Step 2: Accessing head.prev causes error

    Setting head.prev = null when head is null causes NullReferenceException.
  3. Final Answer:

    NullReferenceException if list has only one node -> Option C
  4. Quick Check:

    Accessing property on null causes exception [OK]
Hint: Check if head is null before setting head.prev [OK]
Common Mistakes:
  • Not checking if head is null after moving to next
  • Assuming code always works for single-node list
  • Ignoring runtime exceptions
5. You have a doubly linked list with nodes: 5 <-> 15 <-> 25 <-> 35 <-> null. After deleting the first node twice, what is the resulting list?
hard
A. 25 <-> 35 <-> null
B. 15 <-> 25 <-> 35 <-> null
C. 35 <-> null
D. null

Solution

  1. Step 1: Delete first node once

    First deletion removes node with value 5; head moves to 15.
  2. Step 2: Delete first node second time

    Second deletion removes node with value 15; head moves to 25.
  3. Final Answer:

    25 <-> 35 <-> null -> Option A
  4. Quick Check:

    Two deletions remove first two nodes [OK]
Hint: Each deletion moves head to next node [OK]
Common Mistakes:
  • Deleting only once instead of twice
  • Not updating head correctly after second deletion
  • Confusing node values order
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard