Professional Documents
Culture Documents
CT077-3-2 DSTR
DATA STRUCTURES
WEIGHTAGE: 50%
INSTRUCTIONS TO CANDIDATES:
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
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.
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.
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.
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.
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.
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.
algorithm. In addition, Linear Search algorithms can be applied to both sorted and unsorted
linked list.
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.
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,
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.
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.
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 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
2.10.1 Array
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
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.
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 38 Functions to update the phone number and home address in a linked list
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.
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.
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 44: Array - Manager Main Menu Figure 45: Array - Admin Main Menu
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.
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).
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.
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/
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
Signature