Bird
Raised Fist0
DSA Javascriptprogramming~20 mins

Delete from Beginning of Doubly Linked List in DSA Javascript - 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 Javascript
class Node {
  constructor(data) {
    this.data = data;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.head = null;
  }

  append(data) {
    const newNode = new Node(data);
    if (!this.head) {
      this.head = newNode;
      return;
    }
    let current = this.head;
    while (current.next) {
      current = current.next;
    }
    current.next = newNode;
    newNode.prev = current;
  }

  deleteFromBeginning() {
    if (!this.head) return;
    this.head = this.head.next;
    if (this.head) this.head.prev = null;
  }

  printList() {
    let current = this.head;
    let result = '';
    while (current) {
      result += current.data + ' <-> ';
      current = current.next;
    }
    result += 'null';
    console.log(result);
  }
}

const dll = new DoublyLinkedList();
dll.append(10);
dll.append(20);
dll.append(30);
dll.deleteFromBeginning();
dll.printList();
A20 <-> 30 <-> null
B10 <-> 20 <-> 30 <-> null
C30 <-> null
Dnull
Attempts:
2 left
💡 Hint
Deleting from the beginning removes the first node and updates the head.
🧠 Conceptual
intermediate
1:30remaining
Effect of deleting from an empty doubly linked list
What happens when you try to delete the first node from an empty doubly linked list?
AThrows a runtime error because head is null.
BCreates a new empty node as head.
CDeletes a non-existent node and corrupts the list.
DNothing happens; the list remains empty without error.
Attempts:
2 left
💡 Hint
Check the deleteFromBeginning method's first condition.
❓ Predict Output
advanced
2:00remaining
Output after multiple deletions from beginning
What is the printed state of the doubly linked list after deleting the first node twice?
DSA Javascript
class Node {
  constructor(data) {
    this.data = data;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.head = null;
  }

  append(data) {
    const newNode = new Node(data);
    if (!this.head) {
      this.head = newNode;
      return;
    }
    let current = this.head;
    while (current.next) {
      current = current.next;
    }
    current.next = newNode;
    newNode.prev = current;
  }

  deleteFromBeginning() {
    if (!this.head) return;
    this.head = this.head.next;
    if (this.head) this.head.prev = null;
  }

  printList() {
    let current = this.head;
    let result = '';
    while (current) {
      result += current.data + ' <-> ';
      current = current.next;
    }
    result += 'null';
    console.log(result);
  }
}

const dll = new DoublyLinkedList();
dll.append(5);
dll.append(15);
dll.append(25);
dll.deleteFromBeginning();
dll.deleteFromBeginning();
dll.printList();
A15 <-> 25 <-> null
B25 <-> null
C5 <-> 15 <-> 25 <-> null
Dnull
Attempts:
2 left
💡 Hint
Each deletion removes the current head node.
🔧 Debug
advanced
2:30remaining
Identify the bug in deleteFromBeginning method
What is the bug in this deleteFromBeginning method and what will be the output after deleting the first node from list 1 <-> 2 <-> 3 <-> null? function deleteFromBeginning() { if (!this.head) return; this.head = this.head.next; // Missing line here } // After calling deleteFromBeginning, printList() is called.
AThe prev pointer of new head is not set to null; output: 2 <-> 3 <-> null but prev of 2 points to 1 (incorrect linkage).
BThrows error because head.next is undefined.
CNo bug; output: 2 <-> 3 <-> null with correct linkage.
DOutput is null because head is set to null.
Attempts:
2 left
💡 Hint
Check if the prev pointer of the new head is updated.
🧠 Conceptual
expert
1:30remaining
Time complexity of deleting from beginning in doubly linked list
What is the time complexity of deleting the first node from a doubly linked list and why?
AO(log n) because of pointer adjustments in a balanced list.
BO(n) because it requires traversing the entire list to update pointers.
CO(1) because deletion only updates head and pointers without traversal.
DO(n^2) because each pointer update is nested in loops.
Attempts:
2 left
💡 Hint
Deleting from the beginning does not require visiting all nodes.

Practice

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

Solution

  1. Step 1: Understand the head pointer role

    The head pointer always points to the first node in the 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 B
  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 without checking list length
  • 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 from a doubly linked list in JavaScript?
easy
A. head.prev = null; head = head.next;
B. head = null; head.next = null;
C. head.next = null; head = head.prev;
D. head = head.next; head.prev = null;

Solution

  1. Step 1: Move head to next node

    Assign head to head.next to remove the first node reference.
  2. Step 2: Update new head's prev pointer

    Set head.prev to null to disconnect backward link from old first node.
  3. Final Answer:

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

    Correct syntax updates head and prev pointer [OK]
Hint: Update head first, then set new head.prev to null [OK]
Common Mistakes:
  • Setting head.prev before moving head
  • Setting head.next to null incorrectly
  • Nullifying head before updating pointers
3. Consider the doubly linked list: 10 <-> 20 <-> 30 <-> null. After deleting the first node, what will be the new list?
medium
A. 30 <-> null
B. 10 <-> 30 <-> null
C. 20 <-> 30 <-> null
D. null

Solution

  1. Step 1: Identify the first node

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

    Head moves to 20, and 20.prev is set to null.
  3. Final Answer:

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

    First node removed, list starts at 20 [OK]
Hint: After deletion, list starts from second node [OK]
Common Mistakes:
  • Leaving old head in list
  • Not updating prev pointer of new head
  • Removing wrong node
4. Given this code snippet to delete the first node, what is the error?
if (head !== null) {
  head = head.next;
  head.prev = null;
}
medium
A. head.prev assignment causes error if list has one node
B. No error, code works fine
C. head.next should be assigned to null before head update
D. head should be set to null before updating prev

Solution

  1. Step 1: Check list with one node

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

    head is now null, so head.prev causes runtime error (cannot read property 'prev' of null).
  3. Final Answer:

    head.prev assignment causes error if list has one node -> Option A
  4. Quick Check:

    Null head causes error on prev access [OK]
Hint: Check if head is null before accessing head.prev [OK]
Common Mistakes:
  • Not handling single-node list case
  • Accessing properties of null head
  • Assuming list always has multiple nodes
5. You have a doubly linked list with nodes: 5 <-> 15 <-> 25 <-> 35 <-> null. Write a function to delete the first node and return the updated list head. What will be the list after deletion?
hard
A. 15 <-> 25 <-> 35 <-> null
B. 5 <-> 25 <-> 35 <-> null
C. 25 <-> 35 <-> null
D. null

Solution

  1. Step 1: Move head to next node

    Head moves from 5 to 15, the second node.
  2. Step 2: Set new head's prev to null

    Set 15.prev = null to disconnect from old first node.
  3. Step 3: Return updated head

    Return the new head pointing to 15.
  4. Final Answer:

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

    First node removed, list starts at 15 [OK]
Hint: Update head and set new head.prev to null [OK]
Common Mistakes:
  • Not updating prev pointer of new head
  • Returning old head instead of new head
  • Deleting wrong node or skipping nodes
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