






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 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Phan Minh Tri Student ID GCD Class GCD0904 Assessor name Pham Thanh Son 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 Grading grid P1 P2 P3 M1 M2 M3 D1 D
Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:
I. Definition ❖ An abstract data type (ADT) is a kind (or class) of object whose behavior is specified by a set of values and a set of actions. The definition of ADT merely says what operations are to be done, not how these operations will be carried out. It does not describe how data will be structured in memory or what algorithms will be utilized to carry out the actions. It is named "abstract" because it provides an implementation-independent perspective. ❖ Abstraction is the technique of offering only the basics while concealing the intricacies. Figure 1 : ADT Model ❖ The user of a data type does not need to understand how that data type is implemented. For example, we have been using primitive values such as int, float, and char data types only with the knowledge that these data types can operate and be performed on without understanding how they are implemented. ❖ Features of ADT
❖ Implementation of Operations Operations Implementation Result Push (element) Pop() Peek() Size() isEmpty() Table 3 : Implementation of Operations
I. Application of Stack in memory (P2)
❖ In Java, stack memory is utilized for static memory allocation and thread execution. It holds basic values unique to a method as well as heap pointers to objects referred to by the method. ❖ This memory is accessed in Last-In-First-Out (LIFO) order. When we call a new method, a new block is added to the stack that contains values relevant to that method, such as primitive variables and object references. ❖ When the method completes its execution, the relevant stack frame is flushed, the flow returns to the caller method, and space is made available for the following method.
❖ It expands and contracts when additional methods are called and returned. ❖ Variables in the stack live only for the duration of the method that generated them. ❖ When the method completes execution, it is automatically allocated and deallocated. ❖ Because each thread runs on its own stack, this memory is thread safe.
Figure 2 : Example Code
❖ When we enter the main() function, a space in stack memory is allocated to hold primitives and pointers to this method. Stack memory contains the primitive value of integer id directly. ❖ The call from main() to the parameterized constructor Person(int, String) allocates additional memory on top of the previous stack. The caller object's this object reference in stack memory. The stack memory primitive value id ❖ The main function then calls the static buildPerson() method, which allocates more stack memory on top of the existing one. This will save variables in the same manner as before. Figure 3 : Demonstration for Example II. Application of an ADT (P3) ❖ There are several varieties of ADT, each with its unique use in a certain circumstance. In this part, I will concentrate on ADT use, particularly ArrayList. ArrayList is the java.util package's implementation of the List interface. It keeps the collection of things in the sequence in which they were inserted. ArrayList saves the object and dynamically expands the list size. As a result, the array list is a resizable array. ❖ Characteristics of ArrayList
❖ Add () Function: If we attempt to add an element to the ArrayList using the add () function, Internally, it determines whether the new element may be stored. Otherwise, the capacity will be increased by one and a new element will be added to end of the list. Figure 6 : Add Function ❖ Insert () Function: If we try to add an element to the ArrayList using the insert () function, Internally, it determines whether the new element may be stored. Otherwise, the capacity will be increased by one and a new element will be added after position that user specify before where the position is in the ArrayList. Or not, the application will throw Exception. Figure 7 : Insert Function
❖ Get () Function: If we want to get an element to the ArrayList using the get () function, Internally, it determines whether the element is existed in the list and return it to screen. Otherwise, the application will throw Exception. Figure 8 : Get Function ❖ I will test functionality of ArrayList. The scenario of the test is when user do CRUD function with application. Figure 9 : Code for testing