Bird
Raised Fist0
DSA Javascriptprogramming~10 mins

Delete a Node from Circular Linked List in DSA Javascript - Interactive Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new node with given data.

DSA Javascript
class Node {
  constructor(data) {
    this.data = [1];
    this.next = null;
  }
}
Drag options to blanks, or click blank then click option'
Adata
Bnext
Chead
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' instead of 'data' for the node's data property.
Assigning null to data instead of the input parameter.
2fill in blank
medium

Complete the code to check if the list is empty before deletion.

DSA Javascript
function deleteNode(head, key) {
  if (head == [1]) {
    return null;
  }
  // rest of deletion logic
}
Drag options to blanks, or click blank then click option'
A0
Bnull
Cundefined
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Checking head against undefined instead of null.
Using 0 or false which are not valid for empty list check.
3fill in blank
hard

Fix the error in the loop condition to find the node before the one to delete.

DSA Javascript
let current = head;
do {
  if (current.next.data === key) {
    break;
  }
  current = current[1];
} while (current !== head);
Drag options to blanks, or click blank then click option'
A.prev
B.head
C.next
D.data
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which is not defined in singly circular linked list.
Using .data or .head which are not pointers to next node.
4fill in blank
hard

Fill both blanks to update the links when deleting the head node.

DSA Javascript
if (current.next === head) {
  head = head[1];
  current[2] = head;
}
Drag options to blanks, or click blank then click option'
A.next
B.prev
C.data
D.head
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which does not exist in singly linked list.
Using .data or .head which are not pointers.
5fill in blank
hard

Fill all three blanks to delete a node with given key from circular linked list.

DSA Javascript
function deleteNode(head, key) {
  if (head == null) return null;
  let current = head;
  let prev = null;
  do {
    if (current.data === [1]) {
      if (prev != null) {
        prev[2] = current[3];
      } else {
        // handle head deletion
      }
      break;
    }
    prev = current;
    current = current.next;
  } while (current !== head);
  return head;
}
Drag options to blanks, or click blank then click option'
Akey
Bnext
Cprev
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev.prev or current.prev which do not exist.
Using head or other variables incorrectly in link update.

Practice

(1/5)
1. What happens when you delete the head node from a circular linked list with multiple nodes?
easy
A. The head moves to the next node and the list remains circular
B. The list becomes empty immediately
C. The last node points to null breaking the circle
D. The list throws an error and stops

Solution

  1. Step 1: Understand the head deletion in circular list

    When the head node is deleted, the next node becomes the new head.
  2. Step 2: Maintain circular link

    The last node's next pointer is updated to point to the new head, keeping the list circular.
  3. Final Answer:

    The head moves to the next node and the list remains circular -> Option A
  4. Quick Check:

    Head deletion updates head and last node pointer [OK]
Hint: Head deletion shifts head and keeps circle intact [OK]
Common Mistakes:
  • Assuming list becomes empty after head deletion
  • Breaking the circular link by setting last node to null
  • Not updating the last node's next pointer
2. Which of the following is the correct syntax to delete a node with value `key` from a circular linked list in JavaScript?
easy
A. function deleteNode(head) { /* code */ }
B. function deleteNode(key, head) { /* code */ }
C. function deleteNode(head, key) { /* code */ }
D. function deleteNode() { /* code */ }

Solution

  1. Step 1: Identify function parameters for deletion

    The function needs the head of the list and the key value to delete the correct node.
  2. Step 2: Confirm correct parameter order

    The common and clear order is (head, key) to access the list and the target value.
  3. Final Answer:

    function deleteNode(head, key) { /* code */ } -> Option C
  4. Quick Check:

    Parameters: head and key in order [OK]
Hint: Function needs head and key parameters in order [OK]
Common Mistakes:
  • Swapping parameter order causing confusion
  • Missing key parameter to identify node
  • Using no parameters making deletion impossible
3. What will be the output after deleting node with value 3 from this circular linked list: 1 -> 3 -> 5 -> 7 -> (back to 1)?
<pre>function deleteNode(head, key) { if (!head) return null; let curr = head, prev = null; do { if (curr.data === key) { if (prev) prev.next = curr.next; else { let temp = head; while (temp.next !== head) temp = temp.next; head = curr.next; temp.next = head; } break; } prev = curr; curr = curr.next; } while (curr !== head); return head; } // After deletion, print list starting from head
medium
A. 1 -> 5 -> 7 -> (back to 1)
B. 3 -> 5 -> 7 -> (back to 3)
C. 1 -> 3 -> 5 -> 7 -> (back to 1)
D. 5 -> 7 -> 1 -> (back to 5)

Solution

  1. Step 1: Locate node with value 3

    The code loops through nodes and finds node with data 3.
  2. Step 2: Delete node 3 and update links

    Since node 3 is not head, prev.next skips node 3 and points to node 5, maintaining circular link.
  3. Final Answer:

    1 -> 5 -> 7 -> (back to 1) -> Option A
  4. Quick Check:

    Node 3 removed, list links updated [OK]
Hint: Skip deleted node by linking previous to next [OK]
Common Mistakes:
  • Not updating previous node's next pointer
  • Deleting head incorrectly when key is not head
  • Breaking circular link by missing last node update
4. Identify the bug in this code snippet for deleting a node from a circular linked list:
function deleteNode(head, key) {
  if (!head) return null;
  let curr = head;
  while (curr.next !== head) {
    if (curr.next.data === key) {
      curr.next = curr.next.next;
      return head;
    }
    curr = curr.next;
  }
  return head;
}
medium
A. Infinite loop due to missing break
B. Does not handle deletion when head node has the key
C. Deletes multiple nodes with the key instead of one
D. Returns null even if list is not empty

Solution

  1. Step 1: Analyze loop and deletion logic

    The loop checks curr.next for key but never checks head node itself.
  2. Step 2: Identify missing head deletion case

    If head node contains key, this code does not delete it, causing incorrect behavior.
  3. Final Answer:

    Does not handle deletion when head node has the key -> Option B
  4. Quick Check:

    Head node deletion missing in logic [OK]
Hint: Always check head node separately for deletion [OK]
Common Mistakes:
  • Ignoring head node deletion case
  • Assuming loop covers all nodes including head
  • Not updating head pointer when head is deleted
5. Given a circular linked list with nodes 10 -> 20 -> 30 -> 40 -> (back to 10), how would you delete the last node (40) and maintain the circular structure? Choose the correct approach.
hard
A. Swap last node data with head and delete head
B. Set head to null directly to delete last node
C. Change last node's next to null to break the circle
D. Traverse to node before last, set its next to head, and delete last node

Solution

  1. Step 1: Find node before last node

    Traverse list until node.next.next equals head, identifying node before last.
  2. Step 2: Update next pointer and delete last node

    Set node before last's next pointer to head, removing last node and keeping list circular.
  3. Final Answer:

    Traverse to node before last, set its next to head, and delete last node -> Option D
  4. Quick Check:

    Update second last node's next to head [OK]
Hint: Link second last node directly to head [OK]
Common Mistakes:
  • Breaking circle by setting next to null
  • Deleting head instead of last node
  • Not updating pointers causing broken list
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