JavaScript Linked List (original) (raw)
Which of the following statements is correct about a singly linked list?
- A singly linked list is a linear data structure with elements pointing to the next node.
- A singly linked list stores elements in an array.
- In a singly linked list, each node contains a reference to the previous node.
- A singly linked list supports backward traversal without additional memory.
In JavaScript, which of the following is the correct way to define a node for a singly linked list?
- {data: 10, prevNode: null}
- {nodeValue: 10, nextNode: null}
- {value: 10, prevNode: null}
- {value: 10, nextNode: null}
Which method is used to traverse a singly linked list?
- while loop (traversing by moving from node to node)
What happens if we try to access a node beyond the last node in a singly linked list?
- It will return null or undefined.
- It will result in an infinite loop.
In a linked list, what is the time complexity for inserting a new node at the beginning?
Which of the following methods can be used to remove the last node in a singly linked list?
- Traverse through the list and set the second-last node’s next pointer to null
In a doubly linked list, each node contains:
- Data and reference to the next node only.
- Data and reference to both the next and previous node.
- Data, next node, and reference to the previous node, but in a single direction.
How can you reverse a singly linked list?
- By swapping the data of the nodes.
- By deleting all nodes and creating a new list in reverse order.
- By reversing the next pointers of the nodes.
- By converting the linked list to an array and then reversing it.
Which of the following is the correct way to check if a linked list has a loop?
- Check if the last node points to null.
- Traverse through the list and check if the node’s next points back to a previous node.
- Check if the nodes contain references to themselves.
- There is no way to check for a loop.
What is the space complexity for storing a singly linked list with n nodes?
There are 10 questions to complete.
Take a part in the ongoing discussion