Data Structures & AlgorithmsModerateGATE CS · DSA
In a singly linked list with only a head pointer, which operation CANNOT be done in O(1) time?
- A. Inserting after a node to which you hold a pointer
- B. Deleting the first node
- C. Inserting a new first node
- D. Deleting the last node
Correct answer: D. Deleting the last node
Deleting the tail requires the second-last node so its next pointer can be set to NULL, which takes a Θ(n) walk. The other three only touch the head or a known node.
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
- Run-length encoding: each maximal run is written as the character followed by its length. What is printed? python s = "yyyyyyyyxx" out, i…
- In the binary array [0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1] you may flip at most 2 zeros to ones. What is the length of the longest run…
- Delete duplicates from a SORTED linked list. Version A keeps one copy of each value; version B removes every value that appears more than…
- Trains occupy a platform from arrival to departure INCLUSIVE, so a train arriving at the same minute another departs needs a separate…
- Counting sort on [1, 1, 2, 1, 0, 3, 3, 0, 2, 0] (values 0–4) builds count[], turns it into cumulative counts, then scans the input from…
- What is the length of the shortest contiguous subarray of [1, 3, 1, 8, 7, 3, 4, 7, 1, 2] whose sum is at least 20? (All values are…