Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given data.
DSA Java
Node newNode = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' instead of 'data' when creating the new node.
Passing 'null' or 'next' which are not the data values.
✗ Incorrect
We create a new node by passing the data value to the Node constructor.
2fill in blank
mediumComplete the code to check if the list is empty.
DSA Java
if ([1] == null) {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking newNode instead of head.
Checking tail or next which may not be null even if list is empty.
✗ Incorrect
The list is empty if the head pointer is null.
3fill in blank
hardFix the error in updating the tail's next pointer to the new node.
DSA Java
tail.[1] = newNode;Attempts:
3 left
💡 Hint
Common Mistakes
Using tail.prev which does not exist in singly circular list.
Assigning to tail.data or tail.head which are incorrect.
✗ Incorrect
In a circular linked list, tail's next pointer should point to the new node.
4fill in blank
hardFill both blanks to update the new node's next pointer and the head pointer.
DSA Java
newNode.[1] = head; head = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of assignment.
Setting head to old head instead of newNode.
✗ Incorrect
The new node's next points to the old head, then head is updated to newNode.
5fill in blank
hardFill all three blanks to complete the insert at beginning method for circular linked list.
DSA Java
public void insertAtBeginning(int data) {
Node newNode = new Node([1]);
if (head == null) {
head = newNode;
tail = newNode;
newNode.[2] = head;
} else {
newNode.next = head;
tail.[3] = newNode;
head = newNode;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' for pointers.
Not updating tail.next in else block.
Not setting newNode.next to head when list is empty.
✗ Incorrect
Create new node with data; if empty, point newNode.next to head; else update tail.next to newNode.
