Data Structures & AlgorithmsHardProduct-company MCQ pattern
slow and fast both start at the head of 1 → 2 → 3 → 4 → 5 → 6. Loop A: while (fast && fast->next) { slow = slow->next; fast = fast->next->next; }. Loop B: the same but with condition (fast->next && fast->next->next). Where does slow stop in each case?
- A. A: 4, B: 4
- B. A: 4, B: 3
- C. A: 3, B: 3
- D. A: 3, B: 4
Correct answer: B. A: 4, B: 3
In A, fast goes 1 → 3 → 5 → past the end (null) while slow goes 1 → 2 → 3 → 4, the second middle. In B the loop stops when fast is at 5 (5.next.next is null), leaving slow at 3, the first middle. The difference matters for split-in-half algorithms.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the maximum number of comparisons top-down merge sort can make on 8 elements (any input order)?
- What is the minimum number of comparisons needed, in the worst case, to find BOTH the maximum and the minimum of 100 distinct numbers?
- One Lomuto partition (pivot = last element, i marks the end of the 'smaller' part, swap when a[j] < pivot) is applied to [7, 2, 9, 4, 3…
- Insertion sort (ascending) is applied to [5, 2, 4, 6, 1, 3]. What does the array look like after the first 3 passes (i.e. after inserting…
- Among insertion sort, merge sort, heap sort, quick sort, bubble sort and selection sort (standard array versions), how many are BOTH…
- LSD radix sort (base 10, stable counting sort per digit) is applied to [170, 45, 75, 90, 802, 24, 2, 66]. What is the array after the…