Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Choosing data structures The selection of data structures used in a program depends on both the type of data being stored and the operations the
Choosing data structures
The selection of data structures used in a program depends on both the type of data being stored and the operations the program may need to perform on that data. Choosing the best data structure often requires determining which data structure provides a good balance given expected uses. Ex: If a program requires fast insertion of new data, a linked list may be a better choice than an array.
PARTICIPATION ACTIVITY
: A linked list avoids the shifting problem.
Start
Insert B
A
C
W
B
linked list:
array:
A
C
B
W
Insert B
Static figure:
Pictured are an array and a linked list. Each data structure is accompanied by the text "Insert B
The array has these elements in this order: A B C W Each of these four elements is numbered according to its position in the array; that is A is numbered B is numbered C is numbered and W is numbered
The linked list has the same four elements in the same order: A B C D The node containing element A has an arrow pointing downright to the node with element B which has an arrow pointing upright to the node with C which has an arrow pointing right to the last node with W
Step : Inserting an item at a specific location in an array requires making room for the item by shifting higherindexed items.
Array with contents A C W appears, with the elements numbered respectively. The text "Insert B also appears. In the array, an empty slot appears to the right of the slot containing element W and is numbered W and C each shift position to the right to make room for a new array entry at index
Step : Once the higher index items have been shifted, the new item can be inserted at the desired index.
The B from the text "Insert B replicates and the replica moves to the now empty slot in the array at index The array thus contains these elements: A B C W
Step : To insert a new item in a linked list, a list node for the new item is first created.
A linked list appears with nodes, each node having one element. The node containing element A points to the node containing element C which points to the node containing element W A new node appears that contains element B
Step : Item Bs next reference is assigned to reference item C Item As next reference is updated to reference item B No shifting of other items was required.
An arrow appears that points from the node with element B to the node with C; then, the arrow pointing from the node with element A to the node with B moves such that it now points to the node with element B
Captions
Feedback
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started