Question 41
MediumWhat is the time complexity of deleting the last node of a singly linked list with only a head pointer?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the time complexity of deleting the last node of a singly linked list with only a head pointer?
O(n)
O(log n)
O(1)
O(n²)
Sign up free to see the answer and a step-by-step explanation.
Why is a doubly linked list better than a singly linked list for deleting a node given only a pointer to it?
It uses less memory
It is always sorted
The node's prev pointer gives its predecessor directly, so deletion is O(1)
It needs no head
Sign up free to see the answer and a step-by-step explanation.
What is a disadvantage of linked lists compared with arrays?
They can't store integers
No O(1) random access by index, and poorer cache locality
They have a fixed size
Insertion at the head is slow
Sign up free to see the answer and a step-by-step explanation.
In a circular singly linked list with a pointer to the last node, how fast is inserting at the front?
Impossible
O(n)
O(1)
O(log n)
Sign up free to see the answer and a step-by-step explanation.
What does a sentinel (dummy) head node simplify?
Insertions and deletions at the front, removing special cases for an empty list
Sorting
Searching
Memory use
Sign up free to see the answer and a step-by-step explanation.
How much extra memory does each node of a doubly linked list need compared with a singly linked list?
A full copy of the data
One extra pointer
Two extra pointers
Nothing
Sign up free to see the answer and a step-by-step explanation.
How can a cycle in a linked list be detected using O(n) extra space?
Sort the list
Count nodes
Store visited nodes in a hash set and check each new node
Reverse the list
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of finding the k-th node from the end with two pointers?
O(k)
O(n²)
O(n) in one pass
O(log n)
Sign up free to see the answer and a step-by-step explanation.
Adding two numbers stored as reversed linked lists (2→4→3 is 342) and (5→6→4 is 465) gives which list?
8→0→8
7→1→8
8→0→7
7→0→8
Sign up free to see the answer and a step-by-step explanation.
Which operation does a linked list do better than an array?
Inserting in the middle once the position (node) is known
Using the CPU cache
Accessing the 1,000th element
Binary search
Sign up free to see the answer and a step-by-step explanation.