CARVIEW |
Python Linked List Quiz
This Python quiz on Linked Lists will test your understanding of this fundamental data structure. The quiz will cover various operations such as insertion, deletion, traversal, and searching in a linked list. You will also explore different types of linked lists, including singly, doubly, and circular linked lists, along with their advantages and use cases in solving real-world problems.
Question 1
What is a linked list?
A collection of elements that can only be accessed sequentially.
A collection of nodes where each node contains data and a reference to the next node.
A collection of elements that are all of the same type.
A collection of elements stored in contiguous memory locations.
Question 2
What is the main difference between an array and a linked list?
An array supports dynamic insertion and deletion, while a linked list does not.
In an array, elements are stored in contiguous memory locations, while in a linked list, nodes can be scattered in memory.
An array allows dynamic memory allocation, while a linked list has fixed memory allocation.
An array is a linear data structure, while a linked list is non-linear.
Question 3
Which of the following is true about linked lists?
Linked lists can store elements of different data types.
Linked lists can only store elements of the same data type.
In a linked list, each node must contain only data, not references.
Linked lists are always faster than arrays for accessing elements.
Question 4
In a singly linked list, what does the last node’s next pointer point to?
A random node
The first node
A NULL value
The second node
Question 5
In a singly linked list, how do you insert a new node at the beginning?
Change the next pointer of the last node to the new node.
Add the new node at the end of the list.
Move the head pointer to the new node.
Create a new node and set its next pointer to head.
Question 6
What does it mean when we say a linked list is "doubly linked"?
It means the list can contain a maximum of two nodes.
It means each node has two pointers: one pointing to the next node and the other pointing to the previous node.
It means the list is circular.
It means the list can store two data items in each node.
Question 7
Which of the following is not a valid way to traverse a singly linked list?
Start from the head and follow the next pointers
Use recursion to traverse each node
Start from the tail and follow the prev pointers
Start from the head and use a while loop
Question 8
What is the output of the following python code?
head = Node(1)
head.next = Node(2)
head.next.next = Node(3)
current = head
while current.next and current.next.next:
current = current.next
current.next = None
The list becomes
1 -> 2 -> 3
.The list becomes
1 -> 2
.The list becomes
2 -> 3
.The list becomes
1
.
Question 9
What does the following function do for a given Linked List with first node as head?
def fun1(head):
if head is None:
return
fun1(head.next)
print(head.data, end=' ')
Prints all nodes of linked list in reverse order
Prints all nodes of linked list
Prints alternate nodes in reverse order
Prints alternate nodes of Linked List
Question 10
Consider the following function that takes reference to head of a Doubly Linked List as parameter. Assume that a node of doubly linked list has previous pointer as prev and next pointer as next.
def fun(head_ref):
temp = None
current = head_ref[0]
while current is not None:
temp = current.prev
current.prev = current.next
current.next = temp
current = current.prev
if temp is not None:
head_ref[0] = temp.prev
What action will be performed by the following code?
Set the value of head_ref to next;
Set the value of head_ref to NULL;
Set the value of head_ref to current;
Set the value of head_ref to prev;
There are 15 questions to complete.