0% found this document useful (0 votes)
55 views13 pages

1649 - Assignment 1 - NMT - GCH17392

The document is an assignment front sheet for a BTEC Level 5 HND Diploma in Computing unit on data structures and algorithms. It includes the student's name, ID number, class, assessor name, and a declaration that the assignment is the student's own work. It also lists the grading criteria that will be used to evaluate the assignment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views13 pages

1649 - Assignment 1 - NMT - GCH17392

The document is an assignment front sheet for a BTEC Level 5 HND Diploma in Computing unit on data structures and algorithms. It includes the student's name, ID number, class, assessor name, and a declaration that the assignment is the student's own work. It also lists the grading criteria that will be used to evaluate the assignment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 19: Data Structures and Algorithms

Submission date 06/04/2022 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name NGUYEN MINH TIEN Student ID GCH17392

Class GCH0905 Assessor name DO HONG QUAN

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
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

IV Signature:
Contents
Introduction .................................................................................................................................................... 4
Part I ............................................................................................................................................................... 4
1. Abstract Data Type (ADT) ..................................................................................................................... 4
2. Stack ADT .............................................................................................................................................. 4
3. Stack Memory......................................................................................................................................... 6
4. Queue ADT ............................................................................................................................................. 9
Part II ............................................................................................................................................................ 12
1. Explanation on how to specify an abstract data type using the example of software stack ................. 12
References .................................................................................................................................................... 13

List of figures
Figure 1: ADT ................................................................................................................................................ 4
Figure 2: Push & Pop in Stack ....................................................................................................................... 5
Figure 3: Stack Operations ............................................................................................................................. 6
Figure 4: Recursion Code ............................................................................................................................... 9
Figure 5: Queue ADT ..................................................................................................................................... 9
Figure 6: Operations of Queue ..................................................................................................................... 11
Introduction
A data structure is a group of data elements that provide an efficient way of storing and organizing data in
a computer so that this data can be best used. Some examples of data structures include arrays, linked lists,
stacks, and queues. This concept is widely used in almost all aspects of computer science, including
operating systems, compiler design, artificial intelligence, and several others. In this report, I will present
stacks, queues, and how to represent the abstract data form using the software stack as an example.

Part I
1. Abstract Data Type (ADT)
Abstract Data type (ADT) is a type (or class) for objects whose behaviour is defined by a set of value and
a set of operations.

The definition of ADT only mentions what operations are to be performed but not how these operations
will be implemented. It does not specify how data will be organized in memory and what algorithms will
be used for implementing the operations. It is called “abstract” because it gives an implementation-
independent view. The process of providing only the essentials and hiding the details is known as
abstraction. (GeeksforGeeks, 2019)

Figure 1: ADT

For example, a List is an abstract data type that is implemented using a dynamic array and linked list. A
queue is implemented using linked list-based queue, array-based queue, and stack-based queue. A Map is
implemented using Tree map, hash map, or hash table.

2. Stack ADT
Stack is a linear data structure in which the insertion and deletion operations are performed at only one
end. In a stack, adding and removing of elements are performed at a single position which is known as
"top". That means, a new element is added at top of the stack and an element is removed from the top of
the stack. In stack, the insertion and deletion operations are performed based on LIFO (Last In First Out)
principle. (BTech Smart Class, 2019)

push() and Pop() are two basic operations of a stack. Stack initialization, use, and destruction are all
examples of stack operations. In addition to these basic pieces, a stack is used for these two main
processes.

 Push (store) an element on the stack using push().


 Remove (access) an element from the stack with pop().

Figure 2: Push & Pop in Stack

To cater to the proper use of the stack, we must further assert its state. So the following processes are
applied to Stacks.

 peek() returns the stack's top data piece without deleting it.
 isFull() determines whether the stack is full.
 isEmpty() to check if the stack is empty.
Figure 3: Stack Operations

Applications of Stack

 Decimal to Binary Conversion: When we convert a decimal number to binary, we divide this
decimal number by 2 and write the remainder in the reverse order in which it was produced. Using
the stack, we save the remainder after each division in turn and after the division operation is
finished, reading the last stack will give the binary representation we are looking for.
 Calculate the value of a suffix algebraic expression. Evaluating Expressions: The stack is used to
evaluate prefix, suffix, and prefix expressions.

3. Stack Memory
Stack memory is a memory usage mechanism that allows the system memory to be used as temporary data
storage that behaves as a first-in-last-out buffer. One of the essential elements of stack memory operation
is a register called the Stack Pointer. The stack pointer indicates where the current stack memory location
is, and is adjusted automatically each time a stack operation is carried out. (Yiu, 2015)

*Example of how to implement function calls in a computer


In computer science, Recursion is a method of solving a computational problem where the main solution
is dependent on solutions to smaller instances of the same problem until a certain condition is satisfied, at
which point the program receives the expected result. Recursion solves such recursion problems by using
functions that call themselves from within their own code.

Recursion in java is a process where a method calls itself repeatedly. A method in java that calls itself is
called a recursive method. It makes the code compact but complex to understand. When a function is
called, the values as real arguments must be initialized. This leads to the system being able to restart the
program's execution after its execution is complete. To avoid a recursive call, certain requirements must
be met in the system. Otherwise, the procedure will be considered infinite. We use the if ... else
declaration to pause the recursive call in the process.

Example: Calculate the factorial of a number n (n>= 0). Know that 0! = 1.

We can see a rule that n! = (n-1)!*n, which (n-1)! = (n – 2)!*n-1, and so on, we will generalize this
problem by recursion.

The factorial() method is calling itself. Initially, the value of n is 4 inside factorial(). On the next recursive
call, the factorial() method will be called with the value 3. This process continues until n is 0.
Figure 4: Recursion Code

4. Queue ADT
The queue is a linear data structure in which the insertion and deletion operations are performed at two
different ends. In a queue data structure, adding and removing elements are performed at two different
positions. The insertion is performed at one end and deletion is performed at another end. In a queue data
structure, the insertion operation is performed at a position which is known as 'rear' and the deletion
operation is performed at a position which is known as 'front'. In the queue data structure, the insertion and
deletion operations are performed based on FIFO (First In First Out) principle. (BTech Smart Class, 2020)

Figure 5: Queue ADT

Queue features include creating or defining a queue, using it, and completely removing it from memory.
We will cover the basic operations used in the queue:

 enqueue() is a function that adds (stores) a new item to the queue.


 dequeue()is a function that removes (access) an item from the queue
 front() is a function that returns the first item in the queue.
 rear() is a function to get the final item in the queue.
 size() is a function that returns the number of elements in the queue.
 isEmpty() is a function that returns true if the queue is empty, otherwise, returns false
Figure 6: Operations of Queue
Application of Queue:

 Manage requests on a single shared resource like CPU scheduling and disk scheduling.
 Real-time system or hardware interrupt handling.
 Handling website traffic.
 Routers and switches in the network.
 Maintain playlists in the media player.

Part II
1. Explanation on how to specify an abstract data type using the example of software stack

The functions inside the building are obscured when performing. Data types can be created according to a
uniform principle. Other functions that use the structure, or client code, can use the interface provided by
functions already implemented on the structure. Each variable command and function has its own
implementation. Particularly for structs that do not use an object-oriented implementation, there is another
method. This approach has advantages such as ignoring algorithmic complexity, allowing to swap
different implementations of a struct without changing the actions observed by client code in the main
interface. A unit or package containing an implementation that can be independently modified and built in
several compiled languages without the need to recompile the client code. The rebuild only happens when
the interface has been changed.

Stack ADT

 Top (S: Stack, i, r: Item)


o Pre-condition: S is not full.
o Post-condition: r = i after i (top of Stack) has been popped off Stack.
o Error: Stack is empty → Message: Stack underflow.
 Push (S: Stack, i: Item)➢ Pre-condition: S is not full.
o Post-condition: top(S) = i and size of S = n + 1.
o Error: Stack is full → Message: Stack overflow.
 Pop (S: Stack; i, r: Item)
o Pre-condition: S.size() > 0 and top(S) = i.
o Post-condition: size of S = n – 1 and top(S) = r
o Error: S.size() <= 0 → Message: Stack is empty.
 is_empty(S: Stack): s: bool
o Pre-condition: true
o Post-condition: s = (size(S) = 0)
 is_full(S: Stack): s: bool
o Pre-condition: true
o Post-condition: s = (size(S) = S.max_size)

References
BTech Smart Class. (2019). Retrieved from http://www.btechsmartclass.com/data_structures/stack-adt.html

BTech Smart Class. (2020). Retrieved from http://www.btechsmartclass.com/data_structures/queue-


adt.html#:~:text=Queue%20is%20a%20linear%20data,is%20performed%20at%20another%20end.

GeeksforGeeks. (2019, Sep 19). Retrieved from https://www.geeksforgeeks.org/abstract-data-types/

Yiu, J. (2015). ScienceDirect. Retrieved from https://www.sciencedirect.com/topics/engineering/stack-memory

You might also like