Professional Documents
Culture Documents
Unit number and title Unit 19: Data Structures and Algorithms
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.
1
Grading grid
P1 P2 P3 M1 M2 M3 D1 D2
2
Summative Feedback: Resubmission Feedback:
IV Signature:
3
Table of Contents
Introduction...................................................................................................................................................................5
P1 Create a design specification for data structures explaining the valid operations that can be carried out on
the structures.................................................................................................................................................................5
Using an imperative definition, speccify the abstract data type for a software stack ....................................................5
- Abstract Data Type (ADT):...............................................................................................................................5
Stack ADT:..........................................................................................................................................................6
Compare the performance of two sorting algorithms...............................................................................................8
Analyse the operation, using illustrations, of two network shortest path algorithms, providing an example of each.
............................................................................................................................................................................... 14
P2 Determine the operations of a memory stack and how it is used to implement function calls in a computer........16
Memory Stack:......................................................................................................................................................16
Operations.............................................................................................................................................................17
Exception...............................................................................................................................................................18
Application:...........................................................................................................................................................18
Method calls and the implementation by using stack.............................................................................................18
Implement Stack by Array in Java:........................................................................................................................19
P3. Using an imperative definition, specify the abstract data type for a software stack.............................................20
Definition of software stack:..................................................................................................................................20
Parts of a software stack........................................................................................................................................20
Five Software Stack Examples:.............................................................................................................................21
References................................................................................................................................................................. 23
4
Introduction
Hello everyone, my name is Nguyen Hai Anh, and I work as an in-house software developer at Softnet
Development Ltd. Today, I'm excited to share some insights into the world of Abstract Data Types
(ADTs) and how they can significantly impact the design, development, and testing of software solutions.
Our company is currently engaged in a collaborative service provisioning development project, and we
have been entrusted with a crucial role in designing and developing a middleware solution to interface
with various computer provisioning interfaces and the telecom provisioning network. One of the
fundamental concepts we'll be focusing on is the use of ADTs in this project.
The process of providing only the essentials and hiding the details is known as abstraction.
5
The user of data type does not need to know how that data type is implemented, for example, we have
been using Primitive values like int, float, char data types only with the knowledge that these data type can
operate and be performed on without any idea of how they are implemented.
So a user only needs to know what a data type can do, but not how it will be implemented. Think of ADT
as a black box which hides the inner structure and design of the data type. Now we’ll define three ADTs
namely List ADT, Stack ADT, Queue ADT. [objects?, W., 2023]
Stack ADT:
- A stack is a linear data structure in which the insertion of a new element and removal of an
existing element takes place at the same end represented as the top of the stack. [objects?, W., 2023]
6
Figure 2: LIFO (Last In First Out)
- Example: Browser History Management: Web browsers often use a stack to track the browsing
history of users. Each URL visited by the user is added to the stack when they navigate to a new webpage.
When the user requests to go back or navigate to a previous page, the browser uses the stack to manage
and display the previously visited URLs.
7
Compare the performance of two sorting algorithms.
1. Introduction to sorting algorithms.
- A Sorting Algorithm is used to rearrange a given array or list of elements according to a comparison
operator on the elements. The comparison operator is used to decide the new order of elements in the
respective data structure. [GeeksforGeeks. 2023]
1.2. Explanation of the importance of sorting in data processing.
- Efficient Searching: Sorting enables quicker and more efficient searching of data. When data is ordered,
searching in data structure provides algorithms like binary search that can be employed to dramatically
reduce search time compared to unsorted data.
- Improved Retrieval: In various applications, including databases and information retrieval systems, sorted
data can be retrieved faster. This is crucial for systems handling large datasets that require rapid access to
specific information.
- Algorithm Performance: Many algorithms perform optimally on sorted data. Sorting enhances the
efficiency of algorithms like merge sort and quicksort, resulting in faster processing times.
- Identifying Patterns: Sorted data makes patterns and trends more apparent, aiding in data analysis. It
simplifies tasks like identifying outliers, understanding distributions, and drawing meaningful insights.
[GeeksforGeeks. 2023]
8
Figure 4: Buble sort code
9
Figure 5: Buble sort code
- The first “for” loop: beginning with i = index position 0, i is less than the length of arr - 1
- Assume Swapped = false to check whether the array is completely sorted or not
- The second “for” loop: with j = index position 0, i is less than the length of arr - i - 1
- if arr[j] is greater than arr[j + 1]. If this condition is true, it means that the elements are out of order, and
they are swapped using a temporary variable “temp”.
- After swapping, swapped is set to true to indicate that at least one swap occurred during this pass.
- After the inner loop finishes, there is a check if (!swapped) to see if any swaps were made during this
pass. If swapped is still false, it means that no swaps were made in this pass, and the array is already
sorted. In that case, the sorting process terminates early with the break statement.
10
If the key element is smaller than its predecessor, compare it to the elements before
Move the greater elements one position up to make space for the swapped element.
- The codes:
11
Figure 8: Code insertion sort
- The “for” loop: This loop iterates over the array from i = 1 to i = n - 1. It represents the index of the
element that we want to insert into the sorted portion of the array.
- Inside the loop, int key = arr[i]; stores the value of the current element at index “i” in the variable key.
- int j = i - 1; This line initializes a variable “j” to the index just before the current element “i”. This variable
will be used to compare the key with elements in the sorted portion of the array and shift elements to make
space for the key.
- The “while” loop: This loop runs as long as “j” is >= 0 and the element at index arr[j] is greater than the
key.
- Inside the “while” loop, arr[j + 1] = arr[j]; move the element at index “j” one position to the right to make
space for the key.
- j = j - 1;: This decrements “j” to move further left in the sorted portion of the array.
- After the while loop, arr[j + 1] = key; inserts the key into its correct sorted position, as all elements to its
left are smaller than it.
12
Figure 9: Code insertion sort
13
Analyse the operation, using illustrations, of two network shortest path
algorithms, providing an example of each.
2. Introduction to network shortest path algorithms.
Network shortest path algorithms are a fundamental part of graph theory and network analysis. These
algorithms are used to find the shortest path or the minimum cost path between two nodes in a network,
which can represent a wide range of real-world scenarios such as road networks, computer networks,
social networks, and more. The goal is to determine the most efficient route or path from one point to
another while minimizing some cost or distance metric.Some common shortest path algorithms are:
- Bellman Ford’s Algorithm
- Dijkstra’s Algorithm
There are two main types of shortest paths:
- Single-Source Shortest Path: Finding the shortest path from a single source node to all other nodes
in the network. The most common algorithm for this is Dijkstra's algorithm.
- Single-Pair Shortest Path: Finding the shortest path between a specific pair of nodes in the network. This
is typically achieved using algorithms like Dijkstra's algorithm or the Bellman-Ford algorithm.
2.2 Explanation of their relevance in networking and routing.
Network shortest path algorithms are highly relevant in the field of networking and routing due to their
critical role in ensuring efficient data transmission, resource optimization, fault tolerance, and overall
network performance
- Optimal Routing: Shortest path algorithms are fundamental for finding these optimal routes,
minimizing delays, congestion, and resource utilization.
- Latency Reduction: By selecting the shortest path, these algorithms help reduce the time it takes
for data to traverse the network
- Resource Efficiency: Shortest path algorithms assist in distributing traffic across the network's
infrastructure optimally, ensuring that resources are not wasted and network capacity is fully utilized.
- Network Design and Optimization: When designing network topologies or making changes to
existing networks, shortest path algorithms help find optimal routes and assess the effects of network
modifications on performance and efficiency
- Network Monitoring and Diagnostics: Shortest path algorithms are used in network monitoring and
diagnostic tools to identify bottlenecks, anomalies, or routing problems
Bellman-Ford Algorithm
- Bellman-Ford is a single source shortest path algorithm that determines the shortest path between a
given source vertex and every other vertex in a graph. This algorithm can be used on both weighted and
unweighted graphs.
- Although Bellman-Ford is slower than Dijkstra’s algorithm, it is capable of handling graphs with
negative edge weights, which makes it more versatile. [ Afteracademy.com.2023]
15
Figure 11: Bellman-Ford Algorithm
16
Figure 12: Memory stack
Operations
A Stack is a collection of elements of the same type that are arranged in a logical order. All operations are
performed at a single end of the stack, which is the top of the stack, and the following operations are
possible:
•push() – Inserts a new element at the top of the stack.
•pop() – If the stack isn't empty, remove and return the element at the top.
•peek() – If the stack is not empty, return the element at the top of the stack without removing it.
•isFull() – If the stack is full, return true; otherwise, return false [Tutorialspoint.com, 2023]
17
Exception
-The operations pop and top cannot be performed if the stack is empty. -A StackEmptyException 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 OutOfMemoryError.
[Tutorialspoint.com, 2023]
Application:
Nesting of any kind (such as parentheses)
18
Implement Stack by Array in Java:
Output
19
P3. Using an imperative definition, specify the
abstract data type for a software stack.
Definition of software stack:
An application is made up of a set of functions that work together in a defined architecture to provide the
user with specific services. Three layers make up the most basic application architecture:
•The web tier is comprised of the web server (also known as an HTTP server).
•The application server (which includes the development platform, frameworks, and server-side
programming languages) is the business tier.
•The database tier—the database server you select, which is frequently influenced by the business tier.
20
An operating system, server, database, and server-side scripting language are all included in each tier.
You're not restricted to the components in a stack; they're interchangeable and customizable based on your
needs. [Techopedia.com, 2023]
21
application server framework, and a front-end web framework called Angular.js, and the Node.js
runtime environment.
3. WIMP - The Windows operating system, IIS web servers, MySQL or MS Access for data
administration, and PHP, Perl, or Python for programming make up the WIMP software stack.
4. NMP - NMP is a collection of software stacks that include Nginx web servers, MySQL, and PHP
programming language. This technology suite has been packaged separately for Linux, Windows,
and macOS and is compatible with all major operating systems.
5. MAMP - The MAMP framework allows you to build websites that run on both Windows and Mac
computers. The operating system (macOS or Windows), the Apache web server, MySQL for
relational database administration, and PHP, Perl, or Python for web programming make up the
software stack.
Each software stack has its own set of advantages and disadvantages for developers. Before deciding on
the best set of software solutions to support the delivery of application services to end-users, application
architects must first comprehend and anticipate the application's unique requirements. [ Techopedia.com,
2023]
22
References
1. objects?, W., 2023. What is the difference between Abstract Data Types and objects?. [online] Computer
Science Stack Exchange. Available at: https://cs.stackexchange.com/questions/51847/what- is-the-
difference-between-abstract-data-types-and-objects [Accessed 2 October 2023].
2. W3schools.com. 2023. Java Encapsulation and Getters and Setters. [online] Available
at:<https://www.w3schools.com/java/java_encapsulation.asp> [Accessed 2 October 2023].
3. Afteracademy.com.2023.Comparison of Sorting Algorithms.[online] Available
at:https://afteracademy.com/blog/comparison-of-sorting-algorithms [Accessed 2 October 2023].
4. Programiz.com.2023.Bellman Ford's Algorithm.[online]Available
at :<https://www.programiz.com/dsa/bellman-ford-algorithm> [Accessed 2 October 2023].
5. Tutorialspoint.com. (2023). Data Structure and Algorithms - Stack - Tutorialspoint. [online] Available at:
https://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm.
6. [3]. GeeksforGeeks. 2023. Abstract Data Types - GeeksforGeeks. [online] Available at:<
https://www.geeksforgeeks.org/abstract-data-types/> [Accessed 2 October 2023].
7. Tutorialspoint.com. 2023. Data Structure and Algorithms - Stack - Tutorialspoint. [online]
Available at:< http://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm#
%3A~%3Atext%3DA%20stack> [Accessed 2 October 2023]
8. [6]. Techopedia.com. 2023. What is Software Stack? - Definition from Techopedia. [online] Available at:<
https://www.techopedia.com/definition/4356/software#:~:text=Software%20is%20often%20used
%20to,often%20used%20to%20describe%20software.> [Accessed 2 October 2023].
9. GeeksforGeeks.2023.Queue Data Structure-GeeksforGeeks. [online]Available at:
<https://www.geeksforgeeks.org/queue-data-structure/> [Accessed 2 October 2023].
23