Question 11
EasyIf a singly linked list also keeps a tail pointer, how fast is insertion at the end?
- 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
If a singly linked list also keeps a tail pointer, how fast is insertion at the end?
O(n²)
O(n)
O(log n)
O(1)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of deleting the head node of a linked list?
O(1)
O(n)
O(log n)
O(n²)
Sign up free to see the answer and a step-by-step explanation.
How many pointers does each node of a doubly linked list have?
0
2 (next and previous)
1
3
Sign up free to see the answer and a step-by-step explanation.
Which is a disadvantage of a linked list compared with an array?
No direct access to the k-th element
It can't store numbers
Inserting at the front is slow
Its size is fixed
Sign up free to see the answer and a step-by-step explanation.
What is a sentinel (dummy) node in a linked list?
A corrupted node
The last real node
A node holding the largest value
An extra node placed at the start so that empty-list and head cases need no special code
Sign up free to see the answer and a step-by-step explanation.
How many pointer variables does the usual iterative reversal of a singly linked list use?
Four
Three: previous, current and next
One
Two
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of reversing a singly linked list?
O(n)
O(1)
O(n²)
O(log n)
Sign up free to see the answer and a step-by-step explanation.
In a circular singly linked list, what does the last node point to?
The middle node
Itself
The first node
NULL
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class Node:
def __init__(self, v, nxt=None):
self.v, self.nxt = v, nxt
h = Node(1, Node(2, Node(3)))
s = 0
while h:
s += h.v
h = h.nxt
print(s)
1
Error
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class Node:
def __init__(self, v, nxt=None):
self.v, self.nxt = v, nxt
prev, cur = None, Node(1, Node(2, Node(3)))
while cur:
nxt = cur.nxt
cur.nxt = prev
prev, cur = cur, nxt
out = []
while prev:
out.append(prev.v)
prev = prev.nxt
print(out)
[3]
[3, 2, 1]
Sign up free to see the answer and a step-by-step explanation.
3
6
[1, 2, 3]
[]