Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Thanky you. (36 marks) Consider the following data structure for representing a

ID: 3681253 • Letter: T

Question

Thanky you.

(36 marks) Consider the following data structure for representing a set I of integers. The uestion 2 elements of the set are stored in a doubly linked list of arrays such that: (1) Each element of I occurs in exactly one of the arrays in this list. (2) each array is sorted in increasing order, (3) the number of elements in each array is a power of 2. (4) no two arrays in the list have the same size, and (5) the arrays in the linked list are kept in order of increasin size. Note that although each array is sorted, there is no particular relationship between the elements in different arrays.

Explanation / Answer

Consider a doubly linked list A <--> B <--> C <--> D <--> E. Suppose I have a pointer/reference to D. To remove it, I do:
•Find the predecessor (C) - O(1)
•Find the successor (D) - O(1)
•Change the predecessor's "next" to the successor (E) - O(1)
•Change the successor "previous" to the predecessor's (C) - O(1)


Now, consider a linked list A --> B --> C --> D --> E. I still have a pointer/reference to D. To remove it, I do:

•Find the predecessor (C) - O(n) - I have to search the list to find the predecessor so it isn't O(1)
•Find the successor (E) - O(1)
•Change the predecessor's "next" to the successor (E) - O(1)
•Change the successor "previous" to the predecessor's (C) - O(1)


So time complexity to delete a node from doubly linked list is O(1).

But the insertion and deletion of elements in a sorted array executes at O(n), due to the need to shift all the elements sometimes following the element to be inserted or deleted.

Dr Jack
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote