Bird
Raised Fist0
DSA C#programming~20 mins

Delete Node at Beginning in DSA C# - Practice Problems & Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Delete Node 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 in a singly linked list
What is the printed state of the linked list after deleting the first node?
DSA C#
public class Node {
    public int data;
    public Node next;
    public Node(int d) { data = d; next = null; }
}

public class LinkedList {
    public Node head;

    public void DeleteAtBeginning() {
        if (head != null) {
            head = head.next;
        }
    }

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

class Program {
    static void Main() {
        LinkedList list = new LinkedList();
        list.head = new Node(10);
        list.head.next = new Node(20);
        list.head.next.next = new Node(30);
        list.DeleteAtBeginning();
        list.PrintList();
    }
}
A20 -> 30 -> null
B10 -> 20 -> 30 -> null
C30 -> null
Dnull
Attempts:
2 left
💡 Hint
Deleting the first node means the head moves to the next node.
❓ Predict Output
intermediate
2:00remaining
Output when deleting from an empty linked list
What is the output when DeleteAtBeginning is called on an empty linked list and then printed?
DSA C#
public class Node {
    public int data;
    public Node next;
    public Node(int d) { data = d; next = null; }
}

public class LinkedList {
    public Node head;

    public void DeleteAtBeginning() {
        if (head != null) {
            head = head.next;
        }
    }

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

class Program {
    static void Main() {
        LinkedList list = new LinkedList();
        list.DeleteAtBeginning();
        list.PrintList();
    }
}
AException thrown
B0 -> null
Cnull
Dundefined
Attempts:
2 left
💡 Hint
Deleting from an empty list should not change anything.
🔧 Debug
advanced
2:00remaining
Identify the error in DeleteAtBeginning method
What error will occur when running this DeleteAtBeginning method on a non-empty list?
DSA C#
public void DeleteAtBeginning() {
    head = head.next.next;
}
ACompilation error due to syntax
BNullReferenceException when list has only one node
CNo error, deletes first node correctly
DDeletes last node instead of first
Attempts:
2 left
💡 Hint
Check what happens if head.next is null.
🧠 Conceptual
advanced
1:00remaining
Time complexity of deleting the first node in a singly linked list
What is the time complexity of deleting the first node in a singly linked list?
AO(1) - constant time
BO(n) - linear time
CO(log n) - logarithmic time
DO(n^2) - quadratic time
Attempts:
2 left
💡 Hint
Deleting the first node only changes the head pointer.
❓ Predict Output
expert
3:00remaining
Output after multiple deletions at beginning
What is the printed state of the linked list after deleting the first node twice?
DSA C#
public class Node {
    public int data;
    public Node next;
    public Node(int d) { data = d; next = null; }
}

public class LinkedList {
    public Node head;

    public void DeleteAtBeginning() {
        if (head != null) {
            head = head.next;
        }
    }

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

class Program {
    static void Main() {
        LinkedList list = new LinkedList();
        list.head = new Node(5);
        list.head.next = new Node(15);
        list.head.next.next = new Node(25);
        list.head.next.next.next = new Node(35);
        list.DeleteAtBeginning();
        list.DeleteAtBeginning();
        list.PrintList();
    }
}
A5 -> 15 -> 25 -> 35 -> null
B15 -> 25 -> 35 -> null
C35 -> null
D25 -> 35 -> null
Attempts:
2 left
💡 Hint
Each deletion moves the head to the next node.

Practice

(1/5)
1. What happens when you delete the first node in a singly linked list?
easy
A. The last node is deleted instead of the first
B. Nothing happens because the first node cannot be deleted
C. The entire list is deleted
D. The head pointer moves to the second node, removing the first node from the list

Solution

  1. Step 1: Understand the head pointer role

    The head pointer points to the first node in the list.
  2. Step 2: Update head to next node

    Deleting the first node means moving the head pointer to the second node, effectively removing the first node.
  3. Final Answer:

    The head pointer moves to the second node, removing the first node from the list -> Option D
  4. Quick Check:

    Delete first node = move head to next [OK]
Hint: Delete first node by moving head to next node [OK]
Common Mistakes:
  • Trying to delete the last node instead
  • Not updating the head pointer
  • Deleting the entire list accidentally
2. Which of the following is the correct syntax to delete the first node in a singly linked list in C#?
easy
A. head = null.next;
B. head.next = head;
C. head = head.next;
D. head.next = null;

Solution

  1. Step 1: Identify the head pointer update

    To delete the first node, assign head to head.next to move the head pointer forward.
  2. Step 2: Check syntax correctness

    head = head.next; correctly updates the head pointer to the second node.
  3. Final Answer:

    head = head.next; -> Option C
  4. Quick Check:

    Correct syntax to delete first node = head = head.next; [OK]
Hint: Assign head to head.next to delete first node [OK]
Common Mistakes:
  • Reversing the assignment order
  • Using null.next which is invalid
  • Setting head.next to null instead of head
3. Consider the following code snippet for deleting the first node in a linked list:
Node head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);
head = head.next;
What is the state of the list after deletion?
medium
A. 2 -> 3 -> null
B. null
C. 3 -> null
D. 1 -> 2 -> 3 -> null

Solution

  1. Step 1: Initial list creation

    The list starts as 1 -> 2 -> 3 -> null with head at node 1.
  2. Step 2: Delete first node by moving head

    head = head.next moves head to node 2, so the list becomes 2 -> 3 -> null.
  3. Final Answer:

    2 -> 3 -> null -> Option A
  4. Quick Check:

    After deletion, list starts at second node [OK]
Hint: After deletion, list starts from second node [OK]
Common Mistakes:
  • Forgetting to update head pointer
  • Assuming first node still exists
  • Confusing node values after deletion
4. The following code attempts to delete the first node of a linked list but causes a runtime error:
Node head = null;
head = head.next;
What is the error and how to fix it?
medium
A. SyntaxError; fix by adding semicolon
B. NullReferenceException; fix by checking if head is not null before deleting
C. IndexOutOfRangeException; fix by resizing list
D. No error; code works fine

Solution

  1. Step 1: Identify cause of error

    head is null, so accessing head.next causes NullReferenceException.
  2. Step 2: Fix by adding null check

    Check if head != null before assigning head = head.next to avoid error.
  3. Final Answer:

    NullReferenceException; fix by checking if head is not null before deleting -> Option B
  4. Quick Check:

    Null head causes error; check before delete [OK]
Hint: Always check head != null before deleting first node [OK]
Common Mistakes:
  • Ignoring null checks causing runtime errors
  • Assuming list always has nodes
  • Confusing syntax errors with runtime errors
5. You have a singly linked list with nodes: 5 -> 10 -> 15 -> 20 -> null. You delete the first node twice using head = head.next; two times. What is the resulting list?
hard
A. 15 -> 20 -> null
B. 10 -> 15 -> 20 -> null
C. 20 -> null
D. null

Solution

  1. Step 1: Initial list and first deletion

    List starts as 5 -> 10 -> 15 -> 20 -> null. After first deletion, head moves to 10, list is 10 -> 15 -> 20 -> null.
  2. Step 2: Second deletion moves head again

    After second deletion, head moves to 15, list is 15 -> 20 -> null.
  3. Final Answer:

    15 -> 20 -> 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
  • Confusing node values after multiple deletions
  • Assuming list becomes empty too early
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