The names of vegetables must be always held in alphabetical order in a list in the main memory. The application program should allow insertion and deletion of the names of vegetables from this list.

Question
HLPaper 1

The names of vegetables must be always held in alphabetical order in a list in the main memory. The application program should allow insertion and deletion of the names of vegetables from this list.

1.

Compare the use of a dynamic linked list for holding these names of vegetables with a static one-dimensional array.

[3]
Verified
Solution

Award [1] for each comparison, up to [3 max]. The size of the dynamic list does not have to be predetermined as in an array; The size of the dynamic list is not fixed whilst the size of an array is always fixed; If names are sorted they can be added/deleted (more easily) by changing the pointers without having to shuffle the names; As records can be dynamically added/deleted the memory is better used because there are no wasted / missing spaces as in an array;

2.

Sketch a single linked list holding these vegetables: potato, asparagus, lettuce, radish.

[2]
Verified
Solution

Award [1] for a node containing two fields / data(name) and link (pointer) to the next node and [1] for showing an external pointer pointing to the first vegetable on the list, and null pointer in the last node, and pointers which link the nodes in alphabetical orderup to [2 max].

3.

List the steps required to insert cabbage into the linked list.

[4]
Verified
Solution

Award [1]for each step identified up to [4 max]. Create a new node containing cabbage; Traverse the list (from the beginning) to find the place to insert a new node; Cabbage should be inserted before lettuce and after asparagus; The pointer in new (cabbage) node should be set to point to the node that is before the insertion point / lettuce; The pointer in node before insertion point / asparagus / should now point to the new node / cabbage; Note: award marks for clearly labelled diagrams in candidates'answers.

4.

Explain why deleting the first node in this list is different to deleting other nodes.

[2]
Verified
Solution

Award [1]for identifying a reason why deleting the first node is different to deleting other nodes and [1] for an expansion up to [2 max]. External pointer (First) must be changed/only in situation when deleting the beginning node the external pointer must be changed; And set to the pointer in the link field of the first node (Asparagus) which points to the second node/Lettuce;

Sign up for free to view this answer

5.

State the dynamic data structure suitable for maintaining this list of vegetables which will allow faster searching for a given vegetable name.

[1]
Verified
Solution

Award [1 max]. Binary tree;

Sign up for free to view this answer

6.

Sketch the data structure suggested in part containing the vegetable names sorted in alphabetical order. The vegetable names are input in the following order: potato, asparagus, lettuce, radish.

[3]
Verified
Solution

Award [3 max]. Award [1] for clearly a binary tree and the root is Potato. Award [1] for the correct left subtree. Award [1] for the correct right subtree.

Sign up for free to view this answer

Still stuck?

Get step-by-step solutions with Jojo AI

FreeJojo AI

Want more practice questions for Computer Science (CS)?

Join 350k+ Students Already Crushing Their Exams