You are on page 1of 62

GROUP ASSIGNMENT

TECHNOLOGY PARK MALAYSIA

CT077-3-2 DSTR

DATA STRUCTURES

APU2F2109SE / APD2F2109CS(DA) / APU2F2109CS(DA) /


APD2F2109SE / APD2F2109CS / APU2F2109CS

HAND OUT DATE: 28 MARCH 2022

HAND IN DATE: 30 MAY 2022

WEIGHTAGE: 50%

INSTRUCTIONS TO CANDIDATES:

1 Submit your assignment at the Moodle System.

2 Students are advised to underpin their answers with the use of


references (cited using the APA Style System of Referencing)

3 Late submission will be awarded zero (0) unless Extenuating


Circumstances (EC) are upheld

4 Cases of plagiarism will be penalized

5 The assignment should be submitted in softcopy, where the softcopy of


the written assignment and source code (where appropriate) should be
on Moodle System.

7 You must obtain 50% overall to pass this module.


Full Name TP Number
Handika Harianto Ew Jong TP061297
Ehab Nader Badawi Abughazaleh TP058629
Jasson Armendra Salim TP058075
Data Structures (CT077-3-2-DSTR) i

Table of Contents
1.0 Introduction........................................................................................................................1
1.1 System..........................................................................................................................................1
1.2 Data Structures...........................................................................................................................1
1.3 Classes/Structs............................................................................................................................4
1.4 Enumeration...............................................................................................................................5
2.0 System Implementation......................................................................................................6
2.1 Sorting Algorithms.....................................................................................................................6
2.2 Searching Algorithms.................................................................................................................9
2.3 Utility Functions.......................................................................................................................11
2.4 Add a Tutor Record.................................................................................................................16
2.5 Display All Records..................................................................................................................18
2.6 Search a Tutor by Tutor ID.....................................................................................................20
2.7 Search Tutors by Overall Performance (Rating)..................................................................22
2.8 Sort and Display by Tutors ID in Ascending Order.............................................................24
2.9 Sort and Display by Tutors Hourly Pay Rate in Ascending Order.....................................27
2.10 Sort and Display by Tutors Overall Performance in Ascending Order..............................29
2.11 Modify a Tutor Record............................................................................................................30
2.12 Delete a Tutor Record..............................................................................................................34
3.0 Results...............................................................................................................................38
3.1 Array..........................................................................................................................................38
3.2 Linked List................................................................................................................................46
4.0 Conclusion........................................................................................................................55
5.0 Future Works....................................................................................................................56
6.0 Reflection..........................................................................................................................56
7.0 References.........................................................................................................................56
8.0 Appendix...........................................................................................................................58
Appendix A. Workload Matrix............................................................................................................58

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 1 of 59

1.0 Introduction
1.1 System
Nowadays, the eXcel Tuition Centre is increasingly popular as one of the fastest-growing
tuition centres in Malaysia. Their tuition centres are spread across various locations and have
employed many tutors with their own specializations in each field. To store the tutors' data, the
eXcel Tuition Centre is still using a manual filing system. This filing system works by
categorizing the tutors by their locations, then followed by sorting their names alphabetically.
This approach is very time-consuming and prone to errors because the tutors' records can
potentially be misplaced in the wrong tuition centres and the records may have been placed in the
wrong alphabet sequence. As a result of this, the admin manager of eXcel Tuition Centre has
decided to computerize the current filing system to manage the tutors' records.

Prior to the systems implementation stage, the design of the system must be completed.
First, each tutor will have attributes, such as tutor ID, name, date joined, date terminated, hourly
pay rate, phone number, address, tuition centre code, tuition center name, subject code, subject
name, and rating. In addition, there are various core functionalities that must be fulfilled for the
system to operate as intended. These functionalities comprise adding tutor records, displaying all
records, searching a tutor, sorting a tutor, modifying a tutor record, and deleting a tutor record.

As the speed of the program plays an important role, the system will be developed using
two data structures, which are an array and a linked list. The primary reason for this is because it
allows us to compare which approach is best suited for the Tutors Management System.
Additionally, various algorithms will also be implemented to make the comparison between the
two approaches easier.

1.2 Data Structures


Data structures are commonly applied in various applications, especially the more
complicated ones. Data structures are a specialized means of organizing and storing data in
computers in such a way that operations can be performed more efficiently (Mallawaarachchi,

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 2 of 59

2020). In the system itself, two data structures will be implemented, which are an Array and a
Linked List.

The following are the data structures implemented in the Tutors Management System.
1.2.1 Array
An array is defined as a collection of items that are stored inside a contiguous memory
location. The main idea is to store numerous things of a similar type together. That makes it
simple to calculate the location of every element by basically adding an offset to the base value,
such as the memory area of the first element of the array (for the most part signified by the name
of the array). The first value is in the index of 0 and the 2 index number differences are the
offset. The benefit of using an array is that arrays allow random access to the element, and that
makes accessing the element's position faster. Furthermore, arrays are pretty good at
performance because of the better cache locality, and arrays can multiply data items that are the
same type using a single name.

The disadvantage of using arrays is the size cannot be changed. For example, once the
array is declared, the size cannot be changed due to the static memory location. Moreover, array
insertion and deletion are difficult due to the elements that are inside the contiguous memory
location. The application of arrays varies, such as arrays to store data of the same data type,
arrays for solving matrix problems, arrays for a lookup table, arrays for CPU scheduling, arrays
for sorting, array for a database record, and many more.

1.2.2 Linked List


A linked list is basically a linear type of data structure, meaning that the values are not
stored at a contiguous memory location. Values that are stored in the linked list are linked using
pointers. A Linked List is a structure that works not by its physical placement in the memory, but
it uses the logical links as a part of the value inside the structure. The benefit of using a Linked
List is that it provides a dynamic data structure, by allocating and deallocating the memory the
dynamic arrangement memory can grow and shrink. Furthermore, the linked list is the most
efficient technique where it is no memory wastage, efficient memory can be accomplished since

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 3 of 59

the size of the linked list is increasing and decreasing at run time so there is no memory wastage
and there is compelling reason need to pre-allocating the memory (GeeksForGeeks, 2022).

The drawback of Linked List is the bigger the memory usage. Since in a linked list, a
pointer is additionally expected to store the location of the next value and requires additional
memory for itself. Moreover, random access is not possible with a linked list, since linked lists
use a dynamic memory allocation technique (GeeksForGeeks, 2021).

There are a lot of differences between arrays and linked lists, such as the memory
allocation technique, where arrays use compile-time and linked lists use runtime. Another major
difference is the memory efficiency, for the same number of elements, a linked list utilizes more
memory as a source of perspective to the following node stored along with the data itself. In any
case, size flexibility in the linked list might make them utilize less memory generally, this is
helpful when there is a vulnerability about size or there are enormous varieties in the size of
information components, memory comparable to as far as possible on the size must be
apportioned. While using arrays, a linked list can build their size bit by bit proportionately to the
amount of data stored (GeeksForGeeks, 2021).

In total, there are two types of linked lists, which are singly linked lists, and doubly
linked lists. The following are the comparisons between the singly linked list and the doubly
linked list.

Comparison Between a Singly Linked List and a Doubly Linked List

Variation Singly Linked List Doubly Linked List


Category
Characteristic Contains two fields, which Contains three fields, which
are data field and next link are data field, previous link
field (a pointer to next field (a pointer to previous
node). node), and next link field (a
pointer to next node).

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 4 of 59

Access Accessing elements in a Accessing elements in a


singly linked list is less doubly linked list is more
efficient as it can only be efficient as it can be
performed through one performed through two
direction (forward). directions (forward and
backward).
Memory Requires less memory as it Requires more memory as it
contains only two fields. contains three fields.
Time complexity Time complexity of Time complexity of
performing insertion and performing insertion and
deletion is O(n). deletion is O(1).
Used for Commonly used if non- Commonly used to perform
searching operations are not searching operations.
required.
Preference Preferred when there is Preferred when there is no
memory limitation. memory limitation.

According to the table above, both variations of the Linked List have their advantages
and disadvantages. Therefore, we have decided to use a Singly Linked List over the doubly
Linked List for several reasons. First, when inserting a new node into the singly Linked List,
O(1) can be achieved when the node is inserted at the front of the Linked List. This allows us to
have the same time complexity with the insertion in a Doubly Linked List. Although a doubly
Linked List is commonly used for operations that require searching operations, such as deletion
and updation, implementing a doubly Linked List in this system is a waste of memory because
the nodes inside the Linked List are not sorted. As a result of this, it is not possible to perform a
two-way traversal efficiently.

1.3 Classes/Structs
In the system, a Tutor struct, and a Paging class will be implemented.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 5 of 59

1.3.1 Tutor
To represent the tutor inside the Tutors Management System, a struct keyword will be
used for both the Array and the Linked List implementation to create a user-defined data type. In
the Array implementation, the Tutor struct comprises all attributes listed, except the *next. The
main reason is that an array does not require a pointer to the address of the next element as the
elements will be stored in a contiguous memory location.

The following is the Tutor struct used in the Tutors Management System.

Figure 1 Tutor struct

1.4 Enumeration
To develop a more readable system, Enum will be implemented. Enum is a user-defined
data type that consists of a fixed set of constants or integral constants (Pedamkar, n.d.). The
primary reason is that it makes the code to be more maintainable and allows us to avoid errors by
passing in invalid constants (Singh, n.d.).

The following are two Enums created specifically for the system.
1.4.1 Account Type
As the Tutors Management System has two types of user roles, such as HR manager and
admin, an Enum named AccountType will be defined. The admin holds the value of 1, whereas
the manager holds the value of 2. Additionally, this Enum will primarily be used to check the
user role of the logged-in user.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 6 of 59

Figure 2 AccountType enum

1.4.2 Action Type


Another Enum that will be used in the system is known as ActionType. The main
purpose of this Enum is to map the actions that can be performed by the user (HR manager and
admin) to certain constant values.

Figure 3 ActionType enum

2.0 System Implementation


2.1 Sorting Algorithms
The sorting algorithms implemented within the Tutors Management System are as
follows.
2.1.1 Array
2.1.1.1 Bubble Sort
For the array part, the bubble sort is the only sort algorithm used for sorting. This
algorithm works by repeatedly swapping the adjacent elements if they are in the wrong order
(Bubble Sort, 2022). In addition, this algorithm has a time complexity of O(N 2) because a nested
loop is being used to traverse the nodes inside the linked list.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 7 of 59

Figure 4 sortTutorID() function

2.1.2 Linked List


2.1.2.1 Bubble Sort
The first sorting algorithm used in the linked list implementation is known as the Bubble
Sort algorithm. This algorithm works by repeatedly swapping the adjacent elements if they are in
the wrong order (Bubble Sort , 2022). In addition, this algorithm has a time complexity of O(N2)
because a nested loop is being used to traverse through the nodes inside the Linked List.

Figure 5 Bubble sort algorithm

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 8 of 59

2.1.2.2 Merge Sort


Merge Sort is the most efficient sorting algorithm for a Linked List, and it is based on the
divide-and-conquer paradigm. This algorithm works by constantly cutting down a list into
multiple sublists recursively until each has only one item, then merges those sublists into a sorted
list (Khandelwal, 2021). Furthermore, this algorithm has a time complexity of O(N * log N),
which is faster than the other sorting algorithms, such as Bubble Sort and Insertion Sort as their
time complexity is O(N2). Additionally, there are two helper functions that are used inside the
Merge Sort algorithm to achieve the sorting, which is mergeSortedSublists() and
splitLinkedList().

Figure 6 mergeSort() function

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 9 of 59

Figure 7 mergeSortedSublists() function

Figure 8 splitLinkedList() function

2.2 Searching Algorithms


The following are some of the searching algorithms used in the system implementation.
2.2.1 Array
2.2.1.1 Linear Search
Array only use linear search as the algorithm for searching. Linear search works by
traversing each node sequentially within the Linked List until the desired node is found. This
algorithm has a time complexity of O(N), which is better as compared to the Binary Search

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 10 of 59

algorithm. In addition, Linear Search algorithms can be applied to both sorted and unsorted
linked list.

Figure 9 linear search in array

2.2.2 Linked List


In the linked list implementation, only one searching algorithm used, which is known as
Linear Search Algorithm.
2.2.2.1 Linear Search
Linear search works by traversing each node sequentially within the Linked List until the
desired node is found. This algorithm has a time complexity of O(N), which is better as
compared to the Binary Search algorithm. In addition, Linear Search algorithms can be applied
to both sorted and unsorted linked list.

Figure 10 Linear Search in linked list

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 11 of 59

2.3 Utility Functions


2.3.1 Array

2.3.1.1 Paging function


This function displays records one by one. First the system needs to know at which page
it’s on, so if the index i was at the first element of the array ( allTutor[0] ), the first tutor will
be displayed and only Next and Exit function will be displayed for the user. If they chose to exit,
he will get back to the main menu, but if he chose to go next, then the second tutor will be
displayed and the index i will increment by 1, and as long as i is greater than zero, the options
Next, Previous, Exit will be displayed unless if i + 1 equal zero, in this case it means that we
reached the last tutor in the array, thus, only the options Previous and Exit will be displayed for
the user. When the user chose the Previous option, the value of i will be decreased by 1, which
displays the previous tutor.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 12 of 59

Figure 11: paging() function

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 13 of 59

2.3.1.2 Check for ID duplication or zero


This function will check wither the ID that the user inserted is already existed in the
array or not or if it was zero. First the variable flag was created, then using a for loop, the index i
will loop inside the array to search for the ID in the array. If the ID inserted by user matched
with one of the IDs in the array, flag value will be 1, if the ID is zero, the flag value will be 2.
Out of the loop, if the flag value was 1, it will display a message for the user that the ID is
already existed and return true. If the value of flag is 2, it will display a message for the user that
the ID can’t be zero and return true. If the flag value neither 1 nor 2, then the function will
return false.

Figure 12: checkDuplicateOrZero() function

2.3.2 Linked List

2.3.2.1 Convert string to uppercase letters


The first utility function is convertToUppercase(). As the name implies, this
function accepts a string that contains lowercase letters and convert it into uppercase. In addition,
this utility function is used in various functionalities.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 14 of 59

Figure 13 convertToUppercase() function

2.3.2.2 Check duplication


This function will be called after the user insert the ID of the new tutor. The function will
search for the ID in the records, if there is the same ID inside the records, the flag value will
become 1 and the checkDuplicate() function will return true, otherwise, it will return false if
there is no duplication.

Figure 14: checkDuplicate() function

2.3.3 Shared utilities


2.3.3.1 Get date difference
The purpose of this function is to obtain the days difference between two dates. This
function is mainly used in the “remove tutor record” functionality since only the terminated
tutors that have exceeded 6 months can be deleted. This function accepts one argument which is
the given date. Afterward, the current date will be obtained and split into three parts, which are
the day, month, and the year. Next, both dates will be converted into days and subtraction will be
performed.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 15 of 59

Figure 15 getDateDifference() function

2.3.3.2 Calculate leap year


This utility function is used to determine whether the given year is a leap year or not.

Figure 16 calculateLeapYear() function

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 16 of 59

2.3.3.2 Calculate leap year


This function checks for the validity of the rating, if the user inserted rating over 5 or less
than 1, he will have to insert it again.

Figure 17: validality_rating() function

2.4 Add a Tutor Record


2.4.1 Array
In this functionality, the user can add tutor record into the system. Firstly, After the user
entered the ID of the new tutor, the ID will go inside the function checkDuplicationOrZero(), to
check if three is a duplication or if the ID is zero, then the bool value that is returned from the
function will be captured by the variable the duplicateOrZero and it will be passed to an if
statement, if there is a duplication or the value is zero, then the user will have to insert a different
ID, otherwise, the user will continue to enter the other information of the new tutor. After that,
save it into tutor Struct and use insertTutor() function will be called to add the tutor to the array.
Finally, the user will be directed to the main menu. function is used as the main function to add
the new tutor into the array,

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 17 of 59

Figure 18: inputTutor() function

2.4.2 Linked List


To add a new tutor to the linked list the function addTutor() will be used with the
accountType passed as an argument, to decide later which main menu to display for the user
after done adding new tutors based on his account type. First the user will have to insert how
many tutors he wants to add, then he will need to insert the ID of the new tutor. The new ID will
be passed to the checkDuplication() function, to see if the ID is already existed in the linked
list or not. After that, the boolean value that is returned from the function will be captured by the
variable the duplicate and it will be passed to an if statement, if there is a duplication, then the
user will have to insert a different ID, otherwise, the user will continue to enter the other
information of the new tutor. Then a new tutor will be created and passed to the
insertToTheFront() function, to add it to the front of the linked list. Finally, the system will
print a different message based on the number of tutor that the user entered and redirect him to
the main menu.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 18 of 59

Figure 19: addTutor() Function

2.5 Display All Records


In this functionality, the records of each tutor within the Tutors Management system will
be displayed in the output. The implementation of this functionality is like performing a linear

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 19 of 59

search. But instead of stopping when the tutors’ records have been displayed, the program will
keep going until there are no tutors left.

2.5.1 Array
Firstly, when the user chooses this option from the main menu, he will then have to
choose between either display all records at once, or to display one record at a time, by using the
paging() function. When the user choose the first option, automatically all the tutors inside the
array will be lopped until the id of the tutor equals to ZERO, this means that the loop has reached
an empty element, thus to stop looping. In each loop a tutor record will be displayed. After that
the user will be sent into the main menu again. If the user choose the second option, only one
tutor record can be displayed at a time, and the user can move between the records eaither to the
next record or previous record, and he can exit at any time.

Figure 20: displayTutor() Function

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 20 of 59

2.5.2 Linked List


In the implementation of a singly linked list, tutors’ records will be traversed from the
head of the linked list. The main reason is that a singly linked list does not support two-way
traversal. Although this operation can also be achieved using a doubly linked list, a singly linked
list is preferred because it uses less memory. In addition, both singly and doubly linked lists have
the same time complexity for this operation, which is O(N). Therefore, a singly linked list is
implemented for this operation.

Figure 21 Display all tutors' functionality in a linked list

2.6 Search a Tutor by Tutor ID


In this functionality, a tutor ID will be used to search for a tutor’s records. The tutor ID
will be obtained through user input. For the searching algorithm, a linear search algorithm will
be used. This searching algorithm has a time complexity of O(N) for both array and linked list
implementation. In total, there are two possibilities for this functionality, which are whether the
tutor exists within the system or does not exist at all. If the tutor is present, the records will be
displayed in the output and the program will stop searching. Otherwise, no records will be
displayed.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 21 of 59

2.6.1 Array
This functionality basically is simple, first the user is asked what tutor id that they search
for and then the whole array will be looped until the user tutor id is equal and met to what is
inside the array. If the tutor id is met, the details will be printed, while if not the system will print
tutor not found and the user will be sent back to main menu,

Figure 22 searchTutorID() function

2.6.2 Linked List


In this functionality, a linear search algorithm is performed instead of a binary search
because of two reasons. The first reason is that the binary search requires the linked list to be
sorted first, whereas a linear search works for both unsorted and sorted linked lists. As a result of
this, there is a need to perform a sorting algorithm before a binary search can be implemented.
This will increase the complexity of the program unnecessarily. Another reason is that both

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 22 of 59

searching algorithms have the same time complexity, which is O(N). Therefore, implementing a
linear search algorithm is a better option than a binary search.

Figure 23 Search tutor by ID functionality in a linked list

Figure 24 Search tutor by ID functionality in a linked list

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 23 of 59

2.7 Search Tutors by Overall Performance (Rating)


2.7.1 Array
This functionality works the same as the above (Search a Tutor by Tutor ID) but this time
use Overall performance. The algorithm is the same where the array will be looped and if the
value met each other, the system would print the details.

Figure 25 searchTutorRating() function

2.7.2 Linked List


To search for a tutor by his performance, the function searchTutorByPerformance()
can be used. The algorithm used in this searching function is the linear search algorithm. First,
the user will need to insert the performance of the tutors that he wants to view. Then, the
performance will be compared with every performance inside the nodes in the linked list. Every
node in the linked list that has the same performance will be displayed for the user. Finally, the
user can choose either to search for another performance or to go back to the main menu.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 24 of 59

Figure 26 searchTutorByPerformance() function

2.8 Sort and Display by Tutors ID in Ascending Order


2.8.1 Array
Bubble sort is used in this functionality, where the array is being looped and put into
temp and recirculating until the Tutors ID is put in ascending order. And then the array will be
printed into the system using the display all tutor function that has been explained in the 2.2.1.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 25 of 59

Figure 27 sortTutorID() function

2.8.2 Linked List


The function sortTutorsById() will be used to sort tutors based on their IDs in
ascending order, using the bubble sort method. In this function, first a clone if the head of the
linked list will be created, then 5 Tutor pointers will be created (last, a, b, c, temp),
where last points to the last node in the list, a to the first, b to the node after a, and c at first
will have the value of a, but after a moves, c will point to the node before a, and temp is for
holding the temporary value when swapping. two for loops were used here, in the first one, last
will point to the end node in the list. The pointer last will keep looping until it reaches the second
node (headcopy->next), in each loop the value of last will equal to a.

In the second for loop, c is assigned with the value of a, and a is assigned with the value of the
first node, here, a will keep looping until a->next reach last, and in every loop, c will be
updated with the value of a, while a is updated to the node after it, so c will always point to the
node before a.
Inside the second for loop, b will be updated with the value of the node after a, then a will be
compared with b, if the ID in a is greater than the ID in b, the node after a will be updated with
the node after b, and the node after b will be updated with a. then the system will check, if a is
not the first node, c->next will be assigned with the node b, else, the first node (headcopy)
will be assigned with the node b. Then the system continues with the swapping process between
a and b. After that the paging operations take place to display results one by one.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 26 of 59

Figure 28:sortTutorById() function

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 27 of 59

2.9 Sort and Display by Tutors Hourly Pay Rate in Ascending Order
In this functionality, a list of tutors will be displayed based on their hourly pay rate in
ascending order. To achieve this, a sorting algorithm needs to be performed. For both the array
and the linked list implementation, a sorting algorithm known as bubble sort will be used. This
sorting algorithm has a time complexity of O(N 2) for both implementations. Additionally, as the
users should be able to move back and forth when the tutors’ records are displayed, the Paging
class is also used. This Paging class consists of some useful functions to display the current page,
move to the previous or next page, etc. If the user wants to view the previous tutor, the number 1
needs to be inputted. To view the next tutor, the user just needs to enter the number 2.

2.9.1 Array
sortTutorPay() function will sort tutors based on their hourly pay rate in ascending
order. The sorting method that was use is the insertion sort method, this is because the array that
we have is relatively small and insertion sort is efficient for small data sets, also, it needs only
one constant amount of additional memory space (Madurapperuma, 2019). After this function is
done sorting tutors, the displayTutor() function will be called to let the user decide how he
wants to view the records, either at once, or one by one using the paging() function.

Figure 29 sortTutorPay() function

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 28 of 59

2.9.2 Linked List


In the linked list implementation, a copy of the linked list will first be created using the
clone() function. The main reason is to prevent the original linked list from being modified
after the bubble sort algorithm is performed. The source code for the bubble sort algorithm can
be found in section 2.1.2.1. After the bubble sort algorithm is performed, the head of the copied
linked list is passed as an argument to the constructor of the Paging class so that the users can
move back and forth between the tutors’ records.

Figure 30 Sort and display by tutors hourly pay rate functionality in a linked list

Figure 31 Sort and display by tutors hourly pay rate functionality in a linked list

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 29 of 59

2.10 Sort and Display by Tutors Overall Performance in Ascending Order


In this functionality, a list of tutors will be displayed in the output based on their overall
performance (rating) in ascending order. Prior to displaying the list of tutors, a sorting algorithm
needs to be implemented. In total, there are two sorting algorithms used, which are the bubble
sort and the merge sort algorithms. The bubble sort algorithm is used in the array
implementation, whereas the merge sort algorithm is used in the linked list implementation.
Also, the Paging class is also used to enable users to move back and forth between the tutors’
records.

2.10.1 Array

Figure 32 sortTutorID() function

2.10.2 Linked List


In the linked list implementation, the linked list will be copied first by calling a clone()
function to prevent the original array from being modified. Afterward, the copied linked list will
be sorted using the merge sort algorithm. The merge sort is the most efficient sorting algorithm
in the linked list implementation because it has a time complexity of O(N * log N). This is
significantly faster than the other sorting algorithms, such as the bubble sort and the insertion
sort, which have the time complexity of O(N 2). The source code of the merge sort algorithm can
be found in section 2.1.2.2. After the linked list is sorted, the Paging class will also be used to
enable the users to move back and forth when displaying the tutors’ records.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 30 of 59

Figure 33 Sort and display by tutors overall performance functionality in a linked list

Figure 34 Sort and display by tutors overall performance functionality in a linked list

2.11 Modify a Tutor Record


To modify a tutor's details, the tutor ID will be used to search for the desired tutor within
the Tutors Management System. The primary reason is that the tutor ID is a unique identifier for
the tutor inside the system. Therefore, the precision of the system can be guaranteed.
Additionally, only the account type of HR manager can perform this operation. In total, there are
only two attributes that can be modified, which are the tutor's phone number and home address.
As a searching algorithm is also needed to perform searching for the tutor, a linear search

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 31 of 59

algorithm will be used, which has a time complexity of O(N). This searching algorithm is easy to
use and works well for both unsorted and sorted data structures.

2.11.1 Array
To modify a tutor record in the array system, the function modifyTutor() will be used.
First, the user will have to enter the ID of the tutor that he wants to modify. Then the system will
search for the tutor that has the same ID in the array using the linear search algorithm. If the tutor
ID was found, the tutor details will be displayed and the found variable will be set to true. Else,
the system will display that the tutor isn’t in the array and will let the user to choose if he wants
to continue or go back to the main menu.

When the tutor ID is found. The user can choose which record of the tutor he wants to
modify, phone number or address. To validate to option that the user has entered, a while loop
was used, so if the user has entered a value ither than 1 or 2, it will keep looping until the user
inserts a valid option. After the user choose which record that he wants to change, he will then
enter the new record. The new record then will be updated. Finally, the user will be directed to
the main menu.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 32 of 59

Figure 35: modifyTutor() function

2.11.2 Linked List


In the linked list implementation, the searching process will start from the head of the
linked list using a linear search algorithm. This searching algorithm is used instead of a binary

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 33 of 59

search because there is a need to sort the linked list first if the binary search algorithm is used as
compared to the linear search algorithm where the searching process can be done directly. Once
the desired tutor is found, the current tutor will be passed into the updatePhoneNumber() or
updateHomeAddress() functions so that the selected attribute can be modified.

Figure 36 Modify a tutor functionality in a linked list

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 34 of 59

Figure 37 Modify a tutor functionality in a linked list

Figure 38 Functions to update the phone number and home address in a linked list

2.12 Delete a Tutor Record


In this functionality, the HR manager has an option to delete tutor records that have
exceeded 6 months of termination. The function below will first filter out the tutors based on

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 35 of 59

their termination dates using the function named getDateDifference() to calculate the
number of days that have passed since the termination of the tutors. If the number of days since
the termination has exceeded 183 days (roughly 6 months), the tutor’s name and ID will be
displayed in the output. After every terminated tutor has been listed, the program will prompt the
HR manager to enter the tutor ID of a tutor that needs to be removed from the system. In
addition, since this functionality requires a searching algorithm before tutor deletion, a linear
search algorithm is being used.

2.12.1 Array
To delete a tutor from the records, the function deleteTutor() function will be used.
First the system will check if there are tutors who was terminated for over 6 months, if no tutor
found then the user will be directed to the main menu. If there are tutors who was terminated for
over 6 months, they will be displayed for the user and then he will have to enter the ID of the
tutor that he wants to delete. First the user needs to insert the ID of the tutor that he wants to
delete. Then the system will search for the ID inside the array, if the ID was found, then its tutor
will be displayed and change the value of the found variable to true. if the ID wasn’t found, the
system will display a message to the user and let him choose if he wants to delete different tutor
or if he wants to go back to the main menu.

When the ID is found, first the user will have to confirm his choice, then, if he confirms,
the system will delete that specific tutor from the array. The way the deletion happens is first by
looping in the array, then, when the index reaches the position of the tutor that the user wants to
delete, then shifting the elements after it to the left. Then we decrease the size of the array by
calling the global variable sizeOfArray and decrease it by 1. Then the user will be directed to
the main menu. If the user didn’t confirm his option, he will be directed to the main menu.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 36 of 59

Figure 39: deleteTutor() function

2.12.2 Linked List


In the linked list implementation, after all tutors that can be deleted have been displayed
in the output, the users will be prompted to enter the ID of the tutor that will be deleted.
Afterward, if the inputted tutor ID matches the tutor ID within the Tutors Management System,

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 37 of 59

the tutor record will be deleted. If the tutor with the inputted tutor ID does not exist, then no tutor
records will be deleted from the system.

Figure 40 Delete a tutor record functionality in a linked list

Figure 41 Delete a tutor record functionality in a linked list

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 38 of 59

Figure 42 Delete a tutor record functionality in a linked list

3.0 Results
3.1 Array
3.1.1 Welcome Page
The first time when the Array code in run, the welcome page to tutors management
system will be show up and this system is made only for admin. The administrator user will be
asked to input their password for log in to the system.

Figure 43: Array - Welcome page

3.1.2 Main Menu


After the user inputs their admin password, the user will be directed to the main menu for the
user to choose what functionality they want to use. There are 9 types of function that can be
choose.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 39 of 59

Figure 44: Array - Manager Main Menu Figure 45: Array - Admin Main Menu

3.1.3 Add a Tutor Record


If the user chooses first functionality where its “Add Tutor Records”, the menu for adding the
tutor will be show, and the user will be asked to enter the details of the new tutor.

Figure 46 add a tutor record

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 40 of 59

3.1.4 Display All Records


The user can choose either to display tutors all at once, or one by one.”. All tutor details inside
the array will be printed, and then the user will be redirected back to the main menu.

Figure 47 display tutor record

Figure 48 display tutor record

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 41 of 59

Figure 49 display tutor record

3.1.5 Search a Tutor by Tutor ID


If the user admin, choose third functionality where its “Search a Tutor by Tutor ID”. The user
will be asked to input the Tutor ID that they want to search. Figure below, the user is trying to
search for a tutor that we have added in the beginning.

Figure 50 search tutor by tutor ID

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 42 of 59

3.1.6 Search Tutors by Overall Performance (Rating)


If the user admin choose fourth functionality where its “Search Tutor by Rating”. The user will
be asked to input the Tutor Rating that they want to search. Figure below, the user tried to search
tutor with 5 rating and the system is printing all the tutor’s details with rating of 5

Figure 51 search tutor by rating

3.1.7 Sort and Display by Tutors ID in ascending order


If the user admin choose fifth functionality where its “Sort and Display Tutor by Tutor ID”. All
the sorted tutor id details will be showed as figure below.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 43 of 59

Figure 52 sort and display by tutor ID

3.1.8 Sort and Display by Tutors Hourly Pay Rate in ascending order
If the user chooses sixth functionality where its “Sort and Display Tutor by Tutors Pay Rate”.
All the sorted tutors pay rate details will be printed as figure below.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 44 of 59

Figure 53 sort and display by hourly pay rate

3.1.9 Sort and Display by Tutors Overall Performance in ascending order


If the user chooses the seventh option which is “Sort and Display Tutor by Tutors Performance”.
All the sorted tutors’ details will be printed as it can be seen below.

Figure 54 sort and display tutors by tutor performance

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 45 of 59

3.1.10 Modify a Tutor Record


If the user chooses the 8th option, he can modify a tutor record by inserting the tutor’s ID, and the
user can choose which record he wants to modify.

Figure 55 modify tutor

3.1.11 Delete a Tutor Record


The user can choose the option number 9 to delete a record from the system. First the system will
provide the user with tutors who was terminated for over 6 months, then the user can choose
which record of these tutors he wants to delete. Finally, he needs to confirm the deletion and he
will then be directed to the main menu.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 46 of 59

Figure 56 delete a tutor record

3.2 Linked List


3.2.1 Login page
The login page will allow the users to login either as an admin or HR manager. The main
difference between both roles is that record updation and deletion can only be performed by the
HR manager. After the role has been selected, the user needs to enter the email and password.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 47 of 59

Figure 57 Login page

3.2.2 Main menu


As the logged in account is identified as the HR manager, all functionalities are shown as
follows.

Figure 58 Main menu

3.2.3 Add a tutor record


The user can add a record by choosing the first option from the main menu. First he needs to
specify the number of tutors that he wants to add, then he can proceeds with entering the records.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 48 of 59

Figure 59 add a tutor record

3.2.4 Display all records


This functionality will display all tutor records stored within the system by traversing through all
the tutor records.

Figure 60 Display all records

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 49 of 59

3.2.5 Search a tutor by tutor ID


Within this functionality, the user needs to enter the tutor ID to perform the searching.
Afterward, the found record will be displayed. The strength of this approach is located at the
searching algorithm used, which is the Linear Search algorithm. This algorithm has a time
complexity of O(N).

Figure 61 Search a tutor by tutor ID

3.2.6 Search tutors by overall performance (Rating)


Option 4 in the main menu will let the user to search for all the records in the system that have
the performance rating that the user chooses.

Figure 62 search tutor by overall performance

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 50 of 59

3.2.7 Sort and display by tutors ID in ascending order


When the user choose option 5, he will get the records sorted based on tutors ID in ascending
order. then he can move between the pages to view other records.

Figure 63 sort and display by tutors ID

3.2.8 Sort and display by tutors hourly pay rate in ascending order
Within this functionality, the tutor records will be displayed one-by-one to enable the users to
move back and forth. In addition, the tutor records have been sorted using the Bubble Sort
algorithm. The main weakness is located at the use of the Bubble Sort algorithm because the
time complexity is O(N2).

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 51 of 59

Figure 64 Sort and display by tutors' hourly pay rate

Figure 65 Sort and display by tutors' hourly pay rate

3.2.9 Sort and display by tutors’ overall performance in ascending order


This functionality allows the user to display the tutor records based on the overall performance
(rating). The records displayed will first be sorted using the merge sort, which has a time
complexity of O(N* log N).

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 52 of 59

Figure 66 Sort and display by tutors' overall performance

Figure 67 Sort and display by tutors' overall performance

3.2.10 Modify a tutor record


Within this functionality, the user will be able to modify the tutor’s phone number and home
address. In the searching process, the Linear Search algorithm is implemented because it has a
better time complexity for a singly linked list implementation.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 53 of 59

Figure 68 Modify tutor's phone number

Figure 69 Modify tutor's home address

Results after modification:

Figure 70 Modified phone number

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 54 of 59

Figure 71 Modified home address

3.2.11 Delete a tutor record


In this functionality, the list of tutors that can be deleted will be displayed. The tutors displayed
will be determined based on their termination date. If it has been around 6 months, then the
records can be deleted.

Figure 72 Delete a tutor record

Results after deletion:

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 55 of 59

Figure 73 records after deletion

4.0 Conclusion
In conclusion, the Tutors Management System is developed using two data structures, which are
an array of structures and a linked list. For the system to be working properly, there are nine
functionalities that must be fulfilled. In each of these functionalities, various algorithms are
implemented. This includes, sorting algorithms, searching algorithms, etc. However, there are
some limitations regarding the system developed. The first limitation is located at the algorithms
used. Some of the algorithms implemented may not have the best time complexity. For the array
implementation, the limitation occurs when performing insertion and deletion because there is a
need to shift all the following elements. On the other hand, a linked list implementation also has
a limitation, which is extra memory usage.

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 56 of 59

5.0 Future Works


In the future, for this system, we will add something more beneficial functionality and better data
storing algorithms. For instance, we will use txt file as the way to store data, because with txt file
we can do a lot of things, and the data can be stored forever without using the dummy data
anymore. Moreover, we can also make a system for the user, not just only for admin. The user
can either rate the tutor by themselves and add comment or maybe the user can do their
attendance for the tutor class.

6.0 Reflection
After working on this assignment, and using different types of searching and sorting algorithm,
the team understanding of data structures is much clearer. The team has gained more experience
while working with arrays, and although the concept of linked list is new to us, we were able to
build our skills in it and successfully apply it in our project.

7.0 References
Pedamkar, P. (n.d.). Enum in C++. Retrieved from Educba: https://www.educba.com/enum-in-c-
plus-plus/
Singh, C. (n.d.). Enumeration in C++. Retrieved from BeginnersBook:
https://beginnersbook.com/2017/09/cpp-enumeration/
Khandelwal, V. (2021, October 28). What is Merge Sort Algorithm: How does it work, its
Advantages and Disadvantages . Retrieved from SimpliLearn:
https://www.simplilearn.com/tutorials/data-structure-tutorial/merge-sort-
algorithm#:~:text=Merge%20sort%20is%20one%20of,sublists%20into%20a%20sorted
%20list.
Fast and slow pointer technique in Linked List . (n.d.). Retrieved from OpenGenus:
https://iq.opengenus.org/fast-and-slow-pointer-technique/#:~:text=The%20fast%20and
%20slow%20pointer,linked%20list%2C%20or%20a%20graph.
Bubble Sort . (2022). Retrieved from GeeksForGeeks: https://www.geeksforgeeks.org/bubble-
sort/

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 57 of 59

Difference between Singly linked list and Doubly linked list . (2022, April 12). Retrieved from
GeeksForGeeks: https://www.geeksforgeeks.org/difference-between-singly-linked-list-
and-doubly-linked-list/
Sharma, A. (2021, August 21). Difference between a Singly Linked List and a Doubly Linked
List . Retrieved from PrepBytes: https://www.prepbytes.com/blog/linked-list/difference-
between-a-singly-linked-list-and-a-doubly-linked-list/#:~:text=Difference%20between
%20Singly%20linked%20list%20and%20Doubly%20linked%20list&text=A%20Singly
%20Linked%20has%20nodes,link%20of%20the%20next
Bubble Sort for Linked List by Swapping nodes . (2020, March 04). Retrieved from
GeeksForGeeks: https://www.geeksforgeeks.org/bubble-sort-for-linked-list-by-swapping-
nodes/
Binary Search on Singly Linked List . (2021, June 21). Retrieved from GeeksForGeeks:
https://www.geeksforgeeks.org/binary-search-on-singly-linked-list/
Linear Search vs Binary Search . (2021, June 28). Retrieved from GeeksForGeeks:
https://www.geeksforgeeks.org/linear-search-vs-binary-search/
Yesmin, F. (2021). How to split string in C++ . Retrieved from Linux Hint:
https://linuxhint.com/split-string-cpp/
How to convert a string to an int in C++ . (n.d.). Retrieved from Educative:
https://www.educative.io/edpresso/how-to-convert-a-string-to-an-int-in-cpp
C++ localtime() . (n.d.). Retrieved from Programiz: https://www.programiz.com/cpp-
programming/library-function/ctime/localtime
Merge Sort for Linked Lists . (2021, November 26). Retrieved from GeeksForGeeks:
https://www.geeksforgeeks.org/merge-sort-for-linked-list/
Mallawaarachchi, V. (2020, February 28). 8 Common Data Structures every Programmer must
know. Retrieved from Towards Data Science: https://towardsdatascience.com/8-common-
data-structures-every-programmer-must-know-171acf6a1a42

8.0 Appendix
Appendix A. Workload Matrix
Name Handika Harianto Ehab Nader Badawi Jasson Armendra

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 58 of 59

Ew Jong Abughazaleh Salim (TP058075)


Section (TP061297) (TP058629)
Introduction
Brief introduction 33% 33% 34%
about the system
Source code of data 34% 33% 33%
structure/class
Explanation of Data 34% 33% 33%
Structures and
Classes
Justification 33% 34% 33%
Implementation
Source code of each 34% 33% 33%
algorithm
Brief Explanation 33% 34% 33%
About Algorithms
Provide Justification 33% 33% 34%
on your decision
Result
System Input/ 33% 34% 33%
Output Screenshot
Brief explanation 33% 33% 34%
about screenshots
Strength and 34% 33% 33%
weaknesses of the
proposed approaches
Conclusion, Future
Works, and
Reflection
A brief summary 34% 33% 33%
about your system
Brief description of 33% 34% 33%
your future works
Briefly describe 33% 33% 34%
your
experience/feedback
on the assignment

Level 2 Asia Pacific University of Technology and Innovation 2022


Data Structures (CT077-3-2-DSTR) Page 59 of 59

Signature

Level 2 Asia Pacific University of Technology and Innovation 2022

You might also like