Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Java
Node newNode = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'null' instead of the value.
Using 'head' or 'tail' instead of the value.
✗ Incorrect
We create a new node by passing the value to the Node constructor.
2fill in blank
mediumComplete the code to check if the queue is empty.
DSA Java
if (tail == [1]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing tail to head instead of null.
Comparing tail to newNode or value.
✗ Incorrect
The queue is empty if tail is null.
3fill in blank
hardFix the error in linking the new node at the end of the queue.
DSA Java
tail.[1] = newNode;Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' or 'prev' instead of 'next'.
Trying to assign to 'value' which is not a pointer.
✗ Incorrect
We link the new node by setting tail.next to newNode.
4fill in blank
hardFill both blanks to update the tail pointer after enqueue.
DSA Java
tail = [1]; if (head == [2]) { head = tail; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting tail to head instead of newNode.
Checking if head equals tail instead of null.
✗ Incorrect
After adding newNode, tail points to it. If head is null, set head to tail.
5fill in blank
hardFill all three blanks to complete the enqueue method using linked list.
DSA Java
public void enqueue(int value) {
Node newNode = new Node([1]);
if (tail == [2]) {
head = newNode;
tail = newNode;
} else {
tail.[3] = newNode;
tail = newNode;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for newNode creation.
Checking head instead of tail for emptiness.
Assigning to tail.value instead of tail.next.
✗ Incorrect
Create newNode with value, check if tail is null, link newNode at tail.next, update tail.
