












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Qualification BTEC Level 5 HND Diploma in Computing
Unit number and title Unit 19 : Data Structures and Algorithms
Submission date 17 April 2022 Date Received 1st submission
Re-submission Date Date Received 2nd submission
Student Name Hồ Ngọc Khánh Student ID GCS
Class GCD0901 Assessor name Phạm Thanh Sơn
Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.
Student’s signature Khanh
Grading grid
Grade: Assessor Signature: Date:
Internal Verifier’s Comments:
IV Signature:
An abstract data type (ADT) is a data type notion or paradigm. ADT eliminates the need for a user to
be concerned about how a data type is implemented. Furthermore, ADT handles the implementation of
functions on a data type. In this section, the user will find preset functions for each data type that are
ready to use for any action.
ADTs are implemented differently in each programming language, employing distinct techniques and
logic. Regardless of language, we can still conduct all of the related operations described for that ADT.
ADTs, for example, are generally implemented in C using structure. In C++ or JAVA, on the other hand, they
are implemented using classes.
ADTs are a common and significant form of data. ADTs are mathematical or logical notions that may
be implemented on many computers using various languages. Furthermore, they are exceedingly
adaptable and do not rely on languages or machinery. (Datta, 2021)
Figure 1 : TYPES OF ADTS
Are a set of objects and procedures that offer their users with well-defined abstract features while
concealing how they are represented in terms of lower-level data representations. When a module is used
Because a Linked List is normally represented by its head pointer, traversing the list to the final node
and then changing the next to last node to the new node is necessary.
In this function, it will insert in the linked list the new data. However, it also will check on the status
of the new nodes, the current nodes and the last nodes to implement them into the linked list.
Figure 2 : CODE FOR INSERTING NEW DATA INTO LINKED LIST
LinkedList: 1 2 3 4 5 6 7
Figure 3 : RESULT FOR CREATION AND INSERTATION
PrintList() is a general-purpose function for traversal that prints any provided list by traversing the
list from head node to final node.
In this function, the program will allow the function to print out all the data in the linked list by
traversing from the head node to the final node of the linked list.
Figure 4 : CODE FOR FUNCTION OF TRAVERSAL
LinkedList: 1 2 3 4 5 6 7 8
Figure 5 : RESULT OF TRAVERSAL
Head
Prev
Tmp
Data Next Data Next Data Next Data Next
Table 3 : SINGLY LINKED LIST DELETION
Follow the steps below to remove a node from the linked list. Look for the key's first appearance in
the list. Now, any of the three criteria can exist:
Case 1 : The key is discovered at the head.
Case 2 : Except at the beginning, the key is discovered in the center or at the end.
4 found and deleted
LinkedList: 2 3 5 6 7 8
10 not found
LinkedList: 2 3 5 6 7 8
Figure 7 : RESULT FOR DELETION BY KEY
Head
Prev
Tmp
Data Next Data Next Data Next Data Next
Table 4 : SINGLY LINKED LIST DELETION AT POSITION
The following are the measures to take:
Case 1 : The position is 0, indicating that the head is to be removed.
Case 2 : The position is larger than 0 but less than the number of items in the list, i.e., in the middle
or at the end, except at the top.
Case 3 : The position is bigger than the list's size, i.e., the location is not found in the list.
Figure 8 : CODE FOR DELETION AT POSITION
LinkedList: 1 2 3 4 5 6 7 8
0 position element deleted
LinkedList: 2 3 4 5 6 7 8
Figure 10 : STACK'S MEMORY MANAGEMENT
A stack is a straightforward last-in-first-out (LIFO) data structure. It is usual to teach stacks to young
computer scientists by imagining a stack of dishes at a cafeteria. In the cafeteria, dishes are only removed
or added to the stack at the top. When we initially enter the cafeteria, one of our first activities is to take
a plate from the top of the stack of plates before proceeding through the line. Similarly, the dishwashers
place each clean plate one at a time on top of the stack. As a result, the last clean plate deposited into the
stack is the first plate a client pulls off the top. It is not permissible to insert or remove a plate from the
stack's center. (Anon., 2017)
The stack pointer on a 64-word stack has 6 bits since 26 = 64. Because SP only has six bits, it cannot
be more than 63. (111111 in binary). When 63 is multiplied by one, the output is zero since 111111 + 1 =
1000000 in binary, but SP can only allow the six least significant bits. When 000000 is decremented by
one, the result is 111111. When the stack is full, the one-bit register Full is set to 1, and when the stack is
empty, the one-bit value EMTY is set to 1. The data register (DR) stores the binary data that will be written
to or retrieved from the stack.
Figure 11 : STACK MEMORY ORGANIZATION ILLUSTRATION
The method-call stack (also known as the program-execution stack) is a data structure that operates
in the background to enable the method call/return mechanism. It also allows for the construction,
maintenance, and removal of the local variables of each called method. (Deitel, 2016)
The running Java program's call stack is represented by three interfaces: Frame, which encapsulates
the data stored in a single stack frame, such as the operand stack and local variables; FrameSource, which
encapsulates the allocation and layout of Frames, controlling things like the argument-passing mechanism;
and Context, which encapsulates the call stack storage and management as well as the locking logic
required by synchronized methods.
In this instance, I will show how method call stack works by this small problem by calculating the
factorial result of a specific number. For the number that equals to one, we will let the program
automatically calculate the factorial result to one and from that we will calculate more on the next bigger
numbers. For example, for Factorial(2), it will equal to 2 * Factorial(1) so we will take the result from the
previous Factorial to calculate and then so on for three and four.
Whenever a user performs an action, capture it and move it to the bottom of the list.
Take the final item on the list when UNDO is issued (essentially, use it a stack, push actions when
user takes one, pop actions when undo is issued)
Using the recorded data, restore the state to what it was before the action was made.
Of course, each application will necessitate a very different concrete implementation.
Because it is often assumed that:
A stack, rather than a double-ended queue, is the standard data structure for storing undo and redo
information. Of course, you'd utilize different stacks for undo and redo data, and simply move objects
between them, i.e.
However, by simply adding and deleting items from the same end of the queue, you may easily utilize
a deque to imitate a stack.
Using a deque for the undo stack has the extra benefit of allowing you to trim the stack when it
becomes too big (e.g., you may want to limit undoes to the last 1,000 actions). Trimming the stack simply
implies deleting things from the opposite end of the stack from where they were inserted.
Figure 13 : TWO CHAR STACKS FOR THE PROGRAM
Figure 14 : CODE FOR WRITE FUNCTION
Figure 15 : CODE FOR UNDO FUNCTION
Figure 16 : CODE FOR REDO FUNCTION
Figure 19 : CODE FOR THE MAIN FUNCTION
Figure 20 : RESULT FOR THE ABOVE PROBLEM
Anon., 2002. Usenix. [Online]
Available at: www.usenix.org
[Accessed 14 April 2022].
Anon., 2017. ICARUS. [Online]
Available at: icarus.cs.weber.edu
[Accessed 14 April 2022].
Datta, S., 2021. Baeldung. [Online]
Available at: www.baeldung.com
[Accessed 11 April 2022].
Deitel, P., 2016. Method-Call Stack. In: C# 6 for Programmers, 6th Edition. s.l.:Pearson.
Desai, A., 2019. Opengenus. [Online]
Available at: iq.opengenus.org
[Accessed 15 April 2022].
Mehta, K., 2022. Scaler. [Online]
Available at: www.scaler.com
[Accessed 15 April 2022].
Poornima, S., 2014. Memory Management by Using the Heap and the Stack in Java, Warangal: s.n.