Вы находитесь на странице: 1из 6

# MUIT 210 DATA STRUCTURES AND ALGORITHM LEVEL 200 EVENING SESSION-ASSIGNMENT INDEX NUMBER: BSSI / ED / 115031 NAME:

DODOO SHIVALANDER Q1a. Observe that A is the root, its left subtrees L consist of B D E H M P N R O S T and the right subtrees R consist of CFIJGKL Pre-order The pre-order traversal of the tree processes A, traverses L and traverses R. Therefore the pre-order traversal of the tree will be A B D H M O S T P N R E C F I J G K L In-order The in-order traversal of the tree traverses L, processes A and traverses R. Therefore the in-order traversal of the tree will be S O T M P H N R D B E A I F J C K G L Post-order The post-order traversal of the tree traverses L , traverses R and processes A,. Therefore the post-order traversal of the tree will be S T O P M R N H D E B I J F K L G C A

Q1b. The height of the tree is 7 Q1c. Leaf nodes are S T P R E I J K L Q2a. A binary search tree also called ordered/sorted binary tree is a node-based binary tree data structure which has the following properties. 1. The left sub tree of a node contains only nodes with keys less than the nodes key. 2. The right sub tree of a node contains only nodes with keys greater than the nodes key. 3. Both the left and right sub tree must also be binary search trees.

Q2b.

4 0 6 2 8 6 8 4 9 7 1 6

1
9
1 2

2 3 5 6 1 2 6

2 7

8 5

Q2c.

*
+ -

+ i

Q2d. A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled and all nodes are as far left as possible.

Q3a.

Q
Q3b. The height of the tree is 4. Q3c. The internal nodes are B K P Q3d. The post-order traversal sequence is L M B N Q P K A Q4a. Since the companys objective is to lay off some workers on the basis of service time (the most recently hired employed will be laid off) then the appropriate application will be STACKS (LIFO) and not FIFO queues. This is because FIFO queues, also known as First-in-first-out where deletion/removal of any element can only be done at one end, called the FRONT and insertion/additions can take place only at the other end, called the REAR. Applicable to the situation at hand, the most recently hired workers records will be at the REAR but at this end there is only one operation that can be done and that is INSERTION which will not help us achieve our aim-TO LAY OFF THE MOST RECENTLY EMPLOYED. And inversely to delete/ remove any record, we will end up deleting the wrong records that is old staff records which is not the companys objective. So to achieve the companys objective, STCKS (LIFO) will be suitable because with this data structure, the LAST element to be inserted is the FIRST element to be removed. This will allow the most recently employed workers whose records will be at the last part of the stack to be deleted without affecting the old staff records.

Q4b. Since the aim is to keep track of patients as they check into a clinic and assign them to Doctors on a first-come-firstserve basis, application will be suitable for a FIFO queue. This is because FIFO queues, also known as First-in-firstout where deletion/removal of any element can only be done at one end, called the FRONT and insertion/additions can take place only at the other end, called the REAR. Queues are used in operating systems to keep track of tasks waiting for scarce resource and to ensure that the tasks are carried out in the order that they are generated. Consider the diagram below: Data Five patients in a queue in wait to be assign to 2 Doctors
DOCTOR 1

KOFI
FRONT

AMA

ATA

EMMY

KWAME
REAR

DOCTOR 2

From the diagram above KOFI is the patient so he will be assigned to DOCTOR 1 and AMA to DOCTOR 2, after check up the next assignment will be ATA either to DOCTOR 1 or DOCTOR 2 base on the DOCTOR who finishes with the patient first. And if another patient comes for checkup or treatment, he cannot cross the queue (at the systems/ application level) but to be inserted at the rear which is the behind KWAME who is in wait to be assigned to a DOCTOR Q4c. FIFO queues will not be suitable for this application because FIFO does not allow random selection, where elements or data could be selected from any where. It only allows selection at certain points/places that the FRONT (deletion occurs here) and the REAR (insertion occurs here). The appropriate data structure to use for this application is Linked list which allows random selection without restructuring or reorganizing its data.