Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a node class for the circular singly linked list.
DSA Python
class Node: def __init__(self, data): self.data = data self.[1] = None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is for doubly linked lists.
Using 'pointer' or 'link' which are not standard attribute names.
✗ Incorrect
The 'next' attribute points to the next node in the circular singly linked list.
2fill in blank
mediumComplete the code to initialize the circular singly linked list with a head node.
DSA Python
class CircularSinglyLinkedList: def __init__(self): self.head = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing head with a Node when the list is empty.
Using 0 or self which are incorrect.
✗ Incorrect
The head is initially None because the list is empty.
3fill in blank
hardFix the error in the insert method to correctly insert the first node in the circular singly linked list.
DSA Python
def insert(self, data): new_node = Node(data) if self.head is None: self.head = new_node new_node.[1] = new_node else: # code to insert when list is not empty pass
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is not used in singly linked lists.
Not linking the node to itself causing a broken circle.
✗ Incorrect
For a single node in a circular singly linked list, its next points to itself.
4fill in blank
hardFill both blanks to complete the code that inserts a new node at the end of the circular singly linked list.
DSA Python
def insert(self, data): new_node = Node(data) if self.head is None: self.head = new_node new_node.next = new_node else: temp = self.head while temp.[1] != self.head: temp = temp.[2] temp.next = new_node new_node.next = self.head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which does not exist in singly linked lists.
Using different attributes for traversal causing errors.
✗ Incorrect
To traverse the circular list, use the 'next' attribute to move to the next node.
5fill in blank
hardFill all three blanks to complete the method that prints all nodes in the circular singly linked list.
DSA Python
def print_list(self): if self.head is None: print('List is empty') return temp = self.head while True: print(temp.[1], end=' -> ') temp = temp.[2] if temp == [3]: break print('None')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the node object instead of its data.
Using 'head' instead of 'self.head' causing NameError.
Not stopping the loop causing infinite print.
✗ Incorrect
Print the data of each node, move to the next node, and stop when back at the head.