Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

ASSIGNMENT 1

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 Nguyen Phi Hung Student ID BHAF200124

Class PBIT17102 Assessor name Nguyen Thai Cuong

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:
Table of Contents
I. Create a design specification for data structures explaining the valid operations that can be carried out on
the structures. (P1)....................................................................................................................................................... 3
1. Data Structures ................................................................................................................................................. 3
2. Types of Data Structure .................................................................................................................................... 4
2.1. Linear data structures ............................................................................................................................... 4
2.2. Non-linear data structures ........................................................................................................................ 6
3. Advantages and disadvantage of data structure .............................................................................................. 7
4. Abstract data types ........................................................................................................................................... 7
4.1. Definition .................................................................................................................................................. 7
4.2. List ADT ..................................................................................................................................................... 8
4.3. Stack ADT .................................................................................................................................................. 8
4.4. Queue ADT ................................................................................................................................................ 9
II. Determine the operations of a memory stack and how it is used to implement function calls in a computer
(P2) 9
1. Memory stack ................................................................................................................................................... 9
2. Exception ........................................................................................................................................................ 10
3. Implement function calls in a computer ......................................................................................................... 10
III. Using an imperative definition, specify the abstract data type for a software stack. (P3) ......................... 11
1. Definition of software stack ............................................................................................................................ 11
2. Parts of a software stack................................................................................................................................. 11
IV. Reference ........................................................................................................................................................ 12

I. Create a design specification for data structures


explaining the valid operations that can be carried out
on the structures. (P1)
1. Data Structures
• A data structure is a specialized format for organizing, processing, retrieving, and storing
data. There are several basic and advanced types of data structures, all designed to
arrange data to suit a specific purpose. Data structures make it easy for users to access
and work with the data they need in appropriate ways. Most importantly, data structures
frame the organization of information so that machines and humans can better
understand it.

2. Types of Data Structure


• Data structures are divided into two types:
o Linear data structure
o Non-linear data structure

2.1. Linear data structures


• In linear data structures, the elements are arranged in sequence one after the other.
Since elements are arranged in particular order, they are easy to implement.
• However, when the complexity of the program increases, the linear data structures might
not be the best choice because of operational complexities.
• Popular linear data structures are:
• Array Data Structure:
o In an array, elements in memory are arranged in continuous memory. All the
elements of an array are of the same type. And, the type of elements that can be
stored in the form of arrays is determined by the programming language.
o The following diagram represents an integer array that has 12 elements. The index
of the array starts with 0, so the array having 12 elements has indexed from 0 to
11.

• Stack Data Structure:


o Stacks in Data Structures is a linear type of data structure that follows the LIFO
(Last-In-First-Out) principle and allows insertion and deletion operations from one
end of the stack data structure, that is top. Implementation of the stack can be
done by contiguous memory which is an array, and non-contiguous memory which
is a linked list. Stack plays a vital role in many applications.
o This example allows you to perform operations from one end only, like when you
insert and remove new books from the top of the stack. It means insertion and
deletion in the stack data structure can be done only from the top of the stack. You
can access only the top of the stack at any given point in time.

• Queue Data Structure:


o A queue is defined as a linear data structure that is open at both ends and the
operations are performed in First In First Out (FIFO) order.
o A list in which all additions to the list are made at one end and all deletions from
the list are made at the other end. The element which is first pushed into the
order, the operation is first performed on that.
o Position of the entry in a queue ready to be served, that is, the first entry that will
be removed from the queue, is called the front of the queue(sometimes, head of
the queue), similarly, the position of the last entry in the queue, that is, the one
most recently added, is called the rear (or the tail) of the queue. See the below
figure.
• Linked List Data Structure:
o A linked List is a linear data structure. Unlike arrays, linked list elements are not
stored at a contiguous location; the elements are linked using pointers. They
include a series of connected nodes. Here, each node stores the data and the
address of the next node.
o For example, you have to start somewhere, so we give the address of the first node
a special name called HEAD. Also, the last node in the linked list can be identified
because its next portion points to NULL.

2.2. Non-linear data structures


• A non-linear data structure is another important type in which data elements are not
arranged sequentially; mainly, data elements are arranged in random order without
forming a linear structure.
• Non-linear data structures are further divided into graph and tree based data structures.
• Graph Data Structure:
o In graph data structure, each node is called vertex and each vertex is connected to
other vertices through edges.

• Tree Data Structure:


o Similar to a graph, a tree is also a collection of vertices and edges. However, in tree
data structure, there can only be one edge between two vertices.
3. Advantages and disadvantage of data structure
• Advantages:
o Allows easier processing of data.
o It allows information stored on disk very efficiently.
o These are necessary for designing an efficient algorithm.
o It provides management of databases like indexing with the help of hash tables and
arrays.
o We can access data anytime and anywhere.
o It is secure way of storage of data.
o Graphs models real life problems
o It allows processing of data on software system
• Disadvantages:
o It is applicable only for advanced users.
o If any issue occurs it can be solved only by experts.
o Slow access in case of some data types

4. Abstract data types


4.1. Definition
• Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set
of values 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.

4.2. List ADT


• The data is generally stored in key sequence in a list which has a head structure consisting
of count, pointers and address of compare function needed to compare the data in the
list. The data node contains the pointer to a data structure and a self-referential pointer
which points to the next node in the list.
• The List ADT Functions is given below:
o get() – Return an element from the list at any given position.
o insert() – Insert an element at any position of the list.
o remove() – Remove the first occurrence of any element from a non-empty list.
o removeAt() – Remove the element at a specified location from a non-empty list.
o replace() – Replace an element at any position by another element.
o size() – Return the number of elements in the list.
o isEmpty() – Return true if the list is empty, otherwise return false.
o isFull() – Return true if the list is full, otherwise return false.

4.3. Stack ADT


• In Stack ADT Implementation instead of data being stored in each node, the pointer to
data is stored.
• The program allocates memory for the data and address is passed to the stack ADT.
• The stack head structure also contains a pointer to top and count of number of entries
currently in stack.
o push() – Insert an element at one end of the stack called top.
o pop() – Remove and return the element at the top of the stack, if it is not empty.
o peek() – Return the element at the top of the stack without removing it, if the stack
is not empty.
o size() – Return the number of elements in the stack.
o isEmpty() – Return true if the stack is empty, otherwise return false.
o isFull() – Return true if the stack is full, otherwise return false.

4.4. Queue ADT


• The queue abstract data type (ADT) follows the basic design of the stack abstract data
type.
• Each node contains a void pointer to the data and the link pointer to the next element in
the queue. The program’s responsibility is to allocate memory for storing the data.
o enqueue() – Insert an element at the end of the queue.
o dequeue() – Remove and return the first element of the queue, if the queue is not
empty.
o peek() – Return the element of the queue without removing it, if the queue is not
empty.
o size() – Return the number of elements in the queue.
o isEmpty() – Return true if the queue is empty, otherwise return false.
o isFull() – Return true if the queue is full, otherwise return false.

II. Determine the operations of a memory stack and how


it is used to implement function calls in a computer
(P2)
1. Memory stack
• Memory stacks are linear data structures (locations) used to store data in a computer's
memory. They may also be referred to as queues. Data within a stack must always be of
the same type.
• For example:
2. Exception
• The operations pop and top cannot be performed if the stack is empty.
• A Stack Empty Exception should be thrown if you try to execute pop or top on an empty
stack. Due to a lack of memory, push operations are occasionally unable to complete.
When memory is insufficient, attempting to execute push should result in an out of
Memory Error.

3. Implement function calls in a computer


• Whenever you call one function from another function in programming, the reference of
calling function stores in the stack. When the function call is terminated, the program
control moves back to the function call with the help of references stored in the stack.
• So stack plays an important role when you call a function from another function.

Figure 1: function calls example


III. Using an imperative definition, specify the abstract
data type for a software stack. (P3)
1. Definition of software stack
• A software stack is a collection of independent components that work together to support
the execution of an application. The components, which may include an operating system,
architectural layers, protocols, runtime environments, databases, and function calls, are
stacked one on top of each other in a hierarchy. Typically, the lower-level components in
the hierarchy interact with hardware, while the higher-level components in the hierarchy
perform specific tasks and services for the end user. Components communicate directly
with the application through a series of complex instructions that traverse the stack.

2. Parts of a software stack

• Operating system. The operating system manages the memory and processes within your
computer. The majority of the time, computers will use one of five main systems: macOS,
Microsoft Windows, Linux, Apple iOS, and Android OS.
• Database. Your databases let you create and maintain all the records used in your system.
Popular databases used in stacks include MySQL, Oracle Database, and SQL Server.
• Middleware is software that enables one or more kinds of communication or connectivity
between two or more applications or application components in a distributed network.
IV. Reference
• Software Stack - Definition & Overview - https://www.sumologic.com/glossary/software-
stack/
• What is Software Stack - https://www.geeksforgeeks.org/what-is-software-stack/
• Implementing Stacks in Data Structures - https://www.simplilearn.com/tutorials/data-
structure-tutorial/stacks-in-data-structures
• Function Call Stack Examples - https://cs.gmu.edu/~kauffman/cs222/stack-demo.html
• Stack - https://www.techopedia.com/definition/9523/stack
• Stack Memory - https://www.sciencedirect.com/topics/engineering/stack-memory
• How does memory stacks work in Javascript? - https://www.geeksforgeeks.org/how-
does-memory-stacks-work-in-javascript/
• Introduction to memory and memory units -
https://www.geeksforgeeks.org/introduction-to-memory-and-memory-units/?ref=rp
• What is a non-linear data structure? - https://www.javatpoint.com/what-is-a-non-linear-
data-structure
• What is Linked List - https://www.geeksforgeeks.org/what-is-linked-list/
• Queue Data Structure - https://www.geeksforgeeks.org/queue-data-structure/

You might also like