Consider the following algorithm to insert an element in a triply linked list.
insertelement(data)
{
create a node with given data.
if the linked list is empty
{
_____________
_____________
}
if the given node is less than the head
{
link the nodes through address and adjust the tail
}
if the given node is not less than the head
{
if the given node is equal to the head
{
new node is inserted on top of the head
}
else
{
traverse the linked list to find an element greater than the node and insert in front of the node
}
}
}
Which of the following option is best suited to fill the blank?
insertelement(data)
{
create a node with given data.
if the linked list is empty
{
_____________
_____________
}
if the given node is less than the head
{
link the nodes through address and adjust the tail
}
if the given node is not less than the head
{
if the given node is equal to the head
{
new node is inserted on top of the head
}
else
{
traverse the linked list to find an element greater than the node and insert in front of the node
}
}
}A.
initializing previous, next and top pointers to null
pointing the head and tail to the node createdB.
pointing previous, next and top pointers to the node created
initializing the head and tail to nullC.
initializing previous, next and top pointers to null
initializing the head and tail to nullD.
pointing previous, next and top pointers to the nodeAnswer: Option A
Related Questions on Linked Lists in Data Structures
What is the time complexity of inserting an element at the beginning of a linked list?
A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Which of the following is a disadvantage of linked lists compared to arrays?
A. Dynamic size
B. Random access
C. Ease of insertion and deletion
D. Memory overhead
What is a circular linked list?
A. A list where each node points to the next
B. A list where the last node points to the first node
C. A list where each node points to itself
D. A list where the nodes are in a circle
Which of the following is true about a doubly linked list?
A. Each node has one pointer
B. Each node has two pointers
C. It is a type of tree
D. It can be traversed in one direction only

Join The Discussion