0% found this document useful (0 votes)
141 views69 pages

792 1601898451857 UNIT 19 Data Structures and Algorithms

This document provides guidelines and instructions for an assignment on data structures and algorithms. It outlines 10 tasks for students to complete, including examining data structures for a hotel banquet hall reservation system, implementing the system using appropriate data structures, sorting algorithms and shortest path algorithms, specifying an abstract data type, and analyzing algorithm complexity and efficiency. Students are instructed to provide code snippets, diagrams, test cases and results in a report format with proper citations. The assignment aims to assess students' understanding of key learning outcomes related to data structures, algorithms, abstract data types and analysis of algorithm effectiveness.

Uploaded by

Raisha
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)
141 views69 pages

792 1601898451857 UNIT 19 Data Structures and Algorithms

This document provides guidelines and instructions for an assignment on data structures and algorithms. It outlines 10 tasks for students to complete, including examining data structures for a hotel banquet hall reservation system, implementing the system using appropriate data structures, sorting algorithms and shortest path algorithms, specifying an abstract data type, and analyzing algorithm complexity and efficiency. Students are instructed to provide code snippets, diagrams, test cases and results in a report format with proper citations. The assignment aims to assess students' understanding of key learning outcomes related to data structures, algorithms, abstract data types and analysis of algorithm effectiveness.

Uploaded by

Raisha
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/ 69

Pearson Higher Nationals in

Computing
Unit 19: Data Structures & Algorithms
Assignment 01
General Guidelines

1. A Cover page or title page – You should always attach a title page to your assignment. Use
previous page as your cover sheet and make sure all the details are accurately filled.
2. Attach this brief as the first section of your assignment.
3. All the assignments should be prepared using a word processing software.
4. All the assignments should be printed on A4 sized papers. Use single side printing.
5. Allow 1” for top, bottom , right margins and 1.25” for the left margin of each page.

Word Processing Rules

1. The font size should be 12 point, and should be in the style of Time New Roman.
2. Use 1.5 line spacing. Left justify all paragraphs.
3. Ensure that all the headings are consistent in terms of the font size and font style.
4. Use footer function in the word processor to insert Your Name, Subject, Assignment No, and
Page Number on each page. This is useful if individual sheets become detached for any reason.
5. Use word processing application spell check and grammar check function to help editing your
assignment.

Important Points:

1. It is strictly prohibited to use textboxes to add texts in the assignments, except for the
compulsory information. eg: Figures, tables of comparison etc. Adding text boxes in the body
except for the before mentioned compulsory information will result in rejection of your work.
2. Carefully check the hand in date and the instructions given in the assignment. Late submissions
will not be accepted.
3. Ensure that you give yourself enough time to complete the assignment by the due date.
4. Excuses of any nature will not be accepted for failure to hand in the work on time.
5. You must take responsibility for managing your own time effectively.
6. If you are unable to hand in your assignment on time and have valid reasons such as illness, you
may apply (in writing) for an extension.
7. Failure to achieve at least PASS criteria will result in a REFERRAL grade .
8. Non-submission of work without valid reasons will lead to an automatic RE FERRAL. You will
then be asked to complete an alternative assignment.
9. If you use other people’s work or ideas in your assignment, reference them properly using
HARVARD referencing system to avoid plagiarism. You have to provide both in-text citation and a
reference list.
10. If you are proven to be guilty of plagiarism or any academic misconduct, your grade could be
reduced to A REFERRAL or at worst you could be expelled from the course
Student Declaration

I hereby, declare that I know what plagiarism entails, namely to use another’s work and to present it as
my own without attributing the sources in the correct form. I further understand what it means to copy
another’s work.

1. I know that plagiarism is a punishable offence because it constitutes theft.


2. I understand the plagiarism and copying policy of Edexcel UK.
3. I know what the consequences will be if I plagiarise or copy another’s work in any of the
assignments for this program.
4. I declare therefore that all work presented by me for every aspect of my program, will be my own,
and where I have made use of another’s work, I will attribute the source in the correct way.
5. I acknowledge that the attachment of this document signed or not, constitutes a binding
agreement between myself and Pearson, UK.
6. I understand that my assignment will not be considered as submitted if this document is not
attached to the assignment.

Student’s Signature: Date:


(Provide E-mail ID) (Provide Submission Date)
HND in Computing - App.Dev / SW. Eng. Pathway
Assignment Brief
Student Name /ID Number
Unit Number and Title Unit 19 : Data Structures and Algorithms
Academic Year
Unit Tutor
Assignment Title Specification, Implementation, and Assessment of Data Structures for a
sample scenario.
Issue Date
Submission Date
IV Name & Date

Submission format

The submission should be in the form of a report, which contains code snippets (which must be
described well), text based descriptions, and diagrams where appropriate. References to external
sources of knowledge must be cited (reference list supported by in-text citations) using the
Harvard Referencing style.

Unit Learning Outcomes:

LO1. Examine abstract data types, concrete data structures and algorithms.
LO2. Specify abstract data types and algorithms in a formal notation.
LO3. Implement complex data structures and algorithms.
LO4. Assess the effectiveness of data structures and algorithms.
Assignment Brief and Guidance:

Scenario
‘XYZ’ hotel chain has 100 banquet halls island wide. Any hotel has minimum one banquet hall to
maximum 5 halls. It provides online hotel banquet hall reservation facilities to their customers.
The reservation system uses a waiting list of the selected banquet halls.

Each banquet hall has unique id, name, location, maximum number guests, reservation date
and the three menu prices. Customer can search a banquet hall with the location, reservation
date and the number of guests. According to the hotel chain rules and regulations, when a
possible match between reservation and the banquet hall is found the customer is contacted via
email or SMS and informed. If customer is not responding within a day, he or she is placed back
in the waiting list and must wait again for another hall.

If customer requested a date change or a location change or a change in number of guests, he or


she is placed back in the waiting list and must wait again for another reservation.
We will assume that each banquet hall, once accepted, will be occupied by a reservation ID.
Insert banquet hall details, reservation details and customer details through the keyboard.
The reservation process should remove a banquet hall on a given date from the queue if the
customer “accepts” the reservation. If the customer rejects or changes the reservation delete
the customer reservation, insert it to the back of the queue and compare next customer
reservation and repeat. This process repeats until all customers complete their reservations.
Task 1: Examine and create data structure by simulating the above scenario and explain the
valid operations that can be carried out on this data structure. ( meka wenas )

Task 2: Implement the above scenario using the selected data structure and its valid operations
for the design specification given in task 1 by using java programming. Use suitable error
handling and Test the application using suitable test cases and illustrate the system. Provide
evidence of the test cases and the test results.

Task 3:

Task 4: Sort the banquets halls with two different sorting algorithms and critically review the
performances of those two algorithms by comparing them.

Task 5: There are 8 hotels available in the Southern district in Sri Lanka. A customer plans to visit
all of these eight hotels through the shortest path within a day.
Analyse the above operation by using illustrations, of two shortest path algorithms, specify how
it operates using a sample graph diagram.

Task 6: Banquet hall details are stored from oldest to newest hall. The customer should be able
to find from the newest to the oldest banquet hall added to the hotel chain.
Using an imperative definition, specify the abstract data type for the above scenario.
Examine the advantages of encapsulation and information hiding when using an ADT selected
for the above scenario.
Object orientation is a paradigm where a computer program functions by objects calling the
methods of other objects, which ultimately produces program behaviour. It makes programming
simple, readable, and makes programs maintainable. Imperative ADTs are basis for object
orientation. Do you agree? Disccuss your answer.
Task 7: Implement the above scenario using the selected complex ADT by using java.
Demonstrate how the implementation of an ADT/algorithm solves the above problem.
Critically evaluate the complexity of an implemented ADT/algorithm.
Explain the different ways in which the efficiency of an algorithm can be measured, illustrating
your answer the algorithm which you have developed.

Task 8: Asymptotic analysis can be used to assess the effectiveness of an algorithm. Discuss
Asymptotic analysis for the scenario given in task 7.
Critically review the sort of trade-offs exists when you use an ADT for implementing programs
Describe the benefits of using independent data structures for implementing programs.
Grading Rubric.
Grading Criteria Achieved Feedback

LO1. Examine abstract data types, concrete data structures


and algorithms.
P1 Create a design specification for data structures explaining
the valid operations that can be carried out on the structures.

P2 Determine the operations of a memory stack and how it is


used to implement function calls in a computer.

M1 Illustrate, with an example, a concrete data structure for a


First In First out (FIFO) queue.

M2 Compare the performance of two sorting algorithms.

D1 Analyse the operation, using illustrations, of two network


shortest path algorithms, providing an example of each.
LO2. Specify abstract data types and algorithms in a
formal notation.

P3 Using an imperative definition, specify the abstract data


type for a software stack.

M3 Examine the advantages of encapsulation and information


hiding when using an ADT.
D2 Discuss the view that imperative ADTs are a basis for object
orientation and, with justification, state whether you agree.

LO3. Implement complex data structures and algorithms.

P4 Implement a complex ADT and algorithm in an executable


programming language to solve a well-defined problem.

P5 Implement error handling and report test results.


M4 Demonstrate how the implementation of an
ADT/algorithm solves a well-defined problem.
D3 Critically evaluate the complexity of an implemented
ADT/algorithm.

LO4. Assess the effectiveness of data structures and


algorithms.
P6 Discuss how asymptotic analysis can be used to assess the
effectiveness of an algorithm.
P7 Determine two ways in which the efficiency of an
algorithm can be measured, illustrating your answer with an
example.
M5 Interpret what a trade-off is when specifying an ADT
using an example to support your answer.
D4 Evaluate three benefits of using implementation
independent data structures.
Table of Contents
Acknowledgement...............................................................................................................................14
Task 01.................................................................................................................................................18
1.1. Data Structures........................................................................................................................18
1.1.1. Types of Data Structures..................................................................................................19
1.1.2. Linear Data Structure.......................................................................................................19
1.1.2.1. Array.........................................................................................................................20
1.1.2.3. Stack.........................................................................................................................21
1.1.2.4. Queue......................................................................................................................22
1.1.3. Non-Linear Data Structure...............................................................................................23
1.1.3.1. Tree..........................................................................................................................23
1.1.3.2. Graph.......................................................................................................................24
1.1.4. Queue Data Structure......................................................................................................25
1.1.5. Basic Operations of Queue Data Structure.......................................................................26
Task 02.................................................................................................................................................34
2.1. Implementing the Queue Data Structure.................................................................................34
2.1.2. Test Cases and the Test Results........................................................................................37
Task 03.................................................................................................................................................38
3.1. Stack Implementation..............................................................................................................38
Task 04.................................................................................................................................................41
4.1. Sorting Algorithms...................................................................................................................41
4.1.1. Bubble Sort Algorithm......................................................................................................41
4.1.2. Quick Sort Algorithm........................................................................................................42
4.1.3. Insertion Sort Algorithm...................................................................................................43
4.1.3.1. Pseudo Code............................................................................................................43
4.1.3.2. Implementation.......................................................................................................44
4.1.4. Selection Sort Algorithm..................................................................................................45
4.1.4.1. Pseudo Code............................................................................................................46
4.1.4.2. Implementation.......................................................................................................46
4.1.5. Comparison of Performance............................................................................................47
Task 05.................................................................................................................................................48
5.1. Dijkstra’s Algorithm..................................................................................................................48
5.1.1. Bellman-Ford Algorithm...................................................................................................51
Task 06.................................................................................................................................................54
6.1. ADT (Abstract Data Type).........................................................................................................54
6.1.1. Encapsulation...................................................................................................................56
6.1.1.1. Encapsulation example with Java.............................................................................57
Task 07.................................................................................................................................................59
7.1. Stack ADT.................................................................................................................................59
Task 08.................................................................................................................................................61
References...........................................................................................................................................62
List of Figures.
Figure 1 Array Data Structure..............................................................................................................18
Figure 2 Types of Data Structures........................................................................................................19
Figure 3 Queue....................................................................................................................................22
Figure 4 Tree Data Structure................................................................................................................24
Figure 5 Graph.....................................................................................................................................24
Figure 6 Source code of the queue implementation 1 (Author Developed)........................................35
Figure 7 Source code of the queue implementation 2 (Author Developed)........................................35
Figure 8 Source code of the queue implementation 3 (Author Developed)........................................36
Figure 9 Stack Implementation............................................................................................................38
Figure 10 Push & Pop Operation..........................................................................................................39
Figure 11 Bubble Sort Algorithm..........................................................................................................41
Figure 12 Quick Sort Algorithm............................................................................................................42
Figure 13 Insertion Sort Algorithm.......................................................................................................43
Figure 14 Pseudo Code (Author Developed)........................................................................................43
Figure 15 Insertion Sort (Author Developed).......................................................................................44
Figure 16 Selection Sort Algorithm......................................................................................................45
Figure 17 Pseudo Code (Author Developed)........................................................................................46
Figure 18 Selection Sort (Author Developed)......................................................................................46
Figure 19 Dijkstra’s Algorithm..............................................................................................................48
Figure 20 Dijkstra Implementation 1 (Author Developed)...................................................................49
Figure 21 Dijkstra Implementation 2 (Author Developed)...................................................................50
Figure 22 Dijkstra Implementation 3 (Author Developed)...................................................................50
Figure 23 Bellman-Ford Algorithm.......................................................................................................51
Figure 24 Bellman-Ford Implementation 1 (Author Developed)..........................................................52
Figure 25 Bellman-Ford Implementation 2 (Author Developed)..........................................................52
Figure 26 Bellman-Ford Implementation 3 (Author Developed)..........................................................53
Figure 27 Abstract Data Type (ADT).....................................................................................................54
Figure 28 ADT Stack.............................................................................................................................55
Figure 29 ADT Queue...........................................................................................................................55
Figure 30 ADT List................................................................................................................................56
Figure 31 Stack ADT (Author Developed).............................................................................................59

List of Tables.
Table 1 Operations of Queue Data Structure used...............................................................................25
Table 2 Queue Data Structure Functions.............................................................................................34
Table 3 Test Cases and the Test Results (Author Developed)...............................................................37
Table 4 Comparison of Performance (Author Developed)...................................................................47
Task 01.
1.1. Data Structures.

A data structure is a particular method of organizing data in a computer for efficient use. The
name of the data structure itself indicates the organization of the data memory. There are
many ways to organize data in memory, and one of the data structures already seen is the
array in C language. An array is a collection of memory elements that store data one by one.
In other words, this means that the array continues to store the element. This data is organized
with the help of a number of data structures. There are other ways to organize data in
memory. There are some different types of data structures. Database is not a programming
language like C, C ++, Java. It is a set of algorithms that can be used in any programming
language to process memory data.[ CITATION jav21 \l 1033 ]
For example, it can store a list of items with the same data type using the array data structure.

Figure 1 Array Data Structure

Why are data structures important?


Typical base data types, such as integers or floating-point values, which are available in most
computer programming languages, are generally not sufficient to capture the logical intent for
data processing and use. But need to understand how data should be organized to simplify the
entry, handling and processing of applications that produce information. Data structures bring
the data element in a logical way and facilitate effective use, persistence, and data exchange.
Provides a formal format that describes how the data element is organized.
These are created by composing a data element into a logical unit that represents an abstract
data type relevant to the algorithm or application. An example of an abstract data type is a
"username" consisting of the strings for "first name", "middle name" and "last name".
[ CITATION sea212 \l 1033 ]
1.1.1. Types of Data Structures.

Figure 2 Types of Data Structures

There are two types of data structures,


1. Primitive data structure.
2. Non-primitive data structure.

1. Primitive data structure.


The primitive data types are primitive data structures. The primitive data structures that may
contain a single value are int, char, float, double, and pointer.

2. Non-primitive data structure.


There are two types of non-primitive data structures,
1. Linear data structure.
2. Non-linear data structure.

1.1.2. Linear Data Structure.


A linear data structure is a structure in which the element is stored in sequence and the
element is connected to the previous and next element. Because the elements are stored in
sequence, they can travel on a single track. Linear data structures are easy to implement
because the elements are organized in memory in sequence. The data element in the array
travels one at a time and can only access one element at a time.
Array, Queue, Stack, and Linked List are types of linear data structures.

1.1.2.1. Array.

What is an Array?
An array is a data structure that contains the same type of element. A data structure is a way
of organizing data; An array is a data structure because it organizes data sequentially. An
array is a large partition of memory divided into smaller parts, each of which has the ability
to store some value. Considering that an array consisting of 10 values is created, each of its
blocks stores the value of an integer type. If it tries to store different types of value, it is not
the right array and it throws up a compiler time error.[ CITATION jav211 \l 1033 ]

Code enawa

1.1.2.2. Linked List.

What is a linked list?


A linked list is a collection of randomly stored nodes. Each node consists of two fields,
namely data and link. Here, data is the value stored on that particular node, and the link is the
index that holds the address of the next node.
1.1.2.3. Stack.

What is a stack?
A stack is a linear data structure. In an array, it can be accessed randomly, that is, any element
in an array can be accessed at any time, and only sequential access can be made in stack. It is
a container that follows the rule of entry and deletion. It follows the LIFO (Last in First Out)
principle of insertion and deletion on one side, as described above. In stack, the element of
the same data type can be inserted, that is, the element of different data types cannot be
included in the same stack. The two operations are performed in LIFO, namely push and pop
activation.[ CITATION jav212 \l 1033 ]

Code enawa
1.1.2.4. Queue.

What is a queue?
Queues are a linear data structure. This is a list of orders that follow the FIFO (First In -First
Out) principle. A queue is a structure that follows certain limits on entry and deletion. In the
case of queues, the entry is made from one end, and that end is called the rear end. Deletion is
done at the other end and that end is called the front end. In queues, the technical terms for
insertion and deletion are enqueue () and dequeue (), respectively, while in stack, the
technical terms for entry and deletion are push () and pop (). Its structure consists of a front
indicator and a rear indicator, the front indicator being the first element added to the queue
and the rear indicator being the last added element in the queue. [ CITATION jav212 \l 1033 ]

Figure 3 Queue

Code enawa
1.1.3. Non-Linear Data Structure.

What is a Non-Linear Data Structure?


A non-linear data structure is another type of data structure in which the data elements are not
aligned. Data elements cannot be run at once because the setup is unpredictable. In the case
of a linear data structure, the element is connected to two elements (before and after the
element), and in a non-linear data structure, an element can be connected to more than two
elements.

1.1.3.1. Tree.

What is a tree?
The hierarchy is represented by a tree, which is a non-linear data structure. A tree is a
hierarchy formed by a collection of nodes that are connected together.
And have a look at some of the terms used in tree data structures.
1. Root node - The top node of a tree data structure is called the root node. A node with
no parents is called the root node.
2. Parent of a node - The closest precursor to a node is called the parent of the node. The
precursor here refers to the anterior node of that particular node.
3. Child of a node - The closest successor to a node is called the child of the node.
4. Leaf node - The leaf node is a node without a child node. An external node is another
name for it.
5. Non-leaf node - A node with at least one child node is referred to as a non-leaf node.
An internal node is another name for it.
6. Path - It is a sequence of continuous edges from the origin node to the destination
node. The edge here is a link between two nodes.
7. Ancestor - The antecedent node that occurs on the path from the beginning to that
node is called the ancestor.
8. Descendant - Successive nodes in the path from that node to the leaf node.
9. Sibling - All children with the same parent node are called siblings.
10. Degree - The number of children in a particular node is called a degree.
11. Depth of node - The length of the path from the root to that node is called the depth of
a node.
12. Height of a node - The number of edges that occur on the longest path from that node
to the leaf node is called the height of a node.
13. Level of node - The number of edges from the root node to the given node is called the
level of a node. [ CITATION jav21 \l 1033 ]

Figure 4 Tree Data Structure

1.1.3.2. Graph.

What is a Graph?
A graph is a non-linear data structure that has a finite number of vertices and edges and is
used to connect these edge vertices. Vertical is used to store the data element and represents
the relationship between the vertical of the edges. Uses a graph for various real-time issues
such as telephone networks, circuit networks, social networks such as LinkedIn, and
Facebook. In the case of Facebook, a single user can be considered a node, while a user is
referred to as the edge of the connection with others. [ CITATION jav21 \l 1033 ]
Figure 5 Graph

1.1.4. Queue Data Structure.


Queues are a type of abstract data structure that resembles stacks. Unlike stacks, a queue
opens on both sides of it. Its first element is inserted REAR (also known as the tail) from one
end and the removal of the existing element is called FRONT (also called the head) from the
other end. FIFO technique is used in Queue, which means that the data item that was saved
first would be retrieved first.
The order is First in First Out (FIFO). A good example of queues is any queue of customers
for a resource that serves the customer first. The difference between stocks and queues is the
removal.
A real-world example of queuing could be a single-lane one-way lane, where the vehicle
enters first and exits first. More realistic examples can be seen as queues at ticket counters
and bus stops. [ CITATION stu21 \l 1033 ]

Table 1 Operations of Queue Data Structure used

Operations Description

Enqueue () This method specifies how to add an element to


the queue.
Dequeue () This method specifies how to remove an entry
from a queue.
Init () This method specifies how to remove an entry
from a queue.
Search Searching is an action or a strategy for locating a
certain element or value inside a list.
Front The front property is used to retrieve the first
data item from a queue.
Rear The front property is used to retrieve the first
data item from a queue.
1.1.5. Basic Operations of Queue Data Structure.

1. Enqueue operation.
The queue maintains two front and rear data indicators. Therefore, it is difficult to execute
relative to the performance of its operating inventory.
To enqueue (insert) data into queues, do the following steps:

Step 1 - Check that the queues are full.

Step 2 - If the queue is full, cause an overflow error and exit.

Step 3 - Increase the rear pointer to indicate to the next empty spot if the queue is not
yet full.

Step 4 - Add a data element to the queue point facing backwards.

Step 5 - Return to the success.

For the Example.


- First add to the waiting list reservation.

Rea Fron
Waiting list

Reservation Reservation Reservation Reservation


4 3 2 1

After confirmation the specific reservation should be removed from the waiting list. Add to
confirmed reservation.
- After the Responding.

Reservation Rea Fron


4 Confirm

Reservation Reservation Reservation


3 2 1

Need to add 4 reservations for queues. Then first go to the queue to check if the reservations
are full.

After confirmation, increase the rear pointer to the next empty space and add the new
reservation to the 4th row. The point where it faces backwards.

Rea Fron
Confirm

Reservation Reservation Reservation Reservation


4 3 2 1
The client made a temporary reservation but did not respond within a day.

No change. Reservations must be on the waiting list if the customer does not respond.

Rea Fro
Waiting list

Reservation Reservation Reservation Reservation


4 3 2 1

After confirmation, the customer does not change the requirements such as address, guests
count.

Then there is no difference in confirming the reservation.

Rea Fron
Confirm

Reservation Reservation Reservation Reservation


4 3 2 1
After confirmation, the customer changes requirements such as address, date or guests count.

It will be removed during the confirmed reservation and added to the waiting list.

Rea Fron
Confirm

Remove
Reservation Reservation Reservation
3 2 1

Reservation
4

Rea Fron
Waiting list reservation

Reservation Reservation Reservation Reservation


4 3 2 1
If the customer accepts the reservation without any change.

Then go to the customer reservation confirmed reservation and remove it from the waiting
list. In addition, the meal will be removed from the list of available meals.

Rea Fron
Waiting list

Remove
Reservation Reservation Reservation
3 2 1

Reservation
4

Rea Fron
Confirm

Reservation Reservation Reservation Reservation


4 3 2 1

Rea Fron
Banquet hall

Remove
Banquet hall Banquet hall 2 Banquet hall
3 1

Banquet hall
4
2. Dequeue Operation.
Dequeue Operation in Queue - In Queue, a Dequeue Operation is when you access material
while removing it from the front end of the queue. Accessing data from the queue is a two-
pronged process, accessing the data shown on the front and deleting the data after access. The
dequeue operation is carried out in the following ways.
Step 1 - Check if the queues are empty.

Step 2 - If the queue is empty, cause an overflow error and exit.

Step 3 - If the queue is not empty, go to the data shown on the front.

Step 4 - Increase the front pointer to point to the next existing data element.

Step 5 - Return Success.[ CITATION tut212 \l 1033 ]

Before the function should check reservation, queue is empty it means the reservation is there
or not. If there is no blank message and a blank message is provided, remove the reservation
and add it to the waiting list.

Rea Fron
Waiting list reservation

Reservation Reservation Reservation Reservation


4 3 2 1
After the checking, The Reservation 1 is not responding with in a day. Then it should be
removed and give a chance to the following reservation 2.

Rea Fron

Dequeue
Reservation Reservation Reservation
4 3 2

Reservation
1

If customer need change or reject the reservation. The same procedure should be process.

3. Init ().

1. isEmpty.
In order to prevent operations on empty stack, the programmer needs to maintain the size of
the thrust internally and thus update during thrust and pop operations. isEmpty ()
Traditionally gives a boolean value: True if size is 0, else False.

2. Isfull ().
Since these use single-dimensional arrays to execute queues, check to see if the queue
indicator reaches MAXSIZE to determine if the queue is full. If this maintains a queue in a
circular linked list, the algorithm changes.
4. Search.
What is a search?
Search is the process of locating a given value in a list of values. It determines whether or not
there is a search key in the data. It is the algorithm process of finding a specific item in a
collection of items. It can be done on the internal data structure or on the external data
structure.

Search methods.
To find an element in a given array, it can be done in the following ways:
1. Sequential search.
Sequential search is also known as linear search. Sequential search starts at the beginning of
the list and examines every element of the list. It's a straightforward and easy-to-understand
search algorithm. Sequential search compares the element with all the other elements listed.
If the element matches, it returns the value index, or it returns -1.
2. Binary search.
Binary search is used to find an element in a sorted array. It is a fast search algorithm with
running time complexity in O (log n). Binary search works on the principle of division and
conquest. This search technique searches for a specific element by comparing it with the
middle part of the collection. It is useful when there are a large number of elements in the
array.[ CITATION tut213 \l 1033 ]
Task 02.
2.1. Implementing the Queue Data Structure.

What is a queue data structure?


The queue is an abstract data structure as well as a linear data structure, where the first
element is inserted REAR (also known as the tail) from one end and the existing element is
removed from the other end. Also known as FRONT (also known as head). This converts the
queue into a FIFO (First in First Out) data structure, which means that the first entered
element will be removed first.

Table 2 Queue Data Structure Functions

OPERATIONS VARIABLES

01 Enqueue (Add Operation). Rear, front, buff, bool.


.
02 Dequeue (Remove Operation). Front, string, return, type.
.
03 Is full. Rear, front, buff, bool.
.
04 Is empty. Rear, front, buff, bool.
.
05 Search. Array, key, return type.
.

Implementing the queue data structure.

Queues can be activated using an array, a vertical or a linked list. The easiest way to execute
a queue is to use an array.
Initially the head (FRONT) and tail (REAR) of the queues in the first index of the array
(starting the array index from 0). When the element is added to the queue, the tail moves
forward, always pointing to the point where the next element enters and the head is in the first
indicator.
2.1.1. Queue Implementation.

Figure 6 Source code of the queue implementation 1 (Author Developed)


Figure 7 Source code of the queue implementation 2 (Author Developed)
Figure 8 Source code of the queue implementation 3 (Author Developed)
2.1.2. Test Cases and the Test Results.

Table 3 Test Cases and the Test Results (Author Developed)

Test Action Inputs Outputs Test


Case Results
Test Temp_Reservation Temp_Reservation_ID Search Customer Details. Passed
Case 01 Confirmed Button Reservation_id
add waiting list.
Queue confirmed.
Available banquet.
hall deleted.
Test Temp Reservation Temp_Reservation_ID Search Customer Details. Passed
Case 02 Not Confirmed Button Reservation_id
add waiting list.
Test Change Reservation Date, Address, count of guest Adding: Passed
Case 03 Details. Changed Temp_Reservation,
Waiting list,
Available banquet
Hall.
Test Customer Accept Confirmed Remove waiting list Passed
Case 04 and available banquet
hall.
Test After Reservation Confirmed Customer Details add Passed
Case 05 Database
Task 03.
3.1. Stack Implementation.
Memory stacks are linear data structures (locations) in a computer's memory that hold data. It
is also known as queues. The data in a stack must always be of the same type. The following
is an example of a stack shown in Figure 9. Items in stack are arranged in a linear order. Like
any assembled queue or collection, the data items in a repository are stored and accessed in a
specific way. In this case, a technology called LIFO (Last in First Out) is used. This entails a
number of insertion and removal procedures.[ CITATION stu211 \l 1033 ]

Figure 9 Stack Implementation

Push Operation.
Push operation involves inserting data items into a stack. Check out the restaurant plate
distributor in Figure 10. The push process adds plates (data items) to the plate distributor
(stack). The first plate is pushed to the bottom of the stack followed by all subsequent plates.
The first data item entered is the most inaccessible and is located at the bottom of the
inventory. [ CITATION stu211 \l 1033 ]

The Pop Operation.


The pop operation involves the removal of data items from a loaded stack. In Plate
Distributor example, the last plate (data item) collected is positioned at the top of the stack.
This data item has been removed from the stack as the first item to be removed. Think of the
spring loading system at the foot of the plate distributor. Each time a plate is removed, it
pushes the stack of plate upward. Items continue to pop up in that order in memory.
[ CITATION stu211 \l 1033 ]

Figure 10 Push & Pop Operation

Code enawa
Code enawa
Task 04.

4.1. Sorting Algorithms.


Sorting algorithm is a method of rearranging a large number of items from top to bottom or
vice versa in some alphabetical order. This algorithm takes an input list and executes it (that
is, performs some operations on it) and generates a sorted list. The most common example
experiences every day is the sorting of clothing or other items on the e-commerce website
from the lowest price to the lowest price or listing by popularity or other order.[ CITATION
int21 \l 1033 ]

4.1.1. Bubble Sort Algorithm.


Bubble sort, also known as comparison sort, is a simple sorting algorithm that repeatedly
goes through a list and compares adjacent elements in the wrong order. This is the simplest
algorithm and at the same time inefficient. However, it is very important to learn about it as it
represents the basics of classification.

Figure 11 Bubble Sort Algorithm


4.1.2. Quick Sort Algorithm.
The algorithm was developed in 1959 by British computer scientist Tony Hoare. The name
"instant sorting" comes from the fact that quick sorting allows a data element list to be sorted
significantly faster (two or three times faster than anything else). Algorithm classification. It
is one of the most efficient sorting algorithms and is based on dividing the array (partition)
into smaller ones and comparing them with the selected 'turns' element (exchange). Because
of this, quick sorting is also known as "stock exchange". Like integration classification,
instant classification also involves the approach of dividing and conquering problem-solving
methods. [ CITATION int21 \l 1033 ]

Figure 12 Quick Sort Algorithm


4.1.3. Insertion Sort Algorithm.
Insertion sort is the sorting mechanism that builds the sorted array with one item at a time.
The elements of the array are compared with each other in sequence and then arranged
simultaneously in a certain order. The analogy can be understood from the style in which
arrange a deck of cards. This classification operates on the principle of inserting an element
somewhere, hence the classification of the name entry. [ CITATION int21 \l 1033 ]

Figure 13 Insertion Sort Algorithm

4.1.3.1. Pseudo Code.


Figure 14 Pseudo Code (Author Developed)

4.1.3.2. Implementation.

Figure 15 Insertion Sort (Author Developed)


4.1.4. Selection Sort Algorithm.
Selection Sort is a Sorting algorithm based on simple comparisons. It is functional and
requires no additional memory. This algorithm's concept is fairly simple. The array is divided
into two categories, sorted and unsorted. The subarray on the left is sorted, whereas the
subarray on the right is unsorted. The sorted subarray is initially empty, but the unsorted array
contains the entire supplied array. [ CITATION int21 \l 1033 ]
Figure 16 Selection Sort Algorithm

4.1.4.1. Pseudo Code.

Figure 17 Pseudo Code (Author Developed)

4.1.4.2. Implementation.
Figure 18 Selection Sort (Author Developed)
4.1.5. Comparison of Performance.

Table 4 Comparison of Performance (Author Developed)

Basis for Insertion Sort Selection Sort


Comparison
Basic The data is sorted by inserting the The data is sorted by selecting and
data into an existing sorted file. placing the consecutive elements in
sorted location.
Nature Stable Unstable
Process to be Elements are known beforehand Location is previously known while
followed while location to place them is elements are searched.
searched.
Immediate data Insertion sort is live sorting It cannot deal with immediate data; it
technique which can deal with needs to be present at the beginning.
immediate data.
Best case O(n) O(n2)
complexity
Task 05.
5.1. Dijkstra’s Algorithm.
Dijkstra’s algorithm for a minimal spreading tree is very similar to Prim's algorithm. Like
Prim's MST, generate SPT (the shortest path tree) as the source of a given source. This
maintains two sets, one set contains the vertical that is inserted into the shortest road tree, and
the other set includes the vertical that is not yet inserted into the shortest road tree. At each
step of the algorithm, find the title of the other set (not yet included) and the minimum
distance from the source.
The following are the detailed steps used in the Dijkstra algorithm to find the shortest path
from a single source surface x to all other vertices in a given graph.[ CITATION gee21 \l
1033 ]

Figure 19 Dijkstra’s Algorithm

Algorithm.
01. Create a sptSet (a set of shortcut tree trees) that keeps the vertical notes inserted in the
shortest path tree, that is, the minimum distance from the source is calculated and completed.
Initially, this set was empty.
02. Give a distance value to all the verticals in the input graph. Start all distance values as
INFINITE. Assign the distance value to 0 for the origin header, then it will be selected first.
03. Not all verticals in sptSet are included
a) Choose a vertical plane with a minimum distance that sptSet does not have.
b) Add yourself to sptSet.
c) Update the distance value of all adjacent verticals in u. To update distance values,
re-run across all adjacent verticals. For each adjacent header, update the distance in
u (from the origin) and the distance in v if the edge weight is less than the distance
in u-v, v.
Advantages and Disadvantages of Dijkstra’s Algorithm

Advantages of Dijkstra.
1. One of its main advantages is its small complexity.
2. By stopping the algorithm after reaching the shortest distance to the destination
node, it can be used to calculate the shortest path between one node to all other
nodes and to a single destination node from a single source node.
3. It only works for oriented, weighted graphs and should have non-negative values
at all edges.
Disadvantages of Dijkstra.
1. It makes a vague quest that takes a lot of time to set up,
2. Negative edges cannot be manipulated.
3. Since it goes to the acyclic graph, the correct shortcut cannot be achieved and
there is a need to maintain vertical tracking.

Dijkstra Implementation.
Figure 20 Dijkstra Implementation 1 (Author Developed)

Figure 21 Dijkstra Implementation 2 (Author Developed)


Figure 22 Dijkstra Implementation 3 (Author Developed)
5.1.1. Bellman-Ford Algorithm.

The Bellman-Ford algorithm is a chart search algorithm that finds the shortest path between a
given prototype and all other verticals in a graph. This algorithm can be used on both
weighted and unweighted charts. Like Dijkstra's shortcut algorithm, the Belman-Ford
algorithm guarantees finding the shortest path in a graph. Although it's slower than Dijkstra's
algorithm, Belman-Ford has the ability to handle graphs with negative edge loads, so it's
more versatile. It is worth noting that there is no shortcut if the chart has a negative cycle.
Traveling around the wheel on an indefinite basis will reduce the cost of the road (even if the
road length is longer). Because of this, Bellman-Ford is also able to detect negative-negative
cycles, which is a useful feature.[ CITATION bri21 \l 1033 ]

Figure 23 Bellman-Ford Algorithm


Bellman-Ford Implementation.

Figure 24 Bellman-Ford Implementation 1 (Author Developed)

Figure 25 Bellman-Ford Implementation 2 (Author Developed)


Figure 26 Bellman-Ford Implementation 3 (Author Developed)
Task 06

6.1. ADT (Abstract Data Type).


Data type is basically a type of data that can be used for various computer programs. It
represents integers, floats, etc. It takes up 4 bytes of space, as well as 1-bytes of characters.
An abstract database is a specific database whose behavior is defined by a set of values and a
set of operations. The term "summary" is used because these databases can be used to
perform various operations. But how those operations work is completely hidden from the
user. ADT is made up of primary databases but the operational logic is hidden. Examples of
ADT are stacks, queues, and lists so on.[ CITATION tut214 \l 1033 ]

Figure 27 Abstract Data Type (ADT)


1. Stack -
1. IsFull (), is used to check if the stack is full.
2. IsEmpry (), is used to check whether the stack is empty.
3. Push (x), this is used to push the x stack.
4. Pop (), this is used to delete one element at the top of the stack.
5. Peek (), used to get the top element of the stack.
6. Size (), this function is used to get the number of elements in a stack.

Figure 28 ADT Stack

2. Queue -
1. IsFull (), is used to check whether queues are full.
2. IsEmpry (), is used to check whether queues are empty.
3. Insert (x), this is used to add x to the queue at the back end.
4. Delete (), this is used to delete one element from the front end of the queue.
5. Size (), this function is used to get the number of elements present in the queue.
Figure 29 ADT Queue

3. List -
1. Size (), uses this function to get the number of elements in the list.
2. Insert (x), this method is used to add a single item to a list.
3. Remove (x), this function is used to remove the given element from the list.
4. Get (i), this function is used to get the element at location i.
5. Replace (x, y), this function is used to replace the x value with the y value.

Figure 30 ADT List

6.1.1. Encapsulation.
OAP is one of the four concepts in Encapsulation. The other three are inheritance, multimeter
and abstraction. Java encryption is the process of encoding data (variables) and data
(methods) into a single unit. In development, class variables are hidden from other classes
and can only be accessed by their current class methods. Hence it is also known as data
hiding. Technically, class variables or data are hidden from any other class and can only be
accessed through any member function of their own class that has published it. Circulation
can be achieved by declaring all the variables in the class as private and by writing common
class methods for setting and retrieving the values of the variables.
To Achieve Circulation in Java -
1. Private expression of class variables.
2. Provide common settings and retrieval modes for modifying and viewing variable
values.[ CITATION tut215 \l 1033 ]
6.1.1.1. Encapsulation example with Java.

code ekak enawa.


Advantages of Encapsulation in Java.
Circulating in Java has the following advantages. as follows,
1. Closed code is more flexible and easier to change with new requirements.
2. Prevents other classes from entering the private sector.
3. Encapsulation allows you to modify the executable code without breaking any other
code that has been executed.
4. It protects data and code from external inheritance. Thus, encapsulation helps to
achieve security.
5. It improves the maintenance capability of the application.
6. Field readings can only be done if the class setting method is not defined.
7. Fields can only be written if the method of obtaining the class is not defined.

Disadvantage of encapsulation in Java.


1. The main disadvantage of locking in Java is that it increases the length of the code
and slows down the closing process. [ CITATION sci21 \l 1033 ]
Task 07
7.1. Stack ADT.
Stack is a type of abstract data (ADT) commonly used in many programming languages. It is
called a stack because it behaves like a real-world stack, for example a deck of cards or piles
of sheets. Allows a real-world stack to operate only at one end. For example, it is possible to
place or remove a card or plate just above the stack. Similarly, stack ADT allows only one
end for all data operations. Anytime, only the top component of a stack can be accessed. This
feature converts it into a LIFO data structure. LIFO means Last-in-first-out. Here, the last
positioned (inserted or added) element is first accessed. In bulk terminology, the insertion
operation is called the PUSH operation and the removal operation is called the POP
operation. [ CITATION tut216 \l 1033 ]

Figure 31 Stack ADT (Author Developed)


Task 08
References

brilliant, 2021. brilliant. [Online]


Available at: https://brilliant.org/wiki/bellman-ford-algorithm/
geeksforgeeks, 2021. geeksforgeeks. [Online]
Available at: https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/
interviewbit, 2021. interviewbit. [Online]
Available at: https://www.interviewbit.com/tutorial/sorting-algorithms/
java, 2021. javatpoint. [Online]
Available at: https://www.javatpoint.com/ds-stack-vs-queue
javatpoint, 2021. javatpoint. [Online]
Available at: https://www.javatpoint.com/data-structure-tutorial
javatpoint, 2021. javatpoint. [Online]
Available at: https://www.javatpoint.com/ds-array-vs-linked-list
scientecheasy, 2021. scientecheasy. [Online]
Available at: https://www.scientecheasy.com/2020/07/encapsulation-in-java.html/
searchsqlserver, 2021. searchsqlserver. [Online]
Available at: https://searchsqlserver.techtarget.com/definition/data-structure
study, 2021. study. [Online]
Available at: https://study.com/academy/lesson/stacks-in-computer-memory-definition-uses.html
studytonight, 2021. studytonight. [Online]
Available at: https://www.studytonight.com/data-structures/queue-data-structure
tutorialride, 2021. tutorialride. [Online]
Available at: https://www.tutorialride.com/data-structures/searching-in-data-structure.htm
tutorialspoint, 2021. tutorialspoint. [Online]
Available at: https://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm
tutorialspoint, 2021. tutorialspoint. [Online]
Available at: https://www.tutorialspoint.com/abstract-data-type-in-data-structures
tutorialspoint, 2021. tutorialspoint. [Online]
Available at: https://www.tutorialspoint.com/java/java_encapsulation.htm
tutorialspoint, 2021. tutorialspoint. [Online]
Available at: https://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm

You might also like