You are on page 1of 80

HND in Computing - App.Dev / SW. Eng.

Pathway

Higher Nationals - Summative Assignment Feedback Form


Student Name/ID S.M. Sahan Sudharaka Wickramasinghe, ANU/A-008550
Unit 19 : Data Structures and Algorithms
Unit Title
1 MR. H.N.B. Herath
Assignment Number Assessor
Date Received 1st
Submission Date 28/06/2021 submission
Date Received 2nd
Re-submission Date
submission
Assessor Feedback:
LO1 Demonstrate a range of interpersonal and transferable communication skills to a target
audience Pass, Merit & Distinction P1 P2 M1 M2 D1
Descripts

LO2 Apply critical reasoning and thinking to a range of problem-solving scenarios


Pass, Merit & Distinction P3 M3 D2
Descripts

LO3 Discuss the importance and dynamics of working within a team and the impact of team working in
different environments
Pass, Merit & Distinction P4 P5 M4 D3
Descripts

LO4 Examine the need for Continuing Professional Development (CPD) and its role within the workplace
and for higher level learning
Pass, Merit & Distinction P6 P7 M5 D4
Descripts

Grade: Assessor Signature: Date:

Resubmission Feedback:

Grade: Assessor Signature: Date:

Internal Verifier’s Comments:

Signature & Date:

1
Data Structures and Algorithms Unit 19 S.M. Sahan Sudharaka Wickramasinghe
* Please note that grade decisions are provisional. They are only confirmed once internal and external moderation has taken place
and grades decisions have been agreed at the assessment board.

Assignment Feedback
Formative Feedback: Assessor to Student

Action Plan

Summative feedback

Feedback: Student to Assessor

Assessor Date
signature

Student Date
signature
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: sudarakasahan@gmail.com Date: 28/06/2021


(Provide E-mail ID) (Provide Submission Date)
HND in Computing - App.Dev / SW. Eng. Pathway
Assignment Brief
Student Name /ID Number S.M. Sahan Sudharaka Wickramasinghe, ANU/A-008550
Unit Number and Title Unit 19: Data Structures and Algorithms
Academic Year 2020/21
Unit Tutor Data Structures and Algorithms
Assignment Title Specification, Implementation, and Assessment of Data Structures for a
sample scenario.
Issue Date 16/02/2021
Submission Date 28/06/2021
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.

6
Data Structures and Algorithms Unit 19 S.M. Sahan Sudharaka Wickramasinghe
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.

7
Data Structures and Algorithms Unit 19 S.M. Sahan Sudharaka Wickramasinghe
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.

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: Determine the operations of a memory stack and critically review how it is used to
implement function calls related to the above scenario.

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? Discuss 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.

10
Data Structures and Algorithms Unit 19 S.M. Sahan Sudharaka Wickramasinghe
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
List of Figure..........................................................................................................................15
List of Tables..........................................................................................................................16
Task 1......................................................................................................................................17
Examine and create data structure by simulating the above scenario and explain the
valid operations that can be carried out on this data structure.........................................17
Task 2......................................................................................................................................26
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.......26
2.1 Tase case..................................................................................................................................32
Task 3......................................................................................................................................41
Determine the operations of a memory stack and how it is used to implement function calls
related to the above scenario........................................................................................................41
3.1 Advantages of disadvantages of stack-based CPU organization..........................................44
Task 4......................................................................................................................................45
Sort the banquets halls with two different sorting algorithms and critically review the
performances of those two algorithms by comparing them...............................................45
Task 5......................................................................................................................................50
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..............................................................................................50
Task 6......................................................................................................................................57
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 behavior. It makes programming simple, readable, and makes programs
maintainable. Imperative ADTs are basis for object orientation. Do you agree? Discuss
your answer............................................................................................................................57
6.1 Advantages of Encapsulation and information and information hiding.............................60
6.2 Storing banquet hall details....................................................................................................61
Task 7......................................................................................................................................65
Implement the above scenario using the selected complex ADT by using java.
Demonstrate how the implementation of an ADT/algorithm solves the above problem.

Data Structures and Algorithms S.M. Sahan Sudharaka 13


Unit 19
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.......................................................65
Task 8......................................................................................................................................68
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.......................................68
8.1 Symptomatic analysis..............................................................................................................68
8.2 Discussing Asymptotic Analysis used to assess the effectiveness.........................................71
8.3 Advantages of Asymptotic Analysis.......................................................................................72
8.4 Reviewing the trade-off types when using ADT....................................................................72
8.5 Types of Space-Time Trade-off..............................................................................................72
8.6 Benefits of using independent data structures......................................................................75
Reference.................................................................................................................................79

Data Structures and Algorithms S.M. Sahan Sudharaka 14


Unit 19
List of Figure
Figure 1 Class queue................................................................................................................26
Figure 2 Static void queue Enqueue.........................................................................................27
Figure 3 Static void queue Display..........................................................................................28
Figure 4 Static void queue Display 2.......................................................................................28
Figure 5 Public class static Queue in java................................................................................29
Figure 6 Public class static Queue in java................................................................................30
Figure 7 Result.........................................................................................................................30
Figure 8 Result.........................................................................................................................31
Figure 9 Stack..........................................................................................................................42
Figure 10 push,peek,pop..........................................................................................................42
Figure 11 Stacks in Computer Memory...................................................................................44
Figure 12 Java code..................................................................................................................45
Figure 13 Bubblesort................................................................................................................46
Figure 14 Selection sort...........................................................................................................47
Figure 15 selection sort............................................................................................................48
Figure 17 Dijkstra’s algorithm 01............................................................................................51
Figure 18 Dijkstra’s algorithm 2..............................................................................................52
Figure 19 Dijkstra’s algorithm 3..............................................................................................53
Figure 20 Dijkstra’s algorithm 3..............................................................................................53
Figure 21 Source: Author developed.......................................................................................54
Figure 22 privet void................................................................................................................55
Figure 23 Vertex relaxation.....................................................................................................55
Figure 24 private void relax.....................................................................................................56
Figure 25 Abstract data Type...................................................................................................58
Figure 26 The stack ADT specification...................................................................................61
Figure 27 Inheritance...............................................................................................................63
Figure 28 Polymorphism..........................................................................................................64
Figure 29 Big Oh Notation, Ο..................................................................................................69
Figure 30 Omega Notation.......................................................................................................69
Figure 31 Omega Notation.......................................................................................................70
Figure 32 Fibonacci Numbers..................................................................................................73
Figure 33 Recursion.................................................................................................................74
Figure 34 Out put.....................................................................................................................74
Figure 35 Representation for string..........................................................................................75
Figure 36 Active the value.......................................................................................................76
Figure 37 that internal representation as a variable.................................................................76
Figure 38 New representation..................................................................................................77
Figure 39 new Representation..................................................................................................77
Figure 40 New representation..................................................................................................78
List of Tables
Table 1 Queue operation..........................................................................................................17
Table 2 Queue Enqueue...........................................................................................................18
Table 3 Table 1 test plan..........................................................................................................32
Table 4 TEST RESULTS.........................................................................................................33
Table 5 Table 3 test case 2.......................................................................................................34
Table 6 Table 4 test case 3.......................................................................................................35
Table 7 Table 5 test case 4.......................................................................................................36
Table 8 Table 6 test case 5.......................................................................................................37
Table 9 Table 6 test case 6.......................................................................................................38
Table 10 Table 7 test case 7.....................................................................................................39
Table 11 Table 7 test case 8.....................................................................................................40
Table 12 Abstract Data Type (ADT).......................................................................................41
Table 13 Algorithm comparison chart.....................................................................................49
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.

Author recommend queue data structure for this system. because “XYZ” hotel chain required
a waiting list program list program.
Must be included in the waiting list program:
-If customer is not responding with in a day, he/she is placed back into the waiting list
-If the customer requests any change or refuses to reserve, delete the reservation and enter the
back of the queue
The above requirements based on FIFO methodology.it are referred to first in the first exit
procedure. This is the main reason why I recommend the queue data structure to be more
suitable for this system.This is exactly how the queuing system works in the real world. If
you go to a reservation to book a dining room and are first in line, you will be the first to
make a reservation. The queue status is the same as when the data was first entered, the
queue would exit first, The process to add a clement into queue is called enqueue and the
process of removal of an element from queue is called dequeue,
Author The following is the function of the queue data structure
Queue operation
Operation Description
Dequeue () This function define the operation for
removing an element from queue
Enqueue () This function defines the operation for adding
an element into queue
Search Searching is an operation or a technique that
helps find place of a given element or value in
the list.
Init ()/ (is full,is empty ) This function is used for initializing the queue
Front Front is used to get the front data item from a
queue
Rear Rear is used to get the last item from a queue

Table 1 Queue operation


Source: Author developed
Queue data structure functions based on this requirement
1.when the client makes temporary reservation list.

1. Enqueue
A queue is the maintenance of two data indicators, the front and back steps must be taken to
reserve a queue

Example:

Table 2 Queue Enqueue


Source: (Tutorialspoint.com, 2019)

Step 01: Check is reservation queue.


Step 02: If queue is full then produce overflow error.
Step 03: If queue is not full, increment the rear pointer to point next empty space
Step 04: Add the reservation to the queue location where rear is pointing
Step 05: Return the success reservation

Rear Front
Waiting list reservation

Reservation 4 Reservation 2
Reservation 3 Reservation 1

After confirmation, the specific reservation should be removed from the waiting list. Add a
confirmed reservation
After the responding:

Rear Front

Reservation 4
Conform reservation

Reservation 3 Reservation 2 Reservation 1

2. The client made a temporary reservation but did not respond within a day
No change will occur if the customer does not respond that the reservation should wait

Front
Rear

Waiting list reservation

Reservation 2
Reservation 4 Reservation 3 Reservation 1

3. After confirmation, the customer does not change the requirements such as location,
number of guests.

Then there is no change in the confirm reservation.


Rear Front

Conform reservation

Reservation 4 Reservation 3 Reservation 2 Reservation 1

It will then be removed from the confirmed reservation and added to the waiting list

Rear Front

Conform reservation

Re move
Reservation 3 Reservation 2 Reservation 1

Reservation 4
Rear Front

Waiting list reservation

Reservation 4 Reservation 3 Reservation 2 Reservation 1

4. if the customer accepts the reservation without any changes

The customer then confirms the reservation and takes steps to remove it from the waiting list.
In addition, food is removed from the list of available foods.

Re move
Reservation 3 Reservation 2 Reservation 1

Reservation 4

Rear Rear

Conform reservation

Reservation 4 Reservation 3 Reservation 2 Reservation 1

5. if the customer accepts the reservation without any changes


Then go to the customer reservation confirmation reservation and remove from the waiting
list. In addition, food is removed from the list of available foods.

Remove Reservation 2 Reservation 1


Reservation 3

Rear Front

Conform reservation

Reservation 4 Reservation 3 Reservation 2 Reservation 1

Rear Front

Banquet hall available

Remov e
Banquet hall Banquet hall Banquet hall
3 2 1

Banquet hall 4
2. Dequeue
Separation from queues is a two-pronged process. Enter the front-rear reservation and remove
the reservation after access.

Step 01-chek if reservation queue is empty.


Step 02-if reservation queue is empty produce underflow error.
Step 03-if reservation queue is not empty, access the reservation where front is pointing.
Step 04- increment front point to point next available reservation
Step 05 -return success delete or removed function.

For the example:

-if customer not responding with in a day.


-if customer need to be changed their requirements.
-or reject the reservation
Whether the reservation queues are empty before the function is checked means that there is a
reservation or not. If there is no blank message and an error message is given, remove the
reservation and add it to the waiting list.

Rear Front

Conform reservation

Reservation 4 Reservation 3 Reservation 2 Reservation 1

After the checking reservation is not responding with in day. Then it should be removed and
give a chance to following reservation 2.
Rear Front

Conform reservation

Reservation 4 Reservation 3 Reservation 2

Reservation 1

3. Init ()

Is empty
Cheeks whether the queue is empty. (if is empty is true, then the additiona of an item is
possible. If this is false, then acknowledge with the message “queue is empty)

Is full
Cheeks whether the queue is full. (if is full is true, then the removal of an item is possible, if
this is false, then acknowledge with the message “Queue is full”)

4. Search

Searching ai an operation or a technique that helps find the place of a given element or value
in the list. Some of the standard searching technique that is being followed in the data
structure is listed below:
1. linear search or sequential search
2. binary search

Example of reservation search

The reservation search feature allows you to show reservations by selecting from a larger
search option. This feature provides access to create new reservations and modify exit
reservation information. Access to guest profiles, cancel reservations, cancel large
reservations, check guests and cancel checks

05.rear and front


According to my reservation system, the first customer is inserted behind one end (also called
the tail) and the existing customer is called the front (also called the head) at the other end.
This converts the queue into a FIFO (first out) data structure, which means that the first
entered customer will be removed first.
Task 2

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.

Class queue

Figure 1 Class queue


Source: Author developed
Static void queue Enqueue

Figure 2 Static void queue Enqueue


Source: Author developed
Static void queue Display

Figure 3 Static void queue Display


Source: Author developed

Figure 4 Static void queue Display 2


Source: Author developed
Public class static Queue in java

Figure 5 Public class static Queue in java


Source: Author developed
Figure 6 Public class static Queue in java
Source: Author developed

Figure 7 Result
Source: Author developed
Result

Figure 8 Result.
Source: Author developed
2.1 Tase case
TEST PLAN
Table 1 test plan
XYZ Hotels Reservation System

Test plan ID 01
Brief introduction This system is named as XYZ Hotels Reservation System, and
about the system it is a software which manages information about the
Customers and the recipients.
Brief introduction This document defines the plan for testing the Hotel
about the testing Reservation System, and this document supports the following
objectives objectives:
1. Testing the features of the system
2. List the recommended test requirements
3. Describing the recommended test strategies
4. List the deliverables elements of the test activities

Test items(modules) Functions of the system

Features to be tested Customer ID, Inserting Member Details, Inserting Member ID,
Inserting, Accepting the Customer, Rejecting the Customer,
Continuing the process, Ending the program
Test environment Esoft metro cumpus

Test Approach Black Box


Testing tasks Test planning, Test design, Test development, Test execution,
Test evolution
Test deliverables Test plan, Test environment, Test summary, Test result, Test
evaluation report.
Staffing and Training No needs
needs
Schedule 2nd April 2022, 8.00AM to 12.40PM

Table 3 Table 1 test plan


Source: Author developed
TEST RESULTS
TEST CASE 01
Table 2 test case 1
Project name: XYZ Hotels Reservation System

Test Case

Test unit: Inserting Member ID Test designed by: shan sudharaka


Test case ID: 01 Test designed date: 2nd April 2021

Test executed by: - shan sudharaka


Description: Inserting Member ID
Test execution date: 2nd may 2020
Test execution time: 8.00AM – 12.00
AM
Test data Expected Actual result Status
result (pass/fail)
Step 1: Run the program ID inserted ID inserted Pass
Step 2: Type the member ID
Member ID: 0085

Table 4 TEST RESULTS


Source: Author developed
TEST CASE 02
Table 3 test case 2
Project name: XYZ Hotels Reservation System

Test Case

Test unit: Inserting Member Details Test designed by: shan sudharaka
Test case ID: 02 Test designed date: 2nd April 2020

Test executed by: - shan sudharaka


Description: Inserting Member Details
Test execution date: 2nd May 2020
Test execution time: 11.10AM –
11.30AM
Test data Expected Actual result Status
result (pass/fail)
Step 1: Run the program Details Details inserted Pass
Step 2: Type the member ID inserted
Member ID: 0085
Step 3 – Type member details
Member name –
Member address–
Trincomalee
Member con.no – 0756863658

Table 5 Table 3 test case 2


Source: Author developed
TEST CASE 03
Table 4 test case 3
Project name: XYZ Hotels Reservation System

Test Case

Test unit: Inserting Customer ID Test designed by: shan sudaraka


Test case ID: 03 Test designed date: 2nd April 2021

Test executed by: - shan sudaraka


Description: Inserting Customer ID
Test execution date: 2nd May 2021
Test execution time: 8.00AM –
11.40AM
Test data Expected Actual result Status
result (pass/fail)
Step 1: Run the program ID inserted ID inserted Pass
Step 2: Type the Customer ID
Customer ID: 0085

Table 6 Table 4 test case 3


Source: Author developed
TEST CASE 04
Table 5 test case 4
Project name: XYZ Hotels Reservation System

Test Case

Test unit: Inserting Customer Details Test designed by: shan sudaraka
Test case ID: 04 Test designed date: 2nd April 2021

Test executed by: - shan


Description: Inserting Customer Details
Test execution date: 2nd may 2021
Test execution time: 8.00PM –
12.00PM
Test data Expected Actual result Status
result (pass/fail)
Step 1: Run the program Details Details inserted Pass
Step 2: Type the Customer ID inserted
Customer ID: 001
Step 3 – Type Customer
details
Customer name – sadun
Customer address – Jaffna
Customer con.no -
0775240208

Table 7 Table 5 test case 4


Source: Author developed
TEST CASE 05
Table 6 test case 5
Project name: XYZ Hotels Reservation System

Test Case

Test unit: Accepting the Customer Test designed by: shan sudaraka

Test case ID: 05 Test designed date: 2nd April 2020

Test executed by: -shan


Description: Accepting the Customer
Test execution date: 2nd May 2021

Test execution time: 8.10PM – 12.20PM

Test data Expected Actual result Status


result (pass/fail)

Step 1: Run the program Customer Customer accepted Pass


Step 2: Input the member ID accepted
Step 3: Input Member details
Step 4: Input the Customer ID
Customer ID: 0085

Table 8 Table 6 test case 5


Source: Author developed
TEST CASE 06
Table 6 test case 6
Project name: XYZ Hotels Reservation System

Test Case

Test unit: Rejecting the Customer Test designed by: shan sudaraka

Test case ID: 06 Test designed date: 2th July 2020

Test executed by: -shan


Description: Rejecting the Customer
Test execution date: 2nd April 2021

Test execution time: 12.20PM – 1.30


PM
Test data Expected Actual result Status
result (pass/fail)

Step 1: Run the program Customer Customer rejected Pass


Step 2: Input the member ID rejected
Step 3: Input Member details
Step 4: Input the Customer ID
Customer ID: Press 0

Table 9 Table 6 test case 6


Source: Author developed
TEST CASE 07
Table 7 test case 7
Project name: XYZ Hotels Reservation System

Test Case

Test unit: Continue the process Test designed by: shan sudaraka

Test case ID: 07 Test designed date: 2nd April 202

Test executed by: - shan


Description: Continuing the process
Test execution date: 2nd may 2021
Test execution time: 1.30PM – 2.00PM

Test data Expected Actual result Status


result (pass/fail)

Step 1: Run the program Program is Program is running Pass


Step 2: Input the member ID running
Step 3: Input Member details
Step 4 : Input the Customer ID
Input: True

Table 10 Table 7 test case 7


Source: Author developed
TEST CASE 08
Table 7 test case 8
Project name: XYZ Hotels Reservation System

Test Case

Test unit: Ending the process Test designed by: shan

Test case ID: 08 Test designed date: 2nd April 2021

Test executed by: - shan sudaraka


Description: Ending the process
Test execution date: 2nd may 2021
Test execution time: 12.40PM

Test data Expected Actual result Status


result (pass/fail)

Step 1: Run the program Program is Program is stopped Pass


Step 2: Input the member ID stopped
Step 3: Input Member details
Step 4: Input the Customer ID
Input: False

Table 11 Table 7 test case 8


Source: Author developed
Task 3
Determine the operations of a memory stack and how it is used to implement
function calls related to the above scenario.
1. A stack

A stack is an Abstract Data Type (ADT), commonly used in most programming


languages. It is named stack as it behaves like a real-world stack, for example – a
deck of cards or a pile of plates, etc.

Table 12 Abstract Data Type (ADT)


Source: (Educative: Interactive Courses for Software Developers, n.d.)
Stack Example-
A real-world stack allows operations at one end only. For example, we can place or remove a
card or plate from the top of the stack only. Likewise, Stack ADT allows all data operations
at one end only. At any given time, we can only access the top element of a stack.
This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the
element which is placed (inserted or added) last, is accessed first. In stack terminology,
insertion operation is called PUSH operation and removal operation is called POP operation.

Source: (Educative: Interactive Courses for Software Developers, n.d.)


A stock is a data structure that follows the LIFO (Last In, First Out) principle.

just assume a stack of hotel reservations.

-In a stack of hotel reservations, you can only see


the top reservation

-If you want to access any other customer reservation, you would first need to remov

-customer reservation on top of it


The bottom-most reservation in the stack was put

-first and can only be removed at the last after all reservations on top of it have been

Figure 9 Stack
Source: (Khoja.S, n.d.)

Figure 10 push,peek,pop
Source: (Khoja.S, n.d.)
PUSH Operation
The pushing process is the incorporation of an element into the stock. Since there is only one
place where the new element can be inserted - at the top of the stock, the new element is
inserted at the top of the stock.

POP Operation
The pop operation is the removal of an element. Again, we only have access to the element at
the top of the stock, so we can only remove one element. We remove the top part of the
stock. Note: We can choose to return the value of the popped element, this is the
programmer's choice for full implementation.

PEEK Operation
The maximum function allows the user to view the element at the top of the stock. The stock
does not change in any way during this operation.

Is Empty: Check if the stock is empty

In order to prevent operations on a blank stock, the programmer needs to maintain the size of
the push internally and thus update during push and pop operations. isEmpty () Traditionally
gives a boolean value: magnitude 0 is true or false.
Stacks in Computer Memory
Memory stocks are linear data structures (locations) used to store data in a computer's
memory. They are also known as queues. The data in a stock must always be of the same
type.

Figure 11 Stacks in Computer Memory


Source: (Study.com, 2020)

Memory stock illustration


Items in a stock are inserted or removed in a linear order. Like any assembled queue or
collection, the data items in a warehouse are stored and accessed in a specific way. In this
case, a technology called LIFO (Last In First Out) is used. This includes a series of insertion
and removal operations.
Source: (Study.com, 2020)

3.1 Advantages of disadvantages of stack-based CPU organization

Advantages

1. Efficient computation of complex arithmetic expressions


2. execution of instructions is fast because operand data are stored in consecutive
memory location.
3. Length of instructions is short as they do not have address field.

Disadvantages
1. the size of the program increases
2. Stack based CPU organization user zero address instruction.
Task 4
Sort the banquets halls with two different sorting algorithms and critically review the
performances of those two algorithms by comparing them.
The author selected in two sorting algorithms
1. Bubble Sort algorithms
2. Selection sort algorithms
1.Bubble sort algorithm
Bubble sorting is a simple sorting algorithm. This sorting algorithm is an element in
which each adjacent element pair is compared and they are switched if the element is not
in order. This algorithm is not suitable for large datasets. Its average and worst
complexity is complexity (n2) and n is the number of items.
(Tutorialspoint.com, 2019)

java code

Figure 12 Java code


Source: Author developed
Figure 13 Bubblesort
Source: Author developed

2.Selection sort

Selection sorting is a simple sorting algorithm. This sorting algorithm is an


algorithm based on the comparison of two places, the list is divided into two parts,
the sorted part in the left corner and the unclassified part in the right corner.
Initially, the sorted section is empty, and the unclassified section is the full list.
(www.tutorialspoint.com, n.d.)
Figure 14 Selection sort
Source: Author developed
Figure 15 selection sort
Source: Author developed
Bubble sort algorithm vs selection sort algorithm comparison chart

Basis for comparison Bubble sort Selection sort


Basic Adjacent element is Largest element is selected
compared and swapped and swapped with the last
element (in case of
ascending order).
Efficiency Inefficient Improved efficiency as
compared to bubble sort
Best case time complexity O(n) O(n2)
Method Exchanging Selection
stable yes no
speed slow Fast as compared to
bubble sort

Table 13 Algorithm comparison chart


Source: Author developed

The author suggests that the selection sort algorithm is appropriate because the
selection sort algorithm is faster than the bubble sort.
Also, bubble sorting means using item swapping and item selection. The bubble
sorting algorithm is considered to be the simplest and most efficient algorithm, but
the selection sorting algorithm is relatively efficient compared to the bubble sorting.
Bubble sorting consumes extra space to store the temporary variable and requires
more exchange space.
(Tech Differences, 2017)
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.

Searching method
Search is an operation or technique that helps to find the place of a given element or
value in a list. Any search is said to be successful or unsuccessful depending on
whether the search feature is found or not. Some of the standard search methods
used in a database are element tables, files, simple data elements in arrays, tree
nodes, vertical and edge elements, or charts in other search locations.
(Tech Differences, 2017)

There are 8 hotels in the Southern District of Sri Lanka. A customer plans to visit all
eight of these hotels within a day on the shortest route. Analyze the operation using
examples from two shortcut algorithms.Implementation using a sample graph.

The above scenario gives us an example of using the shortest route algorithm.
Therefore, as mentioned here, there are 8 hotels in the Southern Province. Here we
have to find the shortest route to each of these hotels. So, these hotels are shown in
the chart below, including Route 8. The route is the distance from one hotel to
another. Here are three separate districts in the Southern Province for hotels. A1, A2
are hotels in the HIKKADUWA in Galle District of the Southern Province, and B1,
B2, B3 are hotels in the MIRISSA in Matara District of the Southern Province. C1,
C2, C3 are hotels in the AMBALANTHOTA in Hambanthota District of the
Southern Province.
The author illustrates the graph with,

1. A1, A2 - Hikkaduwa
2. B1, B2, B3 -Mirissa
3. C1, C2, C3 - Ambalanthota
1. Assign a distance value to all verticals in the input group
2. Start all distance values as infinity
3.Assign distance values to infinity

Assign the distance value to 0 for the origin header, then it will be selected first
All we have to do is find the shortest way to get to these 8 hotels using the chart below.
To do this, Author use two separate sorting algorithms.

-Dijkstra’s algorithm
The Dijkstra’s algorithm allows you to calculate the shortest path between one selected
node and each other node in a graph.

Figure 16 Dijkstra’s algorithm 01


Source: Author developed
We need to scan the nodes one by one in a few steps to find the shortest path. The steps are as
follows.

Step 01

I will choose A1 as the starting point here. Then, we want to find next node to be traversed.
So, according to the above algorithm we want to find least distance to traversed. Therefore,
B1 is located in long distance as 53KM but A2 is located in a shortest distance as 15Km. So,
first we traversed to A2.
Step 02
In this step we can traverse one node, It is node B2 with 21KM distance. So, at this step we
have traversed 3 Hotels such as A1, A2, B2.

Figure 17 Dijkstra’s algorithm 2


Source: Author developed

Step 3
We are in this step at B2 Hotel. So, we have 4 hotels to traverse from B2. Namely, B1, B3,
C2, C 3. So, we should traverse a hotel with the shortest distance. So, the shortest distance
has to B3 Hotel, distance is 7KM. So, let's traverse to it.
Figure 18 Dijkstra’s algorithm 3
Source: Author developed

STEP 4

A1 starting point

Figure 19 Dijkstra’s algorithm 3


Source: Author developed
There is only one path from B3. That is C3 witch the distance 60 km

Step 5

Now we are in C3 there is only one path. From C3. That is C2 witch the distance.

Step 6

There are two hotel that we can go from C2 57km distance. from C2 57 km distance
from C2 to B1 and 11km distance. From C2 to B1 and 11 km distance from C2 to C1.we can
selected the next as C1.

Step 7
Only one hotel we have to go now, witch the distance 50km from H1, the hotel is B1

Figure 20 Source: Author developed


Source: Author developed

Relaxation algorithm

Our shortcut execution area is based on an operation called mitigation. We start with disto [s]
to 0 for all other verticals and disto [v] to infinity. Loosening an edge means testing to see if
the best way from s to w is to move from s to v, then move the edge from v to w, then we
need to update our data structures
Vertical relaxation. All our activations actually loosen all the edges that point from a given
header.

Figure 21 privet void Source:


(algs4.cs.princeton.edu, n.d.)

Figure 22 Vertex relaxation


Source: (algs4.cs.princeton.edu, n.d.)
Vertical relaxation. All our activations actually loosen all the edges that point from a given
header.

Figure 23 private void relax


Source: (algs4.cs.princeton.edu, n.d.)
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 behavior. It makes programming simple, readable, and makes
programs maintainable. Imperative ADTs are basis for object orientation. Do you
agree? Discuss your answer.

Author agree
Abstract Data Type (ADT) A series of information and a fixed of operations that perform on
that information is referred to as an summary information type. ADT binds information and
operations together. This so-referred to as closed feature creates the interface of ADT. Data
move is likewise called information hiding. Here the information is hidden to the consumer
due to the fact the consumer can get entry to the information the use of unique features
referred to as methodology. The gadget allows positive regulations on get entry to to
constrained information. In programming, information is posted privately and strategies or
features are made public. The benefit of information consolidation is that it's miles very
critical to shield the data while the use of the gadget. Data is covered from encryption and
hidden from the outdoor world. For example, humans watch tv however the man or woman
looking it does now no longer recognize the intricacies of tv. In turn, the man or woman sees
a lovely color screen. Users get entry to ADT thru operations. Users do now no longer see
how the operation works outdoor. This is referred to as data concealment, so customers can
recognize ADT now no longer with the aid of using the way it works, however with the aid of
using the way it works.
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 we can use these data types and we
can 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, lists, and so on.

Figure 24 Abstract data Type


Source: Author developed

Let us see some operations of those mentioned ADT −

Stack –
A stock is a last activated linear data structure (LIFO).
Final Out (FILO) Order. The last item to go in is to go out. It operates in two basic operations
Called push and pop. The push operation always adds an item to the top of the stock and
pops it together
Operation removes an item from the top of the inventory. Inventory is always accessible
Up. Contains a stock of the same type of element arranged in sequence.

1. Push () - Insert an element in the vertical plane called the top.

2. Pop () - If not, remove the element at the top of the stack and send it back.
3. Quantity () - Return the number of elements in stock.

4. Is Empty () - Return to true if the stock is empty, or return to false.


5. IsFull () - Return to true if the stock is full, or return to false.

Queue −
Queues are used to retain items needed for processing and different types are provided
Operations such as removal and insertion. New items are added to the queue data structure
The back (tail) and existing items are removed from the front (head) and also contain the
element.
1. The same type is arranged in sequential order.
2. Enqueue ( ) : Insert an element at the tail of the queue.
3. Dequeue ( ) : Remove and return the first element at the head of the
4. Size ( ): Return the number of elements in the queue.
5. Is Empty ( ): Return true if the queue is empty, if not return false.
6. Is Full ( ): Return true if the queue is full, if not return false

List ADT –
1. Get (): Return an element from the given location list.
2. Insert (): Insert an element anywhere in the list.
3. Remove (): Remove the first instance of any element from a non-empty list.
4. Remove (): Here we can remove the element at the identified location from a non-
empty location List.
5. Replace (): Replace an element anywhere with the next element.
6. Size (): Return the number of elements in the given list
7. blank (): If the list is empty go back to true, otherwise it is false.
8. is full (): Go back to true if the list is full, otherwise it is
false. The queue abstract data type
The queue abstract data type is defined by the following structure and operations. As
described above, a queue is structured so that it has a collection of items called "back" at one
end and "front" at the other end. Queues FIFO property orders. Queue operations are as
follows.
1. Queue () Creates an empty new queue. It does not require parameters and provides
an empty queue.
2. enqueue (item) Adds a new item to the back of the queue. It requires the item and
nothing will be returned.
3. dequeue () Removes the front item from the queue. It does not require parameters
and returns the item. The queues have changed.
4. Is Empty () tests to see if queues are empty. It does not require parameters and gives a
Boolean value.
5. Size () returns the number of items in the queue. It does not require parameters
and gives an integer.
For example, if q creates a queue and assumes that it is currently empty, Table 1 shows the
results of the queue operation sequence. The contents of the queue are shown on the front
right. 4 is the first item and is the first item returned by the Duke.
6.1 Advantages of Encapsulation and information and information hiding
1. Reusability
It allows the programmer to reuse programming / encoding methods. Are ADTs Independent
components with high integrity and low connectivity. They can be easily reused in other
ways Applications.
2. Ease of maintenance
ADT is an independent component that does not convert personal data to ADT
Other components may cause side effects. This makes the software very easy to maintain
3. Implementation independence
Has a common interface with ADT operations. How to execute operations
Hidden from end user. Therefore, the implementation can be changed as long as the operation
exists Stay the same.
4. Flexibility
With this we only need to write or read the data
5. Testing of the code
Easy to coding
6. Data Hiding
This allows the programmer to hide the key and give access only to what the user wants.
Codes. It allows developers not to let the user know how to store variables and data.
6.2 Storing banquet hall details
We can use the inventory to store restaurants from the newest to the oldest. Inventory is
abstract data the type that last activates for the first time. The inventory always has access to
the chief Array. New items are added to the top and existing items are removed from the top.
Stock Let us get the first and oldest newest halls the stack ADT specification
Pop () 1. Post-conditions: Top elements removed from stock
2. Input: Inventory
3. Output: Modified stock, upper element removed from stock
4. Algorithm: remove the top element of the stack; Give me a copy
5. Element to the user
6. Exception: Empty
7. Pre-conditions: stack is not empty
Init() 1. Post-conditions: stack is defined and empty
2. Pre-conditions: non
3. Input: No inputs required
4. Output: Invented
5. Algorithm: Start the bulk index
Push (element) 1. Post-conditions: element is put onto the top of the stack
2. Pre-conditions: the stack exits, input element is of appropriate type
3. Input: Inventory and component
4. Output: Modified stock of elemental added
5. Algorithm: Insert the element at the top of the stack
6. Exception: bulk overflow
Is Available(elements) 1. Post-conditions: return true if element available /otherwise return.
2. Pre-conditions: In stock, the input element is of the appropriate type.
3. Input: stock, search elements
4. Output: Boolean value
5. Algorithm: Find the given element from top to bottom
6. Exception: Empty blanks

Figure 25 The stack ADT specification.


Source: (Coursehero.com, 2021)
How ADTs relate to object-oriented programming

Uses OOP classes and objects. A class is a template / plan for a similar group of objects. class
Defines data and operations for a similar set of objects. Can define something like a vehicle
class. Vehicle number and speed as vehicle model and operation. Once the class is defined
we Individual vehicle objects can be created. An object is an example of a class. If the idea of
a class. Similar to ADT. They both combine data and operations. Therefore, ADTs may be
Considered as the basis of object orientation. However, OOP's classes are superior to ADT's
Because they support other programming features such as inheritance and polymorphism.

Therefore, Author agree with this object-orientation, that a computer program is driven by
objects called other objects and ultimately produces program behavior. It makes
programming simple, readable and maintainable. Essential ADTs are the basis for object
orientation.

Inheritance
Inheritance in Java is a mechanism by which one object acquires all the attributes and
behaviors of a mother's object. It is an important part of OOPs (Object Oriented
Programming System).
The idea behind Java's legacy is that you can create new classes built on existing ones. Once
you inherit an existing class, you can reuse local class methods and fields. Additionally, you
can add new methods and fields to your current class.
Inheritance represents the IS-A relationship, also known as the parent-child relationship.
(Coursehero.com, 2021)
for an example

Figure 26 Inheritance
Source:(Chaudhary.M, 2020)

Polymorphism

Polymorphism is one of the four main concepts behind object-oriented programming (OOP).
OOP questions are very common in job interviews, so expect multimeter questions in your
next Java job interview.

For example:

In this example, 3 classes are created to represent the polynomial and one class is created to
test the concept. Our super class is called animals. The successors to the animal class are the
dog and cat classes. Those animals, right? That’s what polynomials are - you have many
forms of the same object with slightly different behaviors. To illustrate this, a method called
make Sound () will be used to bypass the output of this method in sequential classes.
Figure 27 Polymorphism
Source: (Java Polymorphism Example | Java Tutorial Network. 2021.)
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.

The author of Task 3 briefly mentions stocks. Now I execute the ADT stack using the array
Data structure. For example, the author pushes 3 data elements into the following array.

Push (80), push (112), and push (170)

0 01 02 03 04
80 112 170

Stack pointer = 2

The coder below shows only a single stack to keep hall ids.

Public class stack {

private int stptr; private int [ ]T; public stack (int size) {

T= new int[size];

}
Public void init()
{
Stptr = -1;
}
Public void push (int data)
{
if (stptr = = T.length -1)
system.out.println(“stack full”)
else
{
Stptr ++;
T[stptr] = data;
}
}// end push
public int pop ()
{int data;
if (stptr = = -1)
{
System.out.println(“stack empty”);
Return 0;
}
else
{
data = T[stptr];
stptr - - ;
return data;
}
}// end loop
public boolean isAvailable(int item)
{ int x = 0;
while (x<T.length)
{ if (item = = T[x])
return true;
else
x + +;
}
return false;
}
}// end stack

Critical Evaluation of the ADT Algorithm

The above algorithm solves the problem of storing dining room ID cards from the latest to
old Orders. Whatever it is, there is some sort of weaknesses. Because this is an array
activation the quantity of stock should be defined in advance. Once we have defined it, the
size cannot be changed. If
We declare it too large, then the store is wasted. If the array is too small, the stock will
overflow Held. Another factor is the efficiency of the "existing" operation. This operation a
Search inventory lines. This could be a slow process if we declare a large stock with
thousands from the elements.

Different ways of measuring of an algorithm

Important resources such as time and space complexity cannot be directly compared, so the
complexity of time and space can be considered for algorithm efficiency.
The efficiency of an algorithm depends on how efficiently it uses time and memory space.
The time efficiency of an algorithm is measured by various factors. For example, write a
program for a defined algorithm, execute it using any programming language, and measure
the time it takes to execute. The measured activation time in this case depends on a number
of factors:

1. Machine speed

2. Compiler and other system software tools

3. operating system

4. The programming language used

5. Data Required Data Volume

(BrainKart, n.d.)
Task 8
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.

8.1 Symptomatic analysis

Give two algorithms

Symptomatic analysis of an algorithm is the mathematical binding / framing definition of its


runtime function. Using asymmetric analysis, we can guess the best case, average case and
worst case of an algorithm.Asymmetric analysis is input bound, i.e., if the algorithm has no
input, it is concluded to work at a constant time. All factors other than "input" are considered
constant.Asymmetric analysis is the calculation of the running time of any operation in
mathematical units. For example, the running time of one operation is calculated as f (n) and
for another operation it is calculated as g (n2). This means that the run time of the first
operation increases linearly with increasing n, and n increases as the running time of the
second operation increases. Similarly, if n is significantly smaller, the running time of both
operations is approximately the same.

1. In general, the time taken for an algorithm falls into three categories -
2. Best time - Minimum time required to run programs.
3. Normal Case - The average time required to run a program.
4. Worst case scenario - maximum time required to execute programs.

Asymptotic Notations

The following are the most commonly used asymmetric notations for calculating the running
time complexity of an algorithm.

1. Notation
2.  Notation
3.  Notation

1. Big Oh Notation, Ο
Ο (n) notation is the formal method of expressing the upper limit of the running time of an
algorithm. It measures the worst time complexity or the longest time it can take to complete
an algorithm.
Figure 28 Big Oh Notation, Ο
Source:(Author adapt course.ccs.neu.edu, n.d.)

Ο(f(n)) = { g(n) : there exists c > 0 and n0 such that f(n) ≤ c.g(n) for all n > n0. }

2.  , Omega Notation

The lower limit of the running time of the algorithm is the formal method of expressing the 
(n) numbering. It measures the best time or the best time it can take to complete an algorithm

Figure 29 Omega Notation


Source:(Author adapt course.ccs.neu.edu, n.d.)
Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all n > n0. }

3.  Theta Notation

θ(f(n)) = {g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n)) for all n > n0. }

source: (Tutorialspoint.com, 2019)

Figure 30 Omega Notation


Source:(Author adapt course.ccs.neu.edu, n.d.)

Benefits and drawbacks of using ADT

Benefits

Agent Independence: Most programs are independent of abstract data representation, which
can improve performance without interrupting the entire program.
Modularity: With representation independence, different parts of a program do not depend on
other parts, but on how other parts work.
Stock Exchange Capacity: Different implementations of an abstract data type may have
different performance characteristics. With abstract data types, activating its data types for
each part of a program is easy to use, making it more efficient for a specific part of the
program.

Source:(course.ccs.neu.edu, n.d.)
Drawbacks –

1. Must have more code: getters / setters' methods to write

- A class enabled as ADT must present getters / setters methods and techniques that allow
access to the 'attributes' of the client code.

- More code means - more testing, more room to introduce errors in our code

2. Limited access: We, as the class user (as the server coder who uses the class), may be
limited by the class 'common methods'.

- Operations that we like to "on" objects in this class may include operations that are not
presented in the class 'common interface'.

Source: (slideplayer.com, n.d.)

8.2 Discussing Asymptotic Analysis used to assess the effectiveness

Given 2 algorithms for a task, however will we ascertain that one is better?

There may be one childish way to do this - implement each algorithm and run 2 programs on
the laptop for different applications and see that it takes less time. Measure some of the
problems with this approach to analyzing the algorithm.

1. It might be attainable that for a few inputs, 1st rule performs higher than the second.
And for a few inputs second performs higher.
2. It might even be potential that for a few inputs, 1st algorithmic rule perform higher on
one machine and therefore the second works higher on different machine for a
few different inputs.

The big idea that handles the above problems when analyzing algorithms is asymmetric
analysis. In asymmetric analysis, we estimate the performance of an algorithm based on the
input volume (we do not measure the actual running time). We calculate how much time (or
space) an algorithm increases with the input size.

(GeeksforGeeks, 2012)
8.3 Advantages of Asymptotic Analysis
Asymmetric analysis is very helpful to analyze the efficiency of an algorithm with runtime
inputs. Otherwise, it can happen if we do it using test cases for different inputs- the
performance may change when the input given to the algorithm changes. The functionality of
the algorithm changes when running on different machines.

Thus, providing a mathematical representation gives a proper understanding of the upper and
lower limits of the running time of the algorithm. This prompts us to select an algorithm
whose performance does not change as the number of inputs provided increases.
(EDUCBA, 2019)
8.4 Reviewing the trade-off types when using ADT

A trade is a situation where one thing increases and another decreases. Here's how to fix the
problem:
1. Either in less time and using more space

2. In a very small space by spending a long time.

8.5 Types of Space-Time Trade-off

Compressed or Uncompressed Data: Spatial trading can be applied to the problem of data
storage. If the stored data is not compressed, it will take up more space but take less time. But
if the data is stored compressed, it will take up less space but will take longer to execute the
decompression algorithm. There are many opportunities to work directly with compressed
data. In compressed bitmap indicators, working with compression without compression is
faster.

Reloading or storing images: In this case, storing only the source and rendering it as an
image will take more time, but it will take less time, that is, storing an image in the cache will
be faster than reloading but will require more memory.

Shortcode or loop unrolling: Shortcode has less space in memory but requires a longer
computation time to jump back to the beginning of the loop at the end of each stop. Loop
unrolling allows you to optimize the execution speed according to the increased binary size
cost. It has more space in memory but requires less computational time.
Query Tables or Recalculation: In a viewing table, activation can include a complete table
that reduces computer time but increases the required amount of memory. It can be
recalculated, counting table entries as needed, increasing computer time but reducing
memory requirements.

For example: Mathematically, the Fn sequential iteration of Fibonacci numbers is defined by:

Figure 31 Fibonacci Numbers


Source: (GeeksforGeeks, 2020)

A simple solution to find the term Nth Fibonacci using the iteration of the recurrence link
above.
Implementation using repetition is as follows:

Figure 32 Recursion
Source: (GeeksforGeeks, 2020)

Figure 33 Out put


Source: (GeeksforGeeks, 2020)
8.6 Benefits of using independent data structures

Abstract data types offer several advantages over concrete data types

Representation Independence: Most programs are independent of abstract data


representation, which can improve performance without interrupting the entire program.

Modularity: With representation independence, different parts of a program do not depend


on other parts, but on how other parts work.

Interchangeability of Parts: Different implementations of an abstract data type may have


different performance characteristics. With abstract data types, it is easy to use activating its
data types for each part of a program, making it more efficient for a specific part of the
program.
Example: Different Representations for Strings

Figure 34 Representation for string


Source: (Author adapt, web.mit.edu, n.d.)
At this point, however, writing test cases using assert Equals directly on MyString objects
will not be successful, as we do not have a defined parity operation on these MyStrings. In
the next reading we will talk about how to carefully implement equality. Currently, the only
operations we can perform with MyStrings are the ones we have defined above: Value Off,
Length, Chart and Substrate. Our tests should be limited to those operations. For example,
here is one test to activate the value:

Figure 35 Active the value


Source:(Author adapted from web.mit.edu, n.d.)

After reading this the author returns to the question of ADT testing.

Now, let's look at a simple representation for MyString: an alphabet, exactly the length of the
strings (no extra space at the end). Here's how to express that internal representation as an
illustration variable in class:

Figure 36 that internal representation as a variable


Source: (Author adapted from web.mit.edu, n.d.)
With the selection of that representative, the operation will be executed in a simple manner:

Figure 37 New representation


Source: (Author adapted from web.mit.edu, n.d.)

This allows music to be enabled in some versions of Java.

To implement this optimization, we can change the internal representation of this class as
follows.

Figure 38 new Representation


Source: (Author adapted from web.mit.edu, n.d.)

With this new representation, operations now work as follows:


Figure 39 New representation
Source: (Author adapted from web.mit.edu, n.d.)

Existing clients in My String depend not only on its private domain, but also on the
specifications of its common methods, so we can check the server code and make this change
without modification. That is the power of representation independence.
Reference:

BrainKart. (n.d.). Efficiency of an algorithm. [online] Available at:


https://www.brainkart.com/article/Efficiency-of-an-algorithm_37217/. Accessed on April
12th 2021.

Chaudhary, M. (2020). OOPs: Inheritance and Polymorphism. [online] Medium. Available


at: https://medium.com/@cmukesh8688/oops-inheritance-and-polymorphism-2334d0dcab87.
Accessed on April 11th 2021.

course.ccs.neu.edu. (n.d.). Advantages of Abstract Data Types. [online] Available at:


https://course.ccs.neu.edu/cs5010f17/InterfacesClasses2/advantagesADT1.html?. Accessed
on April 15th 2021.

Coursehero.com. (2021). [online] Available at:


https://www.coursehero.com/u/file/52991016/task-6docx/?justUnlocked=1#question.
Accessed on April 15th 2021.

Coursehero.com. (2021). [online] Available at:


https://www.coursehero.com/u/file/52991016/task-6docx/?justUnlocked=1#question
Accessed on May 20th 2021.

Educative: Interactive Courses for Software Developers. (n.d.). Data Structures 101: how to
use Stacks and Queues in Java. [online] Available at: https://www.educative.io/blog/data-
structures-stack-queue-java-tutorial. Accessed on may 10th 2021.

EDUCBA. (2019). Asymptotic Analysis | Benefits and Top 5 Asymptotic Notations with
Graphs. [online] Available at: https://www.educba.com/asymptotic-analysis/. Accessed on
April 15th 2021.

GeeksforGeeks. (2012). Analysis of Algorithms | Set 1 (Asymptotic Analysis). [online]


Available at: https://www.geeksforgeeks.org/analysis-of-algorithms-set-1-asymptotic-
analysis/. Accessed on April 15th 2021.

GeeksforGeeks. (2020). Time-Space Trade-Off in Algorithms. [online] Available at:


https://www.geeksforgeeks.org/time-space-trade-off-in-algorithms/. Accessed on April 15th
2021.

Java Polymorphism Example | Java Tutorial Network. 2021. Java Polymorphism Example |
Java Tutorial Network. [ONLINE] Available at: https://javatutorial.net/java-polymorphism-
example. Accessed on April 15th 2021.

Khoja, S. (n.d.). Sort Stack. [online] sweprep.substack.com. Available at:


https://sweprep.substack.com/p/sort-stack. Accessed on May12th 2021.

Study.com. (2020). Stacks in Computer Memory: Definition & Uses | Study.com. [online]
Available at: https://study.com/academy/lesson/stacks-in-computer-memory-definition-
uses.html. Accessed on April 12th 2021.
Tech Differences. (2017). Difference Between Bubble Sort and Selection Sort (with
Comparison Chart). [online] Available at: https://techdifferences.com/difference-between-
bubble-sort-and-selection-sort.html#ComparisonChart. Accessed on April 12th 2021.

Tutorialspoint.com. (2019). Data Structure - Bubble Sort Algorithm - Tutorialspoint. [online]


Available at:
https://www.tutorialspoint.com/data_structures_algorithms/bubble_sort_algorithm.htm.
Accessed on April 12th 2021.

Tutorialspoint.com. (2019). Data Structures - Asymptotic Analysis - Tutorialspoint. [online]


Available at:
https://www.tutorialspoint.com/data_structures_algorithms/asymptotic_analysis.htm.
Accessed on April 15th 2021.

web.mit.edu. (n.d.). Reading 8: Abstract Data Types. [online] Available at:


http://web.mit.edu/6.005/www/fa14/classes/08-abstract-data-types/. Accessed on April 12th
2021.

www.tutorialspoint.com. (n.d.). Data Structure and Algorithms Selection Sort -


Tutorialspoint. [online] Available at:
https://www.tutorialspoint.com/data_structures_algorithms/selection_sort_algorithm.htm#:~:t
ext=Selection%20sort%2. Accessed on May12th 2021.

You might also like