A program is maintaining two data structures (a) a linked-list which has an inte
ID: 3562544 • Letter: A
Question
A program is maintaining two data structures (a) a linked-list which has an integer field and
(b) an array of integers. The same numbers appear in ascending order in both data structures.
The numbers in the array are not stored at their corresponding subscript positions but in such a
way that no array gaps exit between any two consecutive numbers. Assume that both
structures have 10 numbers. So insertion of a middle number is done by first shifting the
larger numbers.
For each data structure, give:
(a) The number of positions affected {*} by inserting a number smaller than all numbers.
(b) The number of positions affected by a request to display the tenth number in the list.
{*} affected here means moved, checked, passed.
Explanation / Answer
a) in linklist 0 position would be affected (We don't need to move any number just put given number at first place)
In array 10 positions would be affected ( We would need to move all 10 numbers to their next position)
b) In linklist 10 positions would be affected ( We need to pass through all the numbers )
In array only 1 position would be affected (The tenth one.. We can directly access it and print it)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.