Docsity

Linked Lists Structures Operations and Types in Data Structures Ultimate Exam, Exams of Technology

Toggle sidebar
bg1
Linked Lists Structures Operations and Types
in Data Structures Ultimate Exam
**Question 1.** Which statement correctly describes the memory allocation
strategy of a singly linked list compared with a static array?
A) Both allocate memory contiguously.
B) Both allocate memory non-contiguously.
C) The array allocates contiguously, while the linked list allocates nodes
non-contiguously.
D) The linked list allocates contiguously, while the array allocates non-contiguously.
Answer: C
Explanation: An array reserves a single contiguous block of memory. Each node of a
linked list is allocated independently, often via `malloc`/`new`, resulting in a
non-contiguous layout.
**Question 2.** In a typical node definition for a singly linked list, which fields are
mandatory?
A) Data and a next pointer.
B) Data, next pointer, and previous pointer.
C) Only a next pointer.
D) Only a data field.
Answer: A
Explanation: A singly linked list node must store the payload (data) and a reference
to the next node; a previous pointer is only needed for doubly linked lists.
**Question 3.** What does the `NULL` (or `None`) pointer signify in a linked list
implementation?
A) The list is empty.
B) The node is the head.
C) The end of the list (no further nodes).
D) The node contains no data.
Answer: C
Explanation: `NULL` marks the termination of a chain; the last node’s next
reference points to `NULL`, indicating there is no successor.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31

Partial preview of the text

Download Linked Lists Structures Operations and Types in Data Structures Ultimate Exam and more Exams Technology in PDF only on Docsity!

in Data Structures Ultimate Exam

Question 1. Which statement correctly describes the memory allocation strategy of a singly linked list compared with a static array? A) Both allocate memory contiguously. B) Both allocate memory non-contiguously. C) The array allocates contiguously, while the linked list allocates nodes non-contiguously. D) The linked list allocates contiguously, while the array allocates non-contiguously. Answer: C Explanation: An array reserves a single contiguous block of memory. Each node of a linked list is allocated independently, often via malloc/new, resulting in a non-contiguous layout. Question 2. In a typical node definition for a singly linked list, which fields are mandatory? A) Data and a next pointer. B) Data, next pointer, and previous pointer. C) Only a next pointer. D) Only a data field. Answer: A Explanation: A singly linked list node must store the payload (data) and a reference to the next node; a previous pointer is only needed for doubly linked lists. Question 3. What does the NULL (or None) pointer signify in a linked list implementation? A) The list is empty. B) The node is the head. C) The end of the list (no further nodes). D) The node contains no data. Answer: C Explanation: NULL marks the termination of a chain; the last node’s next reference points to NULL, indicating there is no successor.

in Data Structures Ultimate Exam

Question 4. Which Big-O time complexity correctly describes searching for a value in an unsorted singly linked list of n elements? A) O(1) B) O(log n) C) O(n) D) O(n log n) Answer: C Explanation: Without ordering, the only way to locate a value is to examine each node sequentially, leading to linear time. Question 5. In contrast, what is the time complexity of accessing the i-th element in a dynamic array (vector) of size n? A) O(1) B) O(log n) C) O(n) D) O(n²) Answer: A Explanation: Dynamic arrays support random access; the element at index i can be retrieved directly via pointer arithmetic. Question 6. Which operation on a singly linked list has the best (lowest) worst-case time complexity? A) Insert at the head. B) Insert at the tail without a tail pointer. C) Delete a node with a given key. D) Search for a value. Answer: A Explanation: Inserting at the head only requires updating the new node’s next pointer and the head reference, both O(1). Question 7. When inserting a new node at the end of a singly linked list that maintains a tail pointer, the operation runs in:

in Data Structures Ultimate Exam

C) Use two pointers moving from both ends. D) Reverse by appending each node to a new list. Answer: A Explanation: The classic recursive reversal processes the sub-list, then makes the original next node point back to the current node, finally setting its next to NULL. Question 11. Floyd’s Cycle-Finding algorithm (Tortoise and Hare) uses two pointers moving at different speeds. What is the time complexity for detecting a cycle in a list of n nodes? A) O(1) B) O(log n) C) O(n) D) O(n²) Answer: C Explanation: Both pointers traverse at most 2 n steps before meeting, yielding linear time. Question 12. Which condition guarantees that a singly linked list does not contain a cycle? A) The fast pointer reaches NULL. B) The slow pointer reaches NULL. C) The fast pointer equals the slow pointer. D) The list length is a prime number. Answer: A Explanation: If the fast pointer (advancing two steps) encounters NULL, there is no way for a loop to exist. Question 13. To find the middle element of a singly linked list in a single pass, which technique is used? A) Two-pointer technique with one moving twice as fast. B) Binary search on indices. C) Maintaining a stack of visited nodes.

in Data Structures Ultimate Exam

D) Sorting the list first. Answer: A Explanation: The “slow” pointer moves one step while the “fast” pointer moves two; when fast reaches the end, slow points to the middle. Question 14. Merging two sorted singly linked lists of sizes m and n using a linear algorithm yields a time complexity of: A) O(m + n) B) O(m × n) C) O(max(m, n) log min(m, n)) D) O(1) Answer: A Explanation: Each node is examined once; the algorithm runs in linear time relative to the total number of elements. Question 15. Which of the following statements about doubly linked lists (DLL) is true? A) Each node stores only a next pointer. B) Deleting a node given its reference is always O(1). C) Traversal can only be performed forward. D) They use less memory than singly linked lists. Answer: B Explanation: Because a DLL node contains both next and prev, once you have a pointer to the target node you can adjust its neighbors without traversal, achieving O(1) deletion. Question 16. In a doubly linked list, what extra pointer does the tail node contain compared to a singly linked list’s tail? A) A pointer to the head. B) A pointer to the previous node. C) A pointer to a dummy node. D) No extra pointer; they are identical.

in Data Structures Ultimate Exam

Explanation: In a circular singly linked list, the last node links to the first, forming a closed loop. Question 20. In a circular doubly linked list, which two pointers are used to identify the “start” of the list? A) Only the head pointer. B) Head and tail pointers, both pointing to the same node. C) Head and tail pointers, each pointing to distinct nodes. D) No pointers are required; the list is self-referencing. Answer: C Explanation: Typically both head and tail are kept for convenient access; they reference distinct nodes, while the tail’s next points to head and head’s prev points to tail. Question 21. Which problem is most naturally solved using a circular linked list? A) Implementing a stack. B) Round-robin scheduling. C) Binary search. D) Maintaining a sorted order. Answer: B Explanation: Circular lists allow continuous iteration without resetting, matching the cyclic nature of round-robin algorithms. Question 22. When traversing a circular singly linked list, how can you reliably detect that you have completed one full loop? A) Stop when a node’s next is NULL. B) Stop when the current node equals the head again. C) Stop after n steps, where n is unknown. D) Use a sentinel node with a special flag. Answer: B Explanation: Since the list has no NULL terminator, returning to the starting node indicates completion.

in Data Structures Ultimate Exam

Question 23. Splitting a circular singly linked list into two equal halves (when the number of nodes is even) can be done in O(n) time using which approach? A) Two-pointer technique (slow/fast) to locate the middle, then adjust pointers. B) Sorting the list first. C) Using a stack to reverse the list. D) Recursively deleting every other node. Answer: A Explanation: The slow/fast pointer finds the midpoint; then the next pointers of the middle and tail are rewired to form two circular lists. Question 24. A “header” (or sentinel) node in a linked list is primarily used to: A) Store the list’s size. B) Simplify insertion and deletion at the boundaries. C) Hold a pointer to the tail. D) Replace the head pointer entirely. Answer: B Explanation: A dummy node provides a non-null predecessor for the first real element, eliminating special-case code for head operations. Question 25. In a multi-level linked list, a node may contain: A) Only a data field. B) Pointers to nodes on the same level and a pointer to a sub-list. C) A pointer to the previous node only. D) No pointers at all. Answer: B Explanation: Multi-level lists (e.g., flattening a list of lists) have “child” pointers that reference independent sub-lists. Question 26. Skip lists achieve O(log n) average search time by:

in Data Structures Ultimate Exam

B) free C) delete D) smart pointer (e.g., std::unique_ptr) Answer: D Explanation: Smart pointers manage lifetime automatically, invoking delete when the owning object is destroyed. Question 30. In Java, why are explicit free calls unnecessary for linked list nodes? A) Java does not support pointers. B) The garbage collector automatically reclaims unreachable objects. C. Memory is never reclaimed in Java. D) Nodes are stored on the stack. Answer: B Explanation: Java’s runtime performs automatic memory management, reclaiming objects that are no longer reachable. Question 31. A “dangling pointer” in a linked list context occurs when: A) A pointer references NULL. B) A pointer references memory that has already been freed. C) A pointer points to the head node. D) A pointer is declared but never initialized. Answer: B Explanation: After freeing a node, any remaining references to that memory become dangling and can cause undefined behavior if dereferenced. Question 32. Which of the following bugs is most likely to cause a segmentation fault during list traversal? A) Forgetting to update the head pointer after insertion. B) Dereferencing a NULL next pointer. C) Using a dummy node.

in Data Structures Ultimate Exam

D) Storing data as an integer. Answer: B Explanation: Accessing memory through a NULL pointer triggers a segmentation fault. Question 33. Losing the head pointer of a linked list typically results in: A) Memory leak of all nodes. B) Faster traversal. C) Automatic garbage collection. D) No effect on the list. Answer: A Explanation: Without a reference to the first node, the entire list becomes unreachable, preventing deallocation and leaking memory. Question 34. Which data structure is most naturally implemented using a singly linked list? A) Stack (LIFO). B) Queue (FIFO) with constant-time enqueue. C) Random-access array. D) Binary heap. Answer: A Explanation: A stack can push and pop at the head in O(1) time, matching the capabilities of a singly linked list. Question 35. Implementing a queue with a singly linked list requires maintaining both head and tail pointers. This allows enqueue and dequeue to run in: A) O(1) for both operations. B) O(n) for enqueue, O(1) for dequeue. C) O(1) for enqueue, O(n) for dequeue. D) O(n) for both. Answer: A

in Data Structures Ultimate Exam

Question 39. Which of the following is true about the space overhead of a doubly linked list compared to a singly linked list? A) Doubly linked list uses the same amount of memory per node. B) Doubly linked list uses less memory per node. C) Doubly linked list uses one extra pointer per node, increasing memory usage. D) Memory usage depends on the data size only. Answer: C Explanation: Each DLL node stores both next and prev, adding an extra pointer field. Question 40. Which operation on a circular linked list can cause an infinite loop if not handled correctly? A) Inserting at the head. B) Deleting the tail without updating the tail pointer. C) Traversing the list with a while (curr != NULL) condition. D) Searching for a key. Answer: C Explanation: Because there is no NULL terminator, a loop that checks for NULL never ends; the condition should check for returning to the start node. Question 41. In a singly linked list, what is the time complexity of finding the predecessor of a node when only a pointer to the target node is given? A) O(1) B) O(log n) C) O(n) D) O(n log n) Answer: C Explanation: Without a backward link, you must scan from the head until you locate the node whose next points to the target. Question 42. Which of the following best describes the purpose of a “sentinel” node in a linked list?

in Data Structures Ultimate Exam

A) To store the list’s length. B) To act as a universal dummy head that simplifies edge-case code. C) To replace the tail pointer. D) To hold the maximum element. Answer: B Explanation: A sentinel (dummy) node sits before the first real element, allowing uniform insertion/deletion logic without checking for NULL head. Question 43. When using a skip list, what is the expected number of levels for a node if the probability p = 0.5? A) 1 B) 2 C) O(log n) D) O(n) Answer: C Explanation: The height of a node follows a geometric distribution; the maximum level across the list is Θ(log n) with high probability. Question 44. Which of the following statements about recursive traversal of a singly linked list is correct? A) It uses O(1) auxiliary space. B) It can cause stack overflow for very long lists. C) It is always faster than iterative traversal. D. It does not require a base case. Answer: B Explanation: Each recursive call adds a stack frame; for large n this may exceed the call stack limit. Question 45. In a doubly linked list, what is the effect of swapping the next and prev pointers of every node and then swapping the head and tail pointers? A) The list becomes corrupted.

in Data Structures Ultimate Exam

C) Its next pointer is read-only. D) Its head pointer is immutable. Answer: A Explanation: Without backward links, the only way to locate a predecessor is to walk the list from the beginning. Question 49. When implementing a stack with a singly linked list, which pointer must be updated on each push operation? A) Tail pointer. B) Head pointer. C) Both head and tail. D) No pointer; only data changes. Answer: B Explanation: Pushing inserts a new node at the front, making it the new head. Question 50. Which of the following is a typical advantage of using a circular linked list for implementing a fixed-size buffer? A) Automatic resizing. B) No need for a length counter to detect full/empty states. C) Constant-time random access. D) Ability to store duplicate elements. Answer: B Explanation: The circular nature allows the head and tail to wrap around; the buffer can detect full/empty by comparing pointers. Question 51. In a multi-level linked list, the “child” pointer of a node typically points to: A) The next node on the same level. B) The previous node on the same level. C) The head of a sub-list representing a lower level. D) A random node elsewhere in the structure.

in Data Structures Ultimate Exam

Answer: C Explanation: The child pointer creates a hierarchy by linking to another list that may itself have further children. Question 52. Which of the following is a correct statement about the average-case time complexity of searching in a skip list? A) O(1) B) O(log n) C) O(n) D) O(n log n) Answer: B Explanation: Skip lists are designed so that, on average, a search descends through logarithmically many levels. Question 53. Which of the following pointer updates is required when deleting the tail node of a singly linked list that does not maintain a tail pointer? A) Only set head to NULL. B) Update the next of the second-last node to NULL. C) Swap head and tail pointers. D) No update is needed; the tail is automatically removed. Answer: B Explanation: To remove the last node, you must locate its predecessor and set its next to NULL, making it the new tail. Question 54. In a doubly linked list, what is the effect of setting node->prev = node->next = NULL before freeing node? A) It prevents memory leaks. B) It eliminates dangling pointers from neighboring nodes. C) It has no effect on safety. D) It causes a segmentation fault. Answer: B

in Data Structures Ultimate Exam

Question 58. In a singly linked list, what is the worst-case number of pointer assignments required to insert a node after a given node p? A) 1 B) 2 C) 3 D) 4 Answer: B Explanation: Set newNode->next = p->next; p->next = newNode; – two assignments. Question 59. Which of the following correctly describes the memory overhead of a header (dummy) node in a singly linked list? A) Zero overhead, because it replaces the head. B) One extra data field. C) One extra pointer field (the dummy’s next). D) Two extra pointer fields. Answer: C Explanation: The dummy node stores a next pointer (and possibly a data field, but the overhead relative to the list structure is the extra node itself). Question 60. In a skip list, increasing the probability p (the chance of promoting a node to a higher level) will: A) Decrease the average search time but increase memory usage. B) Increase both search time and memory usage. C) Decrease memory usage but increase search time. D. Have no effect on performance. Answer: A Explanation: Higher p creates taller towers, reducing hops during search, but each node stores more forward pointers, raising memory consumption.

in Data Structures Ultimate Exam

Question 61. Which of the following is a correct invariant for a well-formed doubly linked list? A) For every node, node->next->prev == node. B) For every node, node->prev->next == NULL. C) The head’s prev points to the tail. D) The tail’s next points to NULL only in circular lists. Answer: A Explanation: In a proper DLL, each forward link’s prev must refer back to the originating node. Question 62. When implementing a queue with a circular singly linked list and only a tail pointer, which node represents the front of the queue? A) The node after the tail (i.e., tail->next). B) The tail itself. C) The head pointer (which does not exist). D) The node with data = 0. Answer: A Explanation: In a circular list, tail->next is the head of the logical sequence, serving as the dequeue point. Question 63. Which operation on a singly linked list can be performed in O(1) time only if you have a pointer to the node before the target? A) Deleting the target node. B) Searching for a value. C) Reversing the list. D) Finding the middle element. Answer: A Explanation: With the predecessor, you can bypass the target node by adjusting its next pointer, achieving constant time deletion. Question 64. In a doubly linked list, what is the effect of forgetting to update the prev pointer of the node that follows a deleted node?