Docsity

Assignment for Data Structures and Algorithms - 1649, Assignments of Data Structures and Algorithms

Toggle sidebar
bg1
ASSIGNMENT 1 FRONT SHEET
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
GCD201632
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
D2
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Assignment for Data Structures and Algorithms - 1649 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

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

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:

Table of Contents

  • CHAPTER 1 – Abstract Data Type – ADT (P1)
    • I. Definition
    • II. Examples of Stack ADT
  • CHAPTER 2 – ADT Usages
    • I. Application of Stack in memory (P2)
        1. Definition
        1. Key Features of Stack Memory
        1. Stack Memory Example................................................................................................................................
    • II. Application of an ADT (P3)
  • References
  • Figure 1: ADT Model Table of Figures
  • Figure 2: Example Code
  • Figure 3: Demonstration for Example...........................................................................................................................
  • Figure 4: List Interface
  • Figure 5: ArrayList Class
  • Figure 6: Add Function
  • Figure 7: Insert Function
  • Figure 8: Get Function
  • Figure 9: Code for testing
  • Figure 10: Result after testing.....................................................................................................................................
  • Table 1: Operations in Stack ADT..................................................................................................................................
  • Table 2: Code Snippet of Operations
  • Table 3: Implementation of Operations

CHAPTER 1 – Abstract Data Type – ADT (P1)

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

  • Abstraction : The user is not required to understand the implementation of the data structure.
  • Better Conceptualization : ADT improves our understanding of reality.
  • Robust : The application is robust and can detect mistakes. ❖ As a result, a user only must know what a data type can accomplish, not how it will be implemented. Consider ADT to be a black box that conceals the data type's underlying structure and design. Now, I will discuss specifically about Stack ADT

❖ Implementation of Operations Operations Implementation Result Push (element) Pop() Peek() Size() isEmpty() Table 3 : Implementation of Operations

CHAPTER 2 – ADT Usages

I. Application of Stack in memory (P2)

1. Definition

❖ 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.

2. Key Features of Stack Memory

❖ 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.

3. Stack Memory Example

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

  • The object saved in ArrayList is in insertion order.
  • ArrayList is used to hold a collection of objects whose size grows dynamically.
  • It is a dynamic array that expands when elements are added and contracts when elements are removed.
  • ArrayList holds objects with null values.
  • ArrayList is not synced.
  • These are not sorted.

❖ 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