Linked List Flashcards

(40 cards)

1
Q

What does the following Java code snippet accomplish?

SLLNode snode = new SLLNode(“Cris”);
System.out.println(snode);

(Assuming toString() is not overridden in the SLLNode class.)

A. It throws a runtime error
B. It prints “Cris”
C. It prints the node’s info field
D. It prints the default object reference

A

D. It prints the default object reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What value does next hold in the last node of a singly linked list?

A. Zero
B. Previous node
C. Null
D. Head

A

C. Null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is insertion at the head more efficient than insertion at the tail in a singly linked list?

A. It uses less memory
B. It requires no traversal
C. It avoids pointer updates
D. It automatically sorts the list

A

B. It requires no traversal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which operation inserts a new node at the beginning of a singly linked list?

A. pushBack()
B. insertAtHead()
C. insertAtTail()
D. append()

A

B. insertAtHead()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the next pointer in a singly linked list node refer to?

A. The previous node
B. The head node
C. The tail node
D. The next node in the list

A

D. The next node in the list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which traversal method is used to visit all nodes in a singly linked list?

A. while (current != null)
B. do-while (current != head)
C. while (current.prev != null)
D. for (int i = 0; i < size; i++)

A

A. while (current != null)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In a singly linked list, how is traversal typically performed?

A. Using array indices
B. By jumping to tail
C. By following next pointers
D. Using backward pointers

A

D. Using backward pointers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which pointer is updated when inserting at the head of a singly linked list?

A. head.prev
B. head.next
C. tail
D. newNode.next

A

D. newNode.next

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the default value of the head pointer in a newly created singly linked list?

A. null
B. -1
C. head.next
D. 0

A

A. null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which operation deallocates a singly linked list node?

A. remove()
B. new()
C. null()
D. delete()

A

D. delete()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the time complexity of inserting a node at the head of a singly linked list?

A. O(1)
B. O(n)
C. O(log n)
D. O(n²)

A

A. O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the diagram [Pedro] → [Hudas] → null represent?

A. A singly linked list
B. A stack
C. A circular list
D. A doubly linked list

A

A. A singly linked list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Consider the sequence:
SLLNode snode2 = new SLLNode(“Hudas”);
SLLNode snode1 = new SLLNode(“Pedro”, snode2);
snode1.next = null;
delete(snode2);

What is the effect of delete(snode2)?

A. It removes the head node from the list
B. It deletes the entire list
C. It sets snode2 to null
D. It deallocates the node containing “Hudas” from memory

A

D. It deallocates the node containing “Hudas” from memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which operation allocates a new singly linked list node?

A. delete()
B. new()
C. null()
D. toString()

A

B. new()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does toString() return when called on a node?

A. A string describing the node’s info
B. The memory address
C. The pointer value
D. The next node

A

A. A string describing the node’s info

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What happens when you delete the head node in a singly linked list?

A. The list is reversed
B. The head pointer is moved to the next node
C. The head remains unchanged
D. The tail becomes null

A

B. The head pointer is moved to the next node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the result of toString(snode1) if snode1 contains “Pedro”?

A. Pedro → Hudas
B. null
C. “Pedro”
D. “Hudas”

A

C. “Pedro”

18
Q

Which operation removes the first node of a singly linked list?

A. deleteFromHead()
B. pop()
C. clear()
D. dequeue()

A

A. deleteFromHead()

19
Q

What happens when snode1.next = null is executed?

A. The node becomes the tail
B. The list is reversed
C. The node is deleted
D. The link to the next node is broken

A

D. The link to the next node is broken

20
Q

What condition indicates that a singly linked list is empty?

A. size == 0
B. head == tail
C. head == null
D. head.next == null

A

C. head == null

21
Q

Which pointer must be updated when inserting a node between two existing nodes in a DLL?

A. Only the new node’s prev pointer
B. No pointers need to be updated
C. Only the new node’s next pointer
D. Both the new node’s next and prev pointers, and the adjacent nodes’ pointers

A

D. Both the new node’s next and prev pointers, and the adjacent nodes’ pointers

22
Q

Which traversal method is unique to doubly linked lists?

A. Backward traversal
B. Recursive traversal
C. Circular traversal
D. Forward traversal

A

A. Backward traversal

23
Q

What happens if prev is not updated during insertion?

A. The node is deleted
B. The node is skipped during traversal
C. The list becomes singly linked
D. The list becomes circular

A

B. The node is skipped during traversal

24
Q

What does a doubly linked list node contain?

A. Data and index
B. Data and two pointers
C. Data and one pointer
D. Only data

A

B. Data and two pointers

25
Which condition correctly identifies an empty doubly linked list? A. head == null and tail == null B. head != null and tail != null C. head != null and tail == null D. head == null and tail != null
A. head == null and tail == null
26
What does the diagram null ← A ↔ B ↔ C → null represent? A. Singly linked list B. Array C. Doubly linked list D. Circular list
C. Doubly linked list
27
What is the result of traversing a DLL from tail to head? A. Reverse order B. Random access C. No output D. Sorted order
A. Reverse order
28
How many pointer fields does each node in a DLL typically contain? A. One B. None C. Three D. Two
D. Two
29
What is the advantage of DLL over SLL? A. Less memory usage B. Simpler implementation C. Faster memory allocation D. Bidirectional traversal
D. Bidirectional traversal
30
What happens if you forget to update the prev pointer during deletion in a DLL? A. The head pointer is lost B. The deleted node remains accessible C. The list becomes circular D. Backward traversal breaks
D. Backward traversal breaks
31
Which of the following is true about the tail node in a DLL? A. Its prev pointer points to the previous node B. It cannot be deleted C. It always has a non-null next pointer D. It is inaccessible from the head
B. It cannot be deleted
32
What value does prev hold in the head node of a DLL? A. Null B. Tail C. Zero D. Head
A. Null
33
What does the prev pointer in a DLL refer to? A. Null B. The previous node C. The head D. The next node
B. The previous node
34
Which pointer allows backward traversal in DLL? A. prev B. tail C. next D. head
A. prev
35
What is the result of inserting a node at the tail of an empty DLL? A. The node is discarded B. Only head is updated C. Both head and tail point to the new node D. Only tail is updated
C. Both head and tail point to the new node
36
Which operation is typically more efficient in a DLL than in a singly linked list? A. Insertion at the head B. Deletion of a node when its pointer is given C. Searching for a value D. Traversal from head to tail
B. Deletion of a node when its pointer is given
37
What is the correct sequence of pointer updates when deleting a middle node in a DLL? A. Set prev.next to node.next and next.prev to node.prev B. No updates are needed C. Set node.prev to null and node.next to null D. Update head and tail only
A. Set prev.next to node.next and next.prev to node.prev
38
What is the primary advantage of a doubly linked list over a singly linked list? A. It allows traversal in both directions B. It is faster for all operations C. It does not require pointers D. It uses less memory
A. It allows traversal in both directions
39
Which operation is easier in DLL than SLL? A. Deletion at tail B. Deletion of a middle node C. Insertion at head D. Traversal
B. Deletion of a middle node
40
Which node in DLL has both prev and next as null? A. Middle B. Only node C. Head D. Tail
B. Only node