Data Structures Soal
Data Structures Soal
BINUS University
Faculty / Dept. : School of Computer Science Deadlin Day / Date : Tuesday / Apr 20th,
e 2021
Time : 13.00 – 16.20 (200
Minutes)
Code - Course : COMP6048 – Data Structures Class : All Classes
Lecturer : Team Exam Type : Online
) Strikethrough the unnecessary items
The penalty for CHEATING is DROP OUT!!!
EXAM INSTRUCTIONS
Learning Outcomes:
LO1 : Explain the concept of data structures and its usage in Computer Science
LO2 : Illustrate any learned data structure and its usage in application
LO3 : Apply data structures using C
Verified by,
Description:
a. search()
This function is built for searching whether the data has the same value as the node
in the existing Binary Search Tree. If it is found then print “found”, otherwise print
“not found”
b. insert()
This function is built for inserting a new node in the existing Binary Search Tree
c. inorder_traversal ()
This function is built for printing out the existing Binary Search Tree in inorder way.
d. preorder_traversal ()
This function is built for printing out the existing Binary Search Tree in preorder way.
e. postorder_traversal ()
This function is built for printing out the existing Binary Search Tree in postorder
way.
f. executeDeleteNode ()
This function is built for deleting a node in the existing Binary Search Tree. If the
node is either root or parent, then find replacement for the node otherwise delete
the leaf node.
g. deleteNode()
This function is built for searching the node in the existing Binary Search Tree that
want to be deleted
h. minValue()
This function is built for searching the minimum value in the existing Binary Search
Tree.
i. maxValue()
This function is built for searching the maximum value in the existing Binary Search
Tree.
Verified by,
struct node {
int key;
struct node *left;
struct node *right;
} *root;
if (root == NULL) {
root = new_node;
}
else if (val != curr->key) {
if (val < curr->key && curr->left == NULL) {
curr->left = new_node;
}
else if (val > curr->key && curr->right == NULL) {
curr->right = new_node;
}
else if (val < curr->key && curr->left != NULL) {
insert(curr->left, val);
}
else if (val > curr->key && curr->right != NULL) {
insert(curr->right, val);
}
}
}
void inorder_traversal(struct node* curr) {
if (curr == NULL) return;
inorder_traversal(curr->left);
printf("%d ", curr->key);
inorder_traversal(curr->right);
}
Verified by,
int main() {
root = NULL;
insert(root, 54);
insert(root, 81);
insert(root, 16);
insert(root, 27);
insert(root, 9);
insert(root, 36);
insert(root, 63);
insert(root, 72);
puts("");
deleteNode(root, 54);
printf("\nPreorder (after del 54): "); preorder_traversal(root);
Verified by,
puts("");
printf("Min value: %d \n", minValue(root));
printf("Max value: %d \n", maxValue(root));
puts("");
search(root, 10);
search(root, 8);
_getch();
return 0;
}
Output:
Hospital XX has a program to manage patient queues with the following criteria:
1. Queue priority is set based on the patient’s condition in the following order: Critical > Serious > Fair
> Good
2. If the patient has the same condition then First In First Served
3. There are two types of events: ADD and CALL
4. ADD to insert patient to the queue
5. CALL to move the patient into the room based on condition:
a. If patient in “Critical” Condition then move to Emergency Room
b. If patient in “Serious” Condition then move to the Examination Room
c. If patient in “Fair” or “Good” Condition move to the Consultation Room
Try implementing Double Linked List into the Hospital XX program using C
FORMAT INPUT
The first line contains an integer N events. Each event contains three variables String C1, String C2, String
C3. String C1 with format “C1 C2 C3”
Verified by,
CONSTRAINTS
1≤N≤100
C1 will contain “ADD” or “CALL”
3≤|C2|≤30
C3 will contain “Good”,”Fair”,”Serious” or “Critical”
Sample 1:
Sample 2:
Verified by,
-- Good Luck --
Verified by,