Question
A developer is choosing between an array and a linked
list to store a collection of elements. If the primary operations will be frequent insertions and deletions at arbitrary positions, and infrequent random access, which data structure is generally more suitable?Solution
Linked List: Insertion and deletion at arbitrary positions (once the position is found) are O(1) because only pointers need to be updated. However, random access (finding an element at a specific index) is O(N) as it requires traversing from the beginning. Â Â Array: Insertion and deletion at arbitrary positions are O(N) because elements need to be shifted. Random access is O(1). Â Â Given the emphasis on frequent insertions/deletions at arbitrary positions and infrequent random access, a linked list is more suitable.
A fish is at a depth d below the surface of a water tank. A cat observes the fish from air. Due to refraction at water-air interface, the apparent depth...
A 60 W lightbulb is connected to a 120V power source. What is the resistance of the bulb?
Which organ removes carbon dioxide from the blood?
Two blocks of unequal mass are connected by a string and placed on a smooth horizontal surface. A force F is applied on the heavier block. The tension i...
In alchemy, aqua fortis is the classical name of which chemical compound that is used chiefly in the manufacture of explosives and fertilisers, and in o...
Which of the following diseases can NOT be spread through air?
The Amrita Devi Bishnoi Wildlife Protection Award is given in the memory of Amrita Devi Bishnoi, who sacrificed her life along with 363 others for the p...
What is the common name of calcium hydroxide?
The main function of centriole is:
Which among the following nutrients is essential for the normal functioning of the thyroid gland?