0% found this document useful (0 votes)
22 views20 pages

FINAL REPORT LeTrungDuc BH00954 DSA

Uploaded by

shinjunglee1007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views20 pages

FINAL REPORT LeTrungDuc BH00954 DSA

Uploaded by

shinjunglee1007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

ASSIGNMENT FINAL REPORT

Qualification Pearson BTEC Level 5 Higher National 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 Le Trung Duc Student ID BH00954

Class SE06205 Assessor name Ngo Thi Mai Loan

Plagiarism
Plagiarism is a particular form of cheating. Plagiarism must be avoided at all costs and students who break the rules, however innocently, may be
penalised. It is your responsibility to ensure that you understand correct referencing practices. As a university level student, you are expected to use
appropriate references throughout and keep carefully detailed notes of all your sources of materials for material you have used in your work,
including any material downloaded from the Internet. Please consult the relevant unit lecturer or your course tutor if you need any further advice.

Student Declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I declare that the work
submitted for assessment has been carried out without assistance other than that which is acceptable according to the rules of the specification. I
certify I have clearly referenced any sources and any artificial intelligence (AI) tools used in the work. I understand that making a false declaration is
a form of malpractice.

Student’s signature Duc


Grading grid

P1 P2 P3 P4 P5 P6 P7 M1 M2 M3 M4 M5 D1 D2 D3 D4
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

Signature & Date:


Table of Contents
A. Introduction.......................................................................................................................................................5
B. Content...............................................................................................................................................................5
I. Definition if abstract data type(ADT)..........................................................................................................5
II. Design specification for data structures explaining the valid operations that can be carried out on
the structures (P1).................................................................................................................................................5
1. Linked List.................................................................................................................................................5
2. Stack...........................................................................................................................................................9
3. Queue........................................................................................................................................................11
III. Determine the operations of a memory stack and how it is used to implement function calls in a
computer. (P2)......................................................................................................................................................13
1. Memory Stack..........................................................................................................................................13
2. The operations of a memory stack..........................................................................................................14
3. How it is used to implement function calls in a computer.....................................................................15
IV. Using an imperative definition, specify the abstract data type for a software stack. (P3)..................16
1. Definition..................................................................................................................................................16
2. Example stack implementation using array or linked list....................................................................16
V. Explain and get a reasonable example with Queue (M1)..........................................................................19
VI. Compare the performance of 2 sorting algorithms (M2)......................................................................19
VII. Advantages of encapsulation and information hiding when using ADT (M3)....................................19
C. Conlusion..........................................................................................................................................................19
D. References........................................................................................................................................................20
A.Introduction
I have not received any assistance from this quest about the ADT that requested it. It offers a wealth of
detailed information about ADT, covering its definition, representation, stack memory, and other features.
Furthermore, Ill use the description to write software for the stack's abstract data type.

Subsequently, I discovered a few practical uses for ADT and stacks. We will discuss the benefits of
utilizing ADT for data encapsulation and obfuscation in the final section. I am now able to send the task
request and read the ADT request script.

B.Content
I. Definition if abstract data type(ADT)
A type (or class) for objects whose behavior depends on a range of inputs and outputs is known as an
abstract data type, or ADT. The term "ADT" describes the necessary acts, not the method by which they
must be canied out. There is a lack of specification on the chosen algorithms, the operations to be carried
out, and the data anangement in memory. It's named "abstract" because it offers an
implementationunrelated point of view. An abstraction of a data structure that offers just operations and
conceals the implementation of those operations is called an abstract data type (ADT). They are frequently
used in object oriented programming languages and may be used to create classes and objects.

II. Design specification for data structures explaining the valid operations that can be
carried out on the structures (P1)
1. Linked List
a. Definition
A Linked List is a linear data structure where each element (called a node) contains a data part and a reference (or
pointer) to the next node in the sequence. This allows for efficient insertion and deletion of elements, as no shifting
of elements is required.

There are four types of linked lists:

- Singly linked lists.

- Doubly linked lists.


- Circular linked lists.
b. Explain operation and working mechainsm
Insertion: Adds a new node at the beginning, end, or any specified position in the list.
Deletion: Removes a node from the beginning, end, or any specified position in the list.
Traversal: Access each node sequentially.
Search: Find a node containing a specified data value.

The linked list works through pointers. The first node is called the head. Each node points to the next
node, forming a chain-like structure. To traverse the list, you start from the head and follow the pointers
until you reach a node that points to null.

c. Code Example
2. Stack
a. Definition
A Stack is an abstract data type that follows the Last In First Out (LIFO) principle. It allows two main
operations: push (adding an item to the top) and pop (removing the item from the top).

b. Explain operation and working mechainsm


 Push: Add an element to the top of the stack.
 Pop: Remove the top element from the stack.
 Peek: Get the top element of the stack without removing it.
 IsEmpty: Check if the stack is empty.
Stacks can be implemented using arrays or linked lists. The addition and removal of items occur at the
same end (the top), making it efficient in terms of both time and space complexity.

c. Code Example
3. Queue
a. Definition
A Queue is a linear data structure that follows the First In First Out (FIFO) principle. The element that is
added first is the one that is removed first.

b. Explain operation and working mechainsm


 Enqueue: Add an element to the end of the queue.
 Dequeue: Remove the element from the front of the queue.
 Front: Get the front element of the queue without removing it.
 IsEmpty: Check if the queue is empty.

Queues can also be implemented using arrays or linked lists. The first element added is the first to be
removed, which is useful in scenarios that require order preservation such as scheduling tasks.
c. Code Example
III. Determine the operations of a memory stack and how it is used to implement function
calls in a computer. (P2)
1. Memory Stack
a. Define
In a Java Thread, stack memory is used to hold local variables for functions and function calls during
runtime. Primitive types, reference types to heap-based objects (reference types), declarations made in
functions, and arguments supplied to functions are examples of local variables. Stack memory is utilized
when a thread is running. The primary contents of stack memory are function calls, method-specific
temporary variables, primitive local variables, and pointers to other objects on the heap that the method is
referring to. One of the major uses of stack ADT is the last-in, first-out (LIFO) data storage technique,
which is always referred to as "stack".

Every time a method call is made in stack memory, a brand-new stack frame is generated to store
pointers to other objects (such an array, String, etc.) and local primitive values in function calls. The
function call terminates with the pop of the stack frame. The operating system limits the size of each
stack.
b. Advantage
 It allows us to manage the data using the Last In First Out (LIFO) concept, which sets it apat from
linked lists and arrays.
 When a function is called, local variables are allocated on a stack, which is promptly released upon
the function's return.
 A stack is used if a variable is not used after that function's bounds.
 This allows you to control memory allocation and deallocation.
 Stack cleaning of objects is done automatically.
 It is hard to corrupt.
 Variables cannot be resized after they are declared.

2. The operations of a memory stack.


Push:

 Description: Adds a new item (stack frame or variable) onto the top of the stack.
 Functionality: When a function is called, all its related information (local variables and return
address) is pushed onto the stack.

Pop:

 Description: Removes the item (top stack frame) from the stack.
 Functionality: When a function completes, the stack frame is popped, and control returns to the
previous function along with its local variables.

Peek (or Top):

 Description: Returns the top item of the stack without removing it.
 Functionality: During execution, it can be used to inspect variables or the return address without
changing the state of the stack.

IsEmpty:

 Description: Checks if the stack is empty.


 Functionality: Determines whether there are active function calls on the stack, assisting in flow
control.

Get Size:

 Description: Returns the current number of items in the stack.


 Functionality: Useful for tracking how many functions are currently active.
3. How it is used to implement function calls in a computer
Function calls in a computer system utilize the memory stack to maintain the current execution context
and manage local variable allocation efficiently. Here’s how it works step-by-step:

a. Function Call Initiation:

When a function is invoked, a new stack frame is created for that function's execution. This frame includes
the return address (where the control should return after the function finishes), local variables, and
parameters passed to the function.

b. Pushing the Stack Frame:

The stack frame for the function call is pushed onto the stack, effectively saving the current state of the
program. This includes:

 Local variable storage (e.g., int a, String name).


 Arguments passed to the function (e.g., foo(int x)).
 The return address (the instruction pointer of where to return after completion).
c. Execution of the Function:

The CPU executes the function using the local variables and arguments stored in the stack frame. The
function can manipulate these variables as needed during its execution.

d. Function Completion:

Upon finishing, the function will typically encounter a return statement. This triggers the process
to pop the stack frame off the stack, removing all local variables and pointers associated with that
function. The return value, if any, may be passed back via the specific data return mechanisms defined by
the language.

e. Control Transfer:

The program control transfers back to the previously saved address, which is now at the top of the stack
(the calling function). The caller can now use the results from the callee (if applicable).

f. Memory Management:

Because of the stack's nature, once the function returns, the memory occupied by the local variables is
automatically reclaimed, reducing the risk of memory leaks and fragmentation.
IV. Using an imperative definition, specify the abstract data type for a software stack.
(P3)
1. Definition
An Abstract Data Type (ADT) Stack can be defined using an imperative specification, where the operations are
explicitly stated. Here is how the stack can be described:

A Stack is a collection of elements with the following operations:

 Push(x) : Adds the element x to the top of the stack.


 Pop () : Removes and returns the element from the top of the stack.
 Peek () : Returns the element at the top of the stack without removing it.
 isEmpty () : Returns true if the stack is empty, otherwise returns false.
 isFull () : (Optional) Returns true if the stack is full, otherwise returns false.

These operations adhere to the Last In, First Out (LIFO) principle, where the last element added is the first one to
be removed.

2. Example stack implementation using array or linked list


ArrayStack
LinkedListStack
V. Explain and get a reasonable example with Queue (M1)
VI. Compare the performance of 2 sorting algorithms (M2)
VII. Advantages of encapsulation and information hiding when using ADT (M3)

C.Conlusion
Abstract Data Types (ADTs) are essential in systems development as they provide a clear, high-level
representation of data and its associated operations. By defining a formal specification, ADTs bring
precision and consistency to system design, facilitating better error handling, modularity, and
maintainability. Examples such as stacks, queues, and linked lists demonstrate how ADTs can be
implemented through various concrete data structures, allowing developers to choose the most suitable
one for specific needs.

The use of ADTs enables developers to focus on the behavior of data rather than implementation
details, promoting robust and scalable system development. This abstraction not only enhances
collaboration among development teams but also supports the creation of flexible software that can adapt
to changing requirements without extensive rework. Overall, ADTs play a crucial role in streamlining the
development process and ensuring the integrity and efficiency of software systems.
D.References
[1] Introduction to stacks in Data Structures: Prepinsta (2023) PREP INSTA. Available at:
https://prepinsta.com/data-structures/introduction-to-stacks-in-data-structures/(Accessed: 28 March2024).

[2] Abstract data type in data structures (n.d) Online Courses and eBooks Library. Available at:

Technical Articles & Resources - Tutorialspoint (Accessed: 28 March 2024).

[3] GfG (2023) Abstract data types, GeeksforGeeks. Available at:

https://www.geeksforgeeks.org/abstractdata-types/(Accessed: 28 March 2024).

[4] Abstract data type in data structure - javatpoint (no date) www.javatpoint.com. Available at:.
https://www.geeksforgeeks.org/abstractdata-types/(Accessed: 28 March 2024).

[5] (No date)

Chapter 5: Abstraction and abstract data types. Available at:

https://web.engr.oregonstate.edu/~sinisa/courses/OSU/CS261/CS261_Textbook/Chapter05.pdf(Accessed:
28 March 2024).

[6] Datta, W. by: S. (2024) What is Abstract Data Type?, Baeldung on Computer Science. Available at:

https://www.baeldung.com/cs/adt (Accessed: 28 March 2024).

[7] What is Abstract Data Type?: Autoblocks Glossary (no date) Autoblocks. Available at:

https://www.autoblocks.ai/glossary/abstract-data-type (Accessed: 28 March 2024).

You might also like