You are on page 1of 81

Higher Nationals

Internal verification of assessment decisions – BTEC (RQF)

INTERNAL VERIFICATION – ASSESSMENT DECISIONS

Programme title Higher National Diploma in Computing

Assessor K.Ushamini Internal Verifier


Unit 19 – Data Structures and Algorithms
Unit(s)
Specification, Implementation, and Assessment of Data Structures for a sample
Assignment title
scenario.

Student’s name Singarasa Joyalraj

List which assessment criteria Pass Merit Distinction


the Assessor has awarded.

INTERNAL VERIFIER CHECKLIST

Do the assessment criteria awarded match


those shown in the assignment brief? Y/N

Is the Pass/Merit/Distinction grade awarded


justified by the assessor’s comments on the
Y/N
student work?

Has the work been assessed


Y/N
accurately?
Is the feedback to the student:
Give details:
• Constructive?
• Linked to relevant assessment criteria? Y/N
• Identifying opportunities for Y/N
improved performance? Y/N
• Agreeing actions? Y/N
Does the assessment decision need
Y/N
amending?

Assessor signature Date

Internal Verifier signature Date


Programme Leader signature (if required)
Date
Confirm action completed
Remedial action taken

Give details:

Assessor signature Date

Internal Verifier
Date
signature
Programme Leader
Date
signature (if required)
Higher Nationals - Summative Assignment Feedback Form
Student Name/ID Singarasa Joyalraj
Unit Title Unit 19: Data Structures and Algorithms

Assignment Number 1 Assessor


Date Received 1st
Submission Date submission
Date Received 2nd
Re-submission Date submission
Assessor Feedback:
LO1 Examine different concrete data structures and it’s valid operations.
Pass, Merit & P1 P2 M1 M2 D1
Distinction Descripts

LO2 Discuss the advantages, complexity of Abstract Data Type and importance concepts of
Object orientation.

Pass, Merit & P3 M3 D2


Distinction Descripts

LO3 Implement, Demonstrate and evaluate complex ADT algorithm.

Pass, Merit & P4 P5 M4 D3


Distinction Descripts

LO4 Examine the advantages of Independent data structures and discuss the need of
asymptotic analysis to assess the effectiveness of an algorithm.
Pass, Merit & P6 P7 M5 D4
Distinction Descripts

Grade: Assessor Signature: Date:


Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:
Signature & Date:
* 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 signature Date

Student signature Date


Pearson Higher Nationals in
Computing
Unit 19: Data Structures & Algorithms
Assignment 01
General Guidelines

• 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.

• Attach this brief as the first section of your assignment.

• All the assignments should be prepared using a word processing software.

• All the assignments should be printed on A4 sized papers. Use single side printing.

• Allow 1” for top, bottom , right margins and 1.25” for the left margin of each page.

Word Processing Rules

• The font size should be 12 point, and should be in the style of Time New Roman.

• Use 1.5 line spacing. Left justify all paragraphs.

• Ensure that all the headings are consistent in terms of the font size and font style.

• 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.

• Use word processing application spell check and grammar check function to help editing your
assignment.

Important Points:

• 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.

• Carefully check the hand in date and the instructions given in the assignment. Late submissions
will not be accepted.

• Ensure that you give yourself enough time to complete the assignment by the due date.

• Excuses of any nature will not be accepted for failure to hand in the work on time.

• You must take responsibility for managing your own time effectively.
• 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.

• Failure to achieve at least PASS criteria will result in a REFERRAL grade .

• Non-submission of work without valid reasons will lead to an automatic RE FERRAL. You will
then be asked to complete an alternative assignment.

• 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.

• 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.

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


• I understand the plagiarism and copying policy of Edexcel UK.
• I know what the consequences will be if I plagiarise or copy another’s work in any of the
assignments for this program.
• 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.
• I acknowledge that the attachment of this document signed or not, constitutes a binding
agreement between myself and Pearson, UK.
• I understand that my assignment will not be considered as submitted if this document is not
attached to the assignment.

jafa008248@esoft.academy 17/01/2022
Student’s Signature: Date:
(Provide E-mail ID) (Provide Submission Date)
Higher National Diploma in Business
Assignment Brief
Student Name /ID Number
Unit Number and Title Unit 19 : Data Structures and Algorithms
Academic Year 2021/22
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
ABC Pvt Ltd organizing Car Racing event across western province and they decided to have
maximum of 6 cars(participants) to compete.
There are totally 3 Rounds and at the end of each round lowest rank car will be eliminated
from the Race.
Each car has unique number, brand, sponsor and driver details.

In order to manage this particular event ABC Pvt Ltd decided to develop an Application.
Application functions are listed down.

1.Register Car Details


2.Delete a car
3.Insert 3 Rounds Results.
4.Find out the winners (1st,2nd,3rd)
5.Search for a particular car

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.
Determine the operations of a queue and critically review how it is used to implement
function calls related to the above scenario.
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 : Registered Car details are stored from oldest to newest. Management of ABC Pvt Ltd
should be able to find from the newest to oldest registered car details. Using an imperative
definition, specify the abstract data type for the above scenario and implement specified
ADT using java programming and briefly discuss the complexity of chosen ADT algorithm. List
down the advantages of Encapsulation and Information hiding when using an ADT selected
for the above scenario.
“Imperative ADTs are basis for object orientation.” Discuss the above view stating whether
you agree or not. Justify your answer.

Task 4: ABC Pvt Ltd plans to visit all of these participants 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. Sort the cars based on numbers with two
different sorting algorithms and critically review the performances of those two algorithms
by comparing them.

Task 5: Evaluate how Asymptotic analysis can be used to assess the effectiveness of an
algorithm and critically evaluate the different ways in which the efficiency of an algorithm
can be measured.
Critically review the sort of trade-offs exists when you use an ADT for implementing
programs. You also need to evaluate 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 .

M3 Examine the advantages of

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.
HND in Computing and Systems
Development

Table of contents
Acknowledgment ..................................................................................................................... 22
Data Structures .................................................................................................................... 23
Basic function for the Data structure .................................................................................. 23
Type of Data Structures ...................................................................................................... 23
Arrays ............................................................................................................................. 24
Linked List ..................................................................................................................... 24
Stack ............................................................................................................................... 24
Queues ............................................................................................................................ 24
Benefits of Data structures .................................................................................................. 25
Disadvantages of Data structures ........................................................................................ 25
Background Study of ABC (PVT) ...................................................................................... 26
Suitable data structures for ABC (PVT) Company ............................................................. 26
Some important points related to the stack ......................................................................... 27
Stack operation Relate the scenario .................................................................................... 27
Push ()............................................................................................................................. 28
Pop () .............................................................................................................................. 29
isEmpty() ........................................................................................................................ 29
isFull() ............................................................................................................................ 30
Peek ()............................................................................................................................. 30
display( ) ......................................................................................................................... 31
Queue data structure ............................................................................................................ 31
Overview of queue data structure ....................................................................................... 31
Other applications in actual order ....................................................................................... 32
Provide detail explanation about queue operations & relate those operations to the function
calls. .................................................................................................................................... 32
Enqueue .......................................................................................................................... 32
Deque.............................................................................................................................. 33

Singarasa Joyalraj Data structure and algorithms Page 17 of 81


HND in Computing and Systems
Development

Code samples for Implementation using java ..................................................................... 33


Induction of Java programming language ........................................................................... 40
Error handling ..................................................................................................................... 40
Error handling method in using java ................................................................................... 40
Errors handling techniques in java ................................................................................. 41
Error handling of the system for the ABC (PVT) LMD ................................................ 42
Test plan .............................................................................................................................. 43
Test case .............................................................................................................................. 45
Object-Oriented Programming ............................................................................................ 56
Time complicity for Apply to Abstract for the development ......................................... 59
Encapsulation ................................................................................................................. 59
Advantages of Encapsulation ......................................................................................... 59
Justify the Abstract data type basis for object orientation .................................................. 62
Introduction of shortest path algorithms ............................................................................. 63
Dijkstra algorithm........................................................................................................... 63
Kruskal's algorithm......................................................................................................... 66
Apply Kruskal's algorithm.............................................................................................. 66
sorting algorithms................................................................................................................ 68
Type of sorting algorithms .................................................................................................. 68
Bucket sorting................................................................................................................. 68
Merge sorting ................................................................................................................. 68
Insertion sorting .............................................................................................................. 68
Selection sorting algorithm ............................................................................................ 68
Selection sorting algorithm using car ID ........................................................................ 69
Bubble sorting algorithm ................................................................................................ 70
Explain the bubble sorting algorithm for Car ID............................................................ 71
Review the performance of both sorting algorithms. ..................................................... 72
Asymptotic analysis ............................................................................................................ 73

Singarasa Joyalraj Data structure and algorithms Page 18 of 81


HND in Computing and Systems
Development

Asymptotic Notation ........................................................................................................... 73


Type of Asymptotic Notation.............................................................................................. 73
Notations for Asymptotic Values ................................................................................... 73
Big O Notation ............................................................................................................... 73
Omega Notation.............................................................................................................. 74
Theta Notation ................................................................................................................ 75
Two types Complexity ................................................................................................... 76
Trade-off of types ................................................................................................................ 77
Reference............................................................................................................................. 79

Table of Figure
Figure 1 types of Linear Data Structures ................................................................................. 23
Figure 2 Stack operation .......................................................................................................... 27
Figure 3 Enqueue ..................................................................................................................... 32
Figure 4 Deque ......................................................................................................................... 33
Figure 5 logo of java ................................................................................................................ 40
Figure 6 Java Exceptions Types .............................................................................................. 40
Figure 7 Errors handling techniques in java ............................................................................ 42
Figure 8 Sample Error handling .............................................................................................. 42
Figure 9 Apply to Abstract for the development ..................................................................... 56
Figure 10 Apply to Abstract for the development ................................................................... 57
Figure 11 Apply to Abstract for the development ................................................................... 58
Figure 12 Encapsulation .......................................................................................................... 59
Figure 13 Using Encapsulation for the implementation .......................................................... 60
Figure 14 Dijkstra algorithm.................................................................................................... 63
Figure 15 Selection sorting algorithm using car ID ................................................................. 70
Figure 16 Result for Selection Sorting..................................................................................... 70
Figure 17 Big O Notation ........................................................................................................ 73
Figure 18 Omega Notation....................................................................................................... 74
Figure 19 Theta Notation ......................................................................................................... 75

Singarasa Joyalraj Data structure and algorithms Page 19 of 81


HND in Computing and Systems
Development

Table of table
Table 1 Test plan...................................................................................................................... 43
Table 2 Test case No 01 .......................................................................................................... 45
Table 3 Test case No 02 ........................................................................................................... 46
Table 4 Test case No 03 ........................................................................................................... 47
Table 5 Test case No 04 ........................................................................................................... 47
Table 6 Test case No 05 ........................................................................................................... 48
Table 7 Test case No 06 ........................................................................................................... 48
Table 8 Test case No 07 ........................................................................................................... 49
Table 9 Test case No 08 ........................................................................................................... 50
Table 10 Test case No 09 ......................................................................................................... 51
Table 11 Test case No 10 ......................................................................................................... 51
Table 12 Test case No 11 ......................................................................................................... 52
Table 13 Test case No 12 ......................................................................................................... 53
Table 14 Test case No 13 ......................................................................................................... 54
Table 15 Dijkstra algorithm .................................................................................................... 65

Singarasa Joyalraj Data structure and algorithms Page 20 of 81


HND in Computing and Systems
Development

Singarasa Joyalraj Data structure and algorithms Page 21 of 81


HND in Computing and Systems
Development

Acknowledgment

First ours elf-thanked our kind full hone stable HND lecturer K.Ushamini and coordinator
Mr. Stephen preamnath, ESOFT Metro campus Manager Mr.B.Gajanan. You have given me
the motivation and help and support to complete this Assignment in a good way and we have
gained knowledge related to the subject Data structures & Algorithms and for your blessing
we have done this in a good way. Finally thank you for the your help and support

Thank you.
Singarasa Joyalraj JAF/A-008248
HND in Computing and Systems Development 30A
ESOFT Metro Campus Jaffna

Singarasa Joyalraj Data structure and algorithms Page 22 of 81


HND in Computing and Systems
Development

Data Structures
Data Structures are the programmatic way of storing data so that data can be used efficiently.
Almost every enterprise application uses various types of data structures in one or the other
way. This tutorial will give you a great understanding on Data Structures needed to
understand the complexity of enterprise level applications and need of algorithms, and data
structures.(Tutorial point)

Basic function for the Data structure


From a data structure point of view, below are some important categories of algorithms
Search - an algorithm for searching for an element in a data structure.
Sort - Sorting is an algorithm for sorting items in a specific order.
Insert - Algorithm for inserting an element into a data structure.
Update - Update is an algorithm for updating an existing item in the data structure.
Delete - an algorithm for removing an existing element from the data structure.

Type of Data Structures


The types of Linear Data Structures are given below

Figure 1 types of Linear Data Structures

Singarasa Joyalraj Data structure and algorithms Page 23 of 81


HND in Computing and Systems
Development

Arrays
An array is a collection of data items of similar type, and each data item is called an item of
the array. The data type of the element can be any valid data type such as char, int, float or
double.
Index items have the same variable name, but each has a different index number, known as an
index. The array can be one-dimensional, two-dimensional, or multidimensional.

Linked List
A linked list is a linear data structure that is used to hold the list in memory. This can be
thought of as the sum of nodes stored in non-contiguous memory locations. Each node in the
list contains a pointer to an adjacent node.

Stack
A stack is a linear list called a sphere, and insertion and deletion are only allowed at one end.
A stack is an abstract data type (ADT) that can be implemented in most programming
languages. It is called a stack because it behaves like a real stack.

Queues
Queues are linear, and items can only be added at one end and deleted at the other. This is an
abstract data structure similar to a stack. Since the queue is open at both ends, it follows the
first in, first out (FIFO) method for storing data elements.

Non-linear data structure


This data structure does not form an array. That is, each element or element is related to two
or more elements in a non-linear order. A data element is not arranged in a sequential
structure.

Singarasa Joyalraj Data structure and algorithms Page 24 of 81


HND in Computing and Systems
Development

The types of nonlinear data structures are described below.


Tree
A tree is a multi-level data structure that has a hierarchical relationship between the elements
called nodes. The lowest node in the inheritance is called the terminal node and the highest
node is called the root node. Each node contains a pointer to an adjacent node. The tree data
structure depends on the parent-child relationship between nodes. Each node in the tree can
have many child elements other than the leaf node, but each node can have up to one parent
other than the root node and Trees can be divided into many categories.

Graph
A graph can be defined as an image representation of a group of related elements
(represented by verticals) called edges. Graphs, unlike trees, can have loops, but trees can't.

Benefits of Data structures


1. Data structures enable the secure storage of information on a computer system. Most
data structures require only a small fraction of the storage capacity of a computer.
Saving data is convenient and enables access at any time. It's also impossible to lose
the information as we could if it were on paper.

2. Data structures enable us to use and process data on a software system. For example,
if we want to keep a log of our working hours and generate a report, we can do so on
a computer through an automated process. This process would make extensive use of
data structures.

3. Data structures make all processes in which they are involved very fast.

Disadvantages of Data structures


1. In order to change data structures, we have to be very advanced IT technicians with a
large experience base. It is almost impossible to change most of the data structures.

Singarasa Joyalraj Data structure and algorithms Page 25 of 81


HND in Computing and Systems
Development

2. When we have a problem with data structures it is very unlikely that we can solve it
without the expertise of a professional.

Background Study of ABC (PVT)


ABC Pvt. There are a total of 3 rounds of this racing event, with the lowest-ranked car being
eliminated from the race at the end of each round. Each car has a unique number, brand,
sponsor and driver details. To manage this particular event, ABC Pvt. Ltd. has created a
resume called ABC Pvt.

1. Record car details


2. Remove a car
3.3 Insert Round Results.
4. Find Winners (1st, 2nd, and 3rd)
5. Look for a specific car

Suitable data structures for ABC (PVT) Company


The suitable data structure for ABC (PVT) is stack. Because, a stack is a linear data structure
that follows the LIFO principle (Last-In-First-Out). The stack has one end, while the queue
has two ends (front and back). It contains only one pointer called top, which points the top
element of the stack. Whenever an item is added to the stack, it is added to the top of the
stack and the item can only be deleted from the stack. In other words, a stack can be defined
as a container into which insertion and deletion can take place from one end, the top of the
stack.
In this scenario, Learner choose to use stack data type for ABC Private limited because the
stack works with the LIFO pattern. That means a stack is a linear list called a sphere, and
insertion and deletion are only allowed at one end. A stack is an abstract data type (ADT) that
can be implemented in most programming languages. Here, 6 car details should be stored
within the stack as well as ABC Private limited need to store the race event’s 3 rounds
results, with the lowest-ranked car being eliminated from the race at the end of each round.
There are two ways to implement the stack such as array based implementation and linked
list based implementation. Here, each car has a unique number, brand, sponsor and driver
details. Hence, linked list implementation is most appropriate to store the multiple type data

Singarasa Joyalraj Data structure and algorithms Page 26 of 81


HND in Computing and Systems
Development

of a car in single node. Because of this reason, dynamic implementation was selected for the
development.

Some important points related to the stack


1. It's called a stack because it works like a real stack, a stack of books, and so on.
2. A stack is an abstract data type with a predefined capacity. That is, you can store
elements of finite size.
3. This is a data structure that follows a specific order for inserting and removing
elements, the order of which can be LIFO or FIRO.

Stack operation Relate the scenario


The stack works with the LIFO pattern. As you can see in the following figure, the stack has
five blocks of memory. Therefore, the size of the stack is 5.Suppose you want to store an
element on the stack and the stack is empty. I got a stack of size 5 as shown below. Here we
are pushing elements one by one until the stack is full.

Figure 2 Stack operation

Singarasa Joyalraj Data structure and algorithms Page 27 of 81


HND in Computing and Systems
Development

Since the size of the stack is 5, the stack is full, so in the above case, you can see that the
stack moves from top to bottom when you enter a new element in the stack. The stack fills
from bottom to top.

When performing a delete operation on the stack, there is only one way to enter and exit
because the other end is closed. This follows the LIFO pattern. That is, the first value you
enter is deleted last. In the above case, the value 5 is entered first, so it will only be removed
after all other elements have been removed.

Push ()

Begin
Step 1: Start

Step 2: Create a node new and declare variable top

Step 3: Set new data part to be Null


// The first node is created, having null value and top pointing to it

Step 4: Read the node to be inserted.

Step 5: Check if the node is Null, then print "Insufficient Memory"

Step 6: If node is not Null, assign the item to data part of new and assign top to link part of new
and also point stack head to new.
End

Singarasa Joyalraj Data structure and algorithms Page 28 of 81


HND in Computing and Systems
Development

When we insert an element into a layer, the function is called push. If the stack is full, a level
overflow occurs. So this push function will use to insert the car details of the ABC (PVT) car.
But in this case, we will use the link list based on Operation Stock Bush development,
because each section must have a car number, brand name, sponsor name and driver name.

Pop ()

Begin
Step 1: Start

Step 2: Check if the top is Null, then print "Stack


Underflow."

Step 3: If top is not Null, assign the top's link part to


ptr and assign ptr to stack_head's link part.

Step 4: Stop
End

When we remove an item from the stack, the operation is known as pop. If the stack is empty,
which means there are no items on the stack, this state is called the downstream state. This
kind of operation will help to remove car details but no more argument for pop function.
Because the stack operation will only remove the highest details, which means it will only
remove the last details of the Push (insert) car.

isEmpty()

Begin
Step 1: Boolean is empty()
Step 2: if head == null than
Step 3: return true
Step 4: Else
Step 5: return false
End

Singarasa Joyalraj Data structure and algorithms Page 29 of 81


HND in Computing and Systems
Development

Determines whether the stack is empty or not. This type of function helps to determine if the
stack is empty or full. In some cases, we need to remove the detail, but if the stack is empty,
we can remove the car details because there are no car details in stack, so the car details
cannot be removed, so we can check whether the stack is empty or not for reasons like this. In
situations like this we will use the empty function.

isFull()
This kind of Is full function will help verify the stack is full or not. purpose of is full function
will help to if we enter greater than 6 more number of car details this kind of statement will
totally wrong because above the scenario only 6 cars only participate in the car rounds so
kind purpose we will use this kind of function for the stack.

Peek ()

Begin
Step 1: int Peek ()
Step 2: if stack is empty then:
Step 3: print as “Stack empty no last car”
Step 4: Else:
Step 5: return top car id
End

The peek function will help to identify the topmost (last ender car detail). This kind of
function will help to identify the last car in the event. At same time analyzing the three round
details for Car event it essay remove the last car Number.

Singarasa Joyalraj Data structure and algorithms Page 30 of 81


HND in Computing and Systems
Development

display( )

Begin
Step 2: assign head in to stack node temp
Step 2: while temp!= null then
Step 2: print the temp > Car number
Step 2: temp equal temp > next

Display function will help to list out the inserted the car details by following stack principle
Last in last out format (LIFO).

Queue data structure


The queue data structure used in programming applications is an array. This is an abstract
data type or linear data structure that stores the elements in the sequence. Use the FIFO
approach to access the element (first, finish first). Arrays are typically used to manage threads
in multiple threads and prioritize orders.

Overview of queue data structure

Arrays are an important data structure in programming. Rows are opened at both ends
according to the FIFO (First In, First Out) method. Data is inserted at one end or end of the
row and deleted at the other end, called the front end or head of the row. A real example of a
Q data structure in a row of people waiting to buy a ticket in a theatre. A new person joins the
queue from the end, and the person standing in front gets the ticket first and leaves the queue.
Similarly, in sequence data structures, the first data sequence added is omitted first.

Singarasa Joyalraj Data structure and algorithms Page 31 of 81


HND in Computing and Systems
Development

Other applications in actual order


Escalator person
Store cash register tax
Car wash

Provide detail explanation about queue operations & relate those operations to the
function calls.
To create the required system, a stack has been chosen in the data structure based on the
scenario. Because the push function is used to insert car details, the pop function is used to
delete them, the display function is used to view inserted car details, the search function is
used to find car details that have been stored in the stack, and the peek function is used to
show the most recently added car. In-order to call these functions, use queue data structure.
Because, this is an abstract data type or linear data structure that stores the elements in the
sequence. Use the FIFO approach to access the element (first In Out).

Enqueue

Figure 3 Enqueue

Enqueue is a method for adding an item to a queue. As previously stated, any new element is
added to the queue's tail, so Enqueue adds an element to the queue's tail.

Singarasa Joyalraj Data structure and algorithms Page 32 of 81


HND in Computing and Systems
Development

Deque

Figure 4 Deque

Because the
stack is a linear data structure that adheres to the LIFO (Last-In-First-Out) principle, we must
use it in the preceding scenario. The queue has two ends, whereas the stack only has one
(front and back). It only has one pointer called the top, which points to the stack's top
element. When an element is added to the stack, it is added to the top of the stack, and the
element is the only thing that can be removed from the stack. In other words, a stack is a
container that allows insertion and deletion from one end, at the top of the stack.

Code samples for Implementation using java


Insert car link list bead stack Implementation

Singarasa Joyalraj Data structure and algorithms Page 33 of 81


HND in Computing and Systems
Development

Interface

Output

Singarasa Joyalraj Data structure and algorithms Page 34 of 81


HND in Computing and Systems
Development

Singarasa Joyalraj Data structure and algorithms Page 35 of 81


HND in Computing and Systems
Development

Singarasa Joyalraj Data structure and algorithms Page 36 of 81


HND in Computing and Systems
Development

Remove last car list bead stack Implementation

Singarasa Joyalraj Data structure and algorithms Page 37 of 81


HND in Computing and Systems
Development

Display the car details list bead stack Implementation

Singarasa Joyalraj Data structure and algorithms Page 38 of 81


HND in Computing and Systems
Development

Show the last car list bead stack Implementation

Output

Singarasa Joyalraj Data structure and algorithms Page 39 of 81


HND in Computing and Systems
Development

Induction of Java programming language

Sun Micro systems initially introduced the Java programming


language in 1995, and it is a high-level and object-oriented
programming language. Java operates on a variety of platforms,
including Windows, Mac OS, and Linux. This lesson will provide
you with a thorough understanding of Java. This tutorial explains
how to learn the Java programming language in a straightforward
Figure 5 logo of
and practical manner.
java

Error handling
Error handling refers to the actions taken by a program in response to unusual inputs or
situations. The clarity of error messages and the alternatives offered to users for correcting
the problem determine the quality of such activities. Exception Handling, on the other hand,
is concerned with reactions to abnormal situations incorporated into a programming language
or machine. See also managing exceptions and channel coding. ( pcmag)

Error handling method in using java


Java Exceptions Types

Checked and unchecked exceptions are the two most


common forms. Unchecked exceptions are referred to
as errors. However, Oracle distinguishes between three
sorts of exceptions: Checked Exception, Unchecked
Exception, Error, and Testing.

Figure 6 Java Exceptions Types

Singarasa Joyalraj Data structure and algorithms Page 40 of 81


HND in Computing and Systems
Development

The difference between verified and unverified exceptions


Checked Exception
Checked Exception are classes that directly receive a Run time Exception and Error
Avoidable class. For example, verified exceptions such as IO Exception, SQL Exception, etc.
will be verified during compilation.

Unchecked exception
Unchecked exceptions are known as classes that receive a Runtime Exception. For example,
Arithmetic Exception, Null Pointer Exception, Array Index Out Of Bounds Exception, and
more. Unverified exceptions will not be verified during compilation, but will be verified at
runtime.

Error
Error in a program is irreversible. Some examples of bugs are Out Of Memory Error, Virtual
Machine Error, and Assertion Error.

Errors handling techniques in java


Keyword Description

Try The 'try' keyword is used to specify the block to which the exception code
should be set. This means you can't just use the try block. The catch or final
block must come after the try block.

Catch The 'catch' block is used to handle the exception. You cannot use the catch
block alone, as you must precede it with a try group. Then you can proceed with
the last block.

Finally The 'finally' block is used to execute program code. It runs regardless of
exception handling.

Throw Use the keyword 'throw' to throw an exception..

Singarasa Joyalraj Data structure and algorithms Page 41 of 81


HND in Computing and Systems
Development

Throws Exceptions are declared using the keyword "throws". Determines whether an
exception can occur during the execution of the method. There are no
exceptions. This is always used with the method signature.

Figure 7 Errors handling techniques in java

Error handling of the system for the ABC (PVT) LMD


Input

Figure 8 Sample Error handling

Output

we have to apply using error handling are using Try catch blog. This try block means The 'try'
keyword is used to specify the block to which the exception code should be set. This means
you can't just use the try block. The catch or final block must come after the try block. And
catch block mean The 'catch' block is used to handle the exception. You cannot use the catch
block alone, as you must precede it with a try group. Then you can proceed with the last
block. The try catch block will using the insert Car detail for handling Error.

Singarasa Joyalraj Data structure and algorithms Page 42 of 81


HND in Computing and Systems
Development

Test plan
The test plan is a written document that describes the purpose, approach, resources, and
timeline for the planned test activities. It specifies the test materials, the features to be tested,
and the test tasks, who will perform each task, the amount of tester freedom, the test
environment, the test design techniques, and the entry and exit criteria to be used, among
other things. And the reasoning behind their decision, as well as the risks entailed by
contingency planning. This document serves as a record of the test planning process.
Table 1 Test plan

Test No Test Name Test condition Test data Expecting result


1 Test JVM Open Command Run “java – Successfully show the
proper to work prompt than run Version “ java version in command
“java” command In command prompt
prompt
2 Test JVM Open Command Run “javac <file Successfully compile the
compile the prompt than run name>.java” in java
program “javac <file command prompt Program in command
name>.java ” prompt
command
3 Test JVM Run Open Command Run “java <file Successfully run the java
the program prompt than run name>” in Class in command
“java <file command prompt prompt
name> ”
command
4 Show the Open Command Run “java stackl” Successfully show the
ABC(PVT) prompt than run then show ABC(PVT) main menu
main menu “java Stackl” ABC(PVT) main
command menu
5 Right way to Choosing the exit Run “java stackl” Successfully clear un
clear function function in than choosing wand text in ABC(PVT)
work ABC(PVT) main Exit function in main menu
menu ABC(PVT) main

Singarasa Joyalraj Data structure and algorithms Page 43 of 81


HND in Computing and Systems
Development

menu
6 Right way to Open Command Run “java stackl” Successfully show
choosing Stackl prompt than run than choosing choosing insert function
Command “java Stackl” insert function in in ABC(PVT)
command ABC(PVT) management menu
management
menu
7 Right way work Select car insert Enter sample car Successfully insert car
to insert the car function details with data detail in stack
detail
8 Right way work Select car remove Last Store the Successfully Remove last
to Remove the function Stack car details car detail in stack
car detail
9 Right way work Select show the Last Store the Successfully Select show
to Show the last last car Stack car details the last car
car detail
10 Right way to Select the Store the Stack Successfully Display all
show list out car Display all car car details car No
numbers in
stack order
11 Right way to Select the Car 1st round car Successfully print 1st
print 1st Round detail detail selected car and
selected Car and management then eliminate last car in 1st
eliminate last ender 1st round round
car in 1st round detail
order
12 Right way to Select the Car 2st round car Successfully print 2st
print 2st Round detail detail selected car and
selected car and management then eliminate last car in 2st
eliminate last ender 2st round round
car in 2st round detail
order

Singarasa Joyalraj Data structure and algorithms Page 44 of 81


HND in Computing and Systems
Development

13 Right way to Select the Car 3st round car Successfully print 3st
print 3st Round detail detail selected car and
selected car and management then eliminate last car in 3st
eliminate last ender 3st round round
st
car in 1 round detail
order

Test case
The test case is defined as the set of conditions by which the tester determines whether a
software application is operating according to the client's requirements or not. This test case
design includes the preconditions, the name of the case, the input conditions and the expected
result. The test case is derived from the first step action and test footage.

Table 2 Test case No 01

Test case No 01
Test name Test JVM proper to work
Test Method Run the “java –version” in command prompt
Test data Run “java –Version “
In command prompt
Expected Successfully show the java version in command prompt
outcome
Actual Successfully show the java version in command prompt
outcome
Test status Pass

Singarasa Joyalraj Data structure and algorithms Page 45 of 81


HND in Computing and Systems
Development

Evidence for
test

Table 3 Test case No 02

Test case No 02
Test name Test JVM compile the program
Test Method run “javac <file name>.java ” command in Command prompt
Test data Run “javac Stackl.java “
In command prompt
Expected outcome Successfully compile the java
Program in command prompt
Actual outcome Successfully compile the java
Program in command prompt
Test status Pass
Evidence for test

Singarasa Joyalraj Data structure and algorithms Page 46 of 81


HND in Computing and Systems
Development

Table 4 Test case No 03

Test case 03
No
Test name Test JVM Run the program
Test run “java <file name>” command in Command prompt
Method
Test data Run “java Stackl “
In command prompt
Expected Successfully run the java
outcome Class in command prompt
Actual Successfully run the java
outcome Class in command prompt
Test status Pass
Evidence
for test

Table 5 Test case No 04

Test case 04
No
Test name Show the ABC(PVT) main menu
Test run “java <file name>” command in Command prompt
Method
Test data Run “java stackl” than show ABC(PVT) main menu
Expected Successfully show the
outcome ABC(PVT) main menu
Actual Successfully show the
outcome ABC(PVT) main menu
Test status Pass

Singarasa Joyalraj Data structure and algorithms Page 47 of 81


HND in Computing and Systems
Development

Evidence
for test

Table 6 Test case No 05

Test case 05
No
Test name Right way to clear function work
Test Choosing the exit function in ABC(PVT) main menu
Method
Test data Run “java stackl” than show ABC(PVT) main menu
Expected Successfully clear un wand text in ABC(PVT) main menu
outcome
Actual Successfully clear un wand text in ABC(PVT) main menu
outcome
Test status Pass
Evidence
for test

Table 7 Test case No 06

Test case 06
No
Test name Right way to choosing Stackl Command
Test Run “java stackl” than choosing Random function in ABC(PVT) car

Singarasa Joyalraj Data structure and algorithms Page 48 of 81


HND in Computing and Systems
Development

Method management menu


Test data Select the insert new car in the car management menu
Expected Successfully show choosing insert function in ABC(PVT) management menu
outcome
Actual Successfully show choosing insert function in ABC(PVT) management menu
outcome
Test status Pass
Evidence
for test

Table 8 Test case No 07

Test case 07
No
Test name Right way work to insert the car detail
Test Select car insert function
Method
Test data Enter sample car details with data
Expected Successfully insert car detail in stack
outcome
Actual Successfully insert car detail in stack
outcome
Test status Pass

Singarasa Joyalraj Data structure and algorithms Page 49 of 81


HND in Computing and Systems
Development

Evidence
for test

Table 9 Test case No 08

Test case 08
No
Test name Right way work to Remove the car detail
Test Select car Remove function
Method
Test data Last Store in Stack car details
Expected Successfully Remove last car detail in stack
outcome
Actual Successfully Remove last car detail in stack
outcome
Test status Pass
Evidence
for test

Singarasa Joyalraj Data structure and algorithms Page 50 of 81


HND in Computing and Systems
Development

Table 10 Test case No 09

Test case 09
No
Test name Right way work to Show the last car detail
Test Select show the last car
Method
Test data Last Store in Stack car details
Expected Successfully Select show the last car
outcome
Actual Successfully Select show the last car
outcome
Test status Pass
Evidence
for test

Table 11 Test case No 10

Test case 10
No
Test name Right way to show list out car numbers in stack order
Test Select the Display all car
Method
Test data

Singarasa Joyalraj Data structure and algorithms Page 51 of 81


HND in Computing and Systems
Development

Expected Successfully Display all car No


outcome
Actual Successfully Display all car No
outcome
Test status Pass
Evidence
for test

Table 12 Test case No 11

Test case 11
No
Test name Right way to print 1st selected car and eliminate last car in 1st round order
Test Select the Car Round detail management then ender 1st round detail
Method
Test data 1st round car detail
Expected Successfully print 1st selected car and eliminate last car in 1st round
outcome
Actual Successfully print 1st selected car and eliminate last car in 1st round
outcome
Test status Pass

Singarasa Joyalraj Data structure and algorithms Page 52 of 81


HND in Computing and Systems
Development

Evidence
for test

Table 13 Test case No 12

Test case 12
No
Test name Right way to print 2st selected car and eliminate last car in 2st round order
Test Select the Car Round detail management then ender 2st round detail
Method
Test data 2st round car detail
Expected Successfully print 2st selected car and eliminate last car in 2st round
outcome
Actual Successfully print 2st selected car and eliminate last car in 2st round
outcome
Test status Pass

Singarasa Joyalraj Data structure and algorithms Page 53 of 81


HND in Computing and Systems
Development

Evidence
for test

Table 14 Test case No 13

Test case 13
No
Test name Right way to print 3st selected car and eliminate last car in 3st round order
Test Select the Car Round detail management then ender 1st round detail
Method
Test data 3st round car detail
Expected Successfully print 1st selected car and eliminate last car in 3st round
outcome
Actual Successfully print 3st selected car and eliminate last car in 3st round
outcome
Test status Pass

Singarasa Joyalraj Data structure and algorithms Page 54 of 81


HND in Computing and Systems
Development

Evidence
for test

Singarasa Joyalraj Data structure and algorithms Page 55 of 81


HND in Computing and Systems
Development

Object-Oriented Programming
Object-oriented programming is a programming paradigm based on the concept of objects,
which contain both data and code to modify the data. Object-oriented programming mimics
many of the real-world attributes of objects. Java, C++, and Ruby are three of the most
popular object-oriented programming languages. Many languages that are not strictly object-
oriented, such as Python and JavaScript, provide features such as classes and objects that are
inspired by object-oriented programming. Simula and Smalltalk were the first widely
accepted object-oriented languages.

Apply to Abstract for the development

Figure 9 Apply to Abstract for the development

Singarasa Joyalraj Data structure and algorithms Page 56 of 81


HND in Computing and Systems
Development

Figure 10 Apply to Abstract for the development

Singarasa Joyalraj Data structure and algorithms Page 57 of 81


HND in Computing and Systems
Development

Figure 11 Apply to Abstract for the development

The Registered Car details are stored in this scenario from oldest to newest. ABC Pvt Ltd's
management should be able to locate information on registered vehicles ranging from the
most recent to the oldest. As a result, in this case, we will implement the Stack data type.

Because a stack is a linear data structure that adheres to the first-in, first-out (LIFO) principle
(Last-In-First-Out). The stack only has one end, whereas the queue has two (front and back).
It only has one pointer called the top, which points to the stack's top element. When an item
is added to the stack, it is placed at the top, and the item can only be deleted from the stack.
In other words, a stack is a container into which insertion and deletion can occur from one
end, the stack's top.

Singarasa Joyalraj Data structure and algorithms Page 58 of 81


HND in Computing and Systems
Development

and Learner selects the stack data type for ABC Private Limited because it follows the LIFO
pattern. That is, a stack is a sphere-shaped linear list in which insertion and deletion are only
permitted at one end. A stack is an abstract data type (ADT) that can be used in almost any
Object-oriented programming language. most suitable Java programming language.In this
case, 6 car details, as well as ABC, should be saved within the stack. Private limited must
save the race event's three-round results, with the lowest-ranked car eliminated at the end of
each round. The stack can be implemented in two ways: array-based implementation and
linked list-based implementation. Each car has its own number, brand, sponsor, and driver
information. As a result, linked list implementation is best suited to storing multiple types of
data for a car in a single node. As a result, dynamic implementation was chosen for the
development.

Time complicity for Apply to Abstract for the development

Encapsulation

Encapsulation in Java is a mechanism for grouping


variables (data) and methods (code) together as a
single unit. It is the process of hiding the details of
information and protecting the data and behavior of
the object. It is one of the four important OOP
concepts. The encapsulation class is easy to test, so
it's also better for unit testing.(James Hartman
Figure 12 Encapsulation
December 18, 2021)

Advantages of Encapsulation
1. The attached code is very flexible and easy to change with new requirements.

Singarasa Joyalraj Data structure and algorithms Page 59 of 81


HND in Computing and Systems
Development

2. Other categories are not allowed to enter the private sector.


3. Encapsulation allows you to modify the executable code without breaking the other code
that activated the code.
4. It protects data and code from external inheritance. Thus, encapsulation helps to achieve
security.
5. Improves application maintenance.
6. If you do not specify the setting method in the class, you can only read the fields.
7. If you don't specify a getter method in the class, you can just write the fields.

Using Encapsulation for the implementation

Figure 13 Using Encapsulation for the implementation

Singarasa Joyalraj Data structure and algorithms Page 60 of 81


HND in Computing and Systems
Development

Singarasa Joyalraj Data structure and algorithms Page 61 of 81


HND in Computing and Systems
Development

Justify the Abstract data type basis for object orientation


An abstract data type is an abstraction of a data structure that only provides the interface that
the data structure must correspond to. The interface does not provide specific details about
what to implement or in what programming language. In other words, we can say that
abstract data types are entities that are definitions of data and operations but have no
implementation details. In this case, we know what data we are storing and what operations
can be performed on the data, but we do not know the implementation details. For example,
the reason for the lack of implementation details is that each programming language has a
different implementation strategy; The object-oriented C ++ role data structure is
implemented by structures, while the Java data structure is implemented by objects and
classes.

In the scenario Queue is an abstract data type implemented using a dynamic array and a
linked list, an array-based queue and a stack-based queue. The map is implemented using a
tree diagram, hash map, or hash table. Therefore, all object-oriented programming depends
on the abstract data type.

Singarasa Joyalraj Data structure and algorithms Page 62 of 81


HND in Computing and Systems
Development

Introduction of shortest path algorithms


The shortest path algorithm calculates the shortest path from the start node to each node in
the connected graph. Developed in 1956 by Edsger W. Dijsktra, it is the basis for all
applications that show you the shortest route from one place to another. In 15 minutes of
video, we tell you about the history of the algorithm and a little bit about Edsger himself,
mention the problem, and then develop the algorithm.(David Gries)

Dijkstra algorithm
Figure 14 Dijkstra algorithm

Dijkstra’s algorithm is a single source shortest path algorithm. Here, single source means that
only one source is given, and we have to find the shortest path from source to all nodes. First,
we have to consider any vertex as a source vertex. Suppose we consider vertex 0 as a source
vertex. Here we assume 0 as the source vertex, and the distance to all other vertices is
infinity. At first, we don't know the distances. First, we will find out which vertices are
directly connected to vertex 0. We also notice in the above graph that two vertices are
directly connected to vertex 0.

Graph diagram for the above algorithms


Learner is going to execute using the Dijkstra algorithm. However, the ABC (PVT) car will
go to 6 different locations above the race, so learner will apply the Dijkstra shortest path
algorithm for identifies the shortest path as flow.

Singarasa Joyalraj Data structure and algorithms Page 63 of 81


HND in Computing and Systems
Development

The algorithm will create a shortcut for ABC (PVT) from different Car Location 1001 to all
other car locations on the map. For this map, the weight of the edges represents the distance
between two car locations. They will have a shortcut from car location 1001 to car location
1002, and from car location 1001 to car location 1003 and each car location on the map.

Step 1

1001 to 1006 is the minimum distance. Hence travel to 1006 location will 2nd visited car is
1006

Singarasa Joyalraj Data structure and algorithms Page 64 of 81


HND in Computing and Systems
Development

Step 2

3rd visited car is 1005

Step 3

Table 15 Dijkstra algorithm

1001 1002 1003 1004 1005 1006


1001 0 X X X X X
1006 0 6 X X 4 2
1005 0 6 X X 4 2
1002 0 6 7 8 4 2

Singarasa Joyalraj Data structure and algorithms Page 65 of 81


HND in Computing and Systems
Development

1003 0 6 7 8 4 2
1004 0 6 7 8 4 2

Kruskal's algorithm
Kruskal's algorithm is a concept introduced in discrete mathematics graph theory. In a
connected weighted graph, it is used to find the shortest path between two points. This
algorithm converts a given graph into a forest, with each node treated as a separate tree.
These trees can only be linked if the edge connecting them has a low value and does not
produce a cycle in the MST structure. In this tutorial, we will learn all about the Kruskal
Algorithm.

Method of Steps for Solving


Step 1: Sort all edges by edge weight in ascending order.
Step 2: Select the tiniest edge.
Step 3: In a spanning tree, see if the new edge creates a cycle or loop.
Step 4: Include that edge in MST if it does not form the cycle. Otherwise, throw it away.
Step 5: Repeat step 2 until the MST includes a |V| - 1 edge.
Apply Kruskal's algorithm

Singarasa Joyalraj Data structure and algorithms Page 66 of 81


HND in Computing and Systems
Development

Step 1

Step 2

Step 3

Above the scenario apply the Apply Kruskal's algorithm on the final output of the minimum
Sort path is 16 km.

Singarasa Joyalraj Data structure and algorithms Page 67 of 81


HND in Computing and Systems
Development

sorting algorithms
Sorting is the process of arranging the elements of an array in ascending or descending order.
Than mean if we ender the data it will change the ascending or descending order
Type of sorting algorithms
Bucket sorting
Bucket sort is also referred to as bin sort. It works by distributing the element into the array,
which is also known as buckets. Buckets are sorted individually using different sorting
algorithms in this sorting algorithm.

Merge sorting
Merge sort implements the divide and conquers strategy, in which the list is first divided into
sets of equal elements, and then each half of the list is sorted using merge sort. The sorted list
is combined once more to form an elementary sorted array.

Insertion sorting
Insertion sort, as the name implies, inserts each element of the array into its proper place. It is
a simple sort method used to arrange the deck of cards when playing bridge.

Selection sorting algorithm


A selection sort algorithm is used to arrange a list of items in a specific order (ascending or
descending). In selection sort, the first item in the list is selected and it is compared
repeatedly with all remaining items in the list. If any element is smaller than the specified
element (for ascending order), both are swapped so that the first position is filled with the
smallest element in the sorted order. Next, we select the item in the second position in the list
and it is compared to all the remaining items in the list. If any element is smaller than the
specified element, both will be swapped. This procedure is repeated until the entire list has
been sorted.

Step by step process

The selection sort algorithm is implemented using the following steps

Step 1 - Select the first item from the list (i.e. the item in the first position in the list).

Singarasa Joyalraj Data structure and algorithms Page 68 of 81


HND in Computing and Systems
Development

Step 2: Compare the selected item with all the other items in the list.

Step 3: In each comparison, if any element smaller than the given element is found (in
ascending order), both will be swapped.

Step 4: Repeat the same procedure with the item in the next position in the list until the entire
list is sorted.

Selection sorting algorithm using car ID

Singarasa Joyalraj Data structure and algorithms Page 69 of 81


HND in Computing and Systems
Development

Figure 15 Selection sorting algorithm using car ID

Result for Selection Sorting

Figure 16 Result for Selection Sorting

Bubble sorting algorithm


In this article, we will discuss the bubble sort algorithm. The working procedure for bubble
sorting is simpler. This article will be very useful and interesting for students as they may
face some kind of bubble in the form of a question in their exams. So, it is important to
discuss the topic.

Bubble sort repeatedly shuffles adjacent items so they are not in the intended order. It is
called bubble sorting because the movement of the matrix elements is similar to the

Singarasa Joyalraj Data structure and algorithms Page 70 of 81


HND in Computing and Systems
Development

movement of air bubbles in water. Bubbles in the water rise to the surface; similarly, the
array elements in bubble sort move to the end of each iteration.

Although it is easy to use, it is mainly used as an educational tool because the bubble type
performs poorly in the real world. It is not suitable for large data sets. The average
complexity and worst case of bubble sort is O(n2), where n represents a number of elements.

Explain the bubble sorting algorithm for Car ID

Singarasa Joyalraj Data structure and algorithms Page 71 of 81


HND in Computing and Systems
Development

Result for bubble Shorting

Review the performance of both sorting algorithms.


in this scenario, Lerner will choose the Selection sorting algorithm and the Bubble sorting
algorithm. these two types of sedation will suitable for the scenario because the selection sort
algorithm is used to arrange a list of items in a specific order (ascending or descending). In
selection sort, the first item in the list is selected and it is compared repeatedly with all
remaining items in the list. If any element is smaller than the specified element (for ascending
order), both are swapped so that the first position is filled with the smallest element in the
sorted order. Next, we select the item in the second position in the list and it is compared to
all the remaining items in the list. If any element is smaller than the specified element, both
will be swapped. This procedure is repeated until the entire list has been sorted.
and bubble sort algorithm. The working procedure for bubble sorting is simpler. This article
will be very useful and interesting for students as they may face some kind of bubble in the
form of a question in their exams. So, it is important to discuss the topic.
Bubble sort repeatedly shuffles adjacent items so they are not in the intended order. It is
called bubble sorting because the movement of the matrix elements is similar to the
movement of air bubbles in the water. Bubbles in the water rise to the surface; similarly, the
array elements in bubble sort move to the end of each iteration. Although it is easy to use, it
is mainly used as an educational tool because the bubble type performs poorly in the real
world. It is not suitable for large data sets. The average complexity and worst case of bubble
sort are O(n2), where n represents a number of elements.

Singarasa Joyalraj Data structure and algorithms Page 72 of 81


HND in Computing and Systems
Development

Asymptotic analysis
Asymptotic Analysis is the big idea that deals with the issues mentioned above when
analyzing algorithms. In Asymptotic Analysis, we evaluate an algorithm's performance in
terms of input size (rather than actual running time). We calculate how the time (or space)
required by an algorithm increases with the size of the input. (Harry Davis, 28.10.2021)
Asymptotic Notation
Asymptotic Notations: Asymptotic Notation is a method of comparing functions that take
into account constant factors and small input sizes. To calculate an algorithm's running time
complexity, three notations are used. Big-oh notation: Big-oh is a formal way of expressing
the maximum running time of an algorithm. (Harry Davis, 28.10.2021)
Type of Asymptotic Notation
Notations for Asymptotic Values
Asymptotic notations are mathematical notations that are used to describe the running time
of an algorithm when the input tends toward a specific value or a limiting value. In bubble
sort, for example, when the input array is already sorted, the time taken by the algorithm is
linear, which is the best case. However, when the input array is in reverse order, the
algorithm takes the longest (quadratic) time to sort the elements, i.e. the worst case. It takes
average time when the input array is not sorted or in reverse order. Asymptotic notations are
used to represent these durations. There are three types of asymptotic notations
Big O Notation

Figure 17 Big O Notation

Singarasa Joyalraj Data structure and algorithms Page 73 of 81


HND in Computing and Systems
Development

The upper bound of an algorithm's running time is represented by Big-O notation. As a


result, it provides the worst-case complexity of an algorithm.

For sufficiently large n, the above expression can be described as a function f(n) belonging
to the set O(g(n)) if there exists a positive constant c such that it lies between 0 and
cg(n).The running time of an algorithm does not exceed the time provided by O(g(n) for any
value of n. It is widely used to analyze algorithms because it provides the worst-case
running time of an algorithm, and we are always interested in the worst-case scenario.

Omega Notation
.

Figure 18 Omega Notation

The lower bound of an algorithm's running time is represented by omega notation. As a


result, it provides an algorithm's best-case complexity

For sufficiently large n, the above expression can be described as a function f(n) belonging
to the set (g(n)) if there exists a positive constant c such that it lies above cg(n).Omega(g(n))
gives the minimum time required by the algorithm for any value of n.

Singarasa Joyalraj Data structure and algorithms Page 74 of 81


HND in Computing and Systems
Development

Theta Notation

Figure 19 Theta Notation

The function is encased in theta notation from above and below. It is used to analyze an
algorithm's average-case complexity because it represents the upper and lower bounds of its
running time. The relation: (g(n)) gives the value of a function g(n).

For sufficiently large n, the above expression can be described as a function f(n) belonging
to the set (g(n)) if there exist positive constants c1 and c2 such that it can be sandwiched
between c1g(n) and c2g(n).If a function f(n) is asymptotically tight bound if it lies anywhere
between c1g(n) and c2g(n) for all n n0.

Complexity
An algorithm's complexity computes the amount of time and space required by an algorithm
for a given input size (n). An algorithm's complexity can be classified into two types. There
are two types of complexity: time complexity and space complexity. That is, an algorithm is

Singarasa Joyalraj Data structure and algorithms Page 75 of 81


HND in Computing and Systems
Development

a step-by-step instruction for solving any problem, and each problem can have an infinite
number of solutions. However, in order to solve any problem, we must compare the
efficiency of all possible solutions to the same problem. This efficiency is measured in
terms of the amount of time and/or space required by an algorithm for an input of a given
size (n), and it is referred to as complexity.
Two types Complexity
Time Complexity of an Algorithm
Any physical object in the Universe is defined by Space and Time. Similarly, an algorithm's
effectiveness can be defined by its space and time complexity. While we all know that there
are multiple ways to solve a problem in programming, understanding how the algorithm
works efficiently can add value to the way we program. To determine the effectiveness of a
program/algorithm, knowing how to evaluate them using Space and Time complexity can
cause the program to behave optimally, making us efficient programmers.
While we save understanding Space complexity for another post, let us focus on Time
complexity in this one. Money is made from time! This post will give you a gentle
introduction to an algorithm's Time complexity and how to evaluate a program based on
Time complexity.

Space Complexity of an Algorithm


Running an algorithm on a computer inevitably requires a certain amount of memory space.
Space complexity represents the amount of memory a program uses to achieve its
execution. Space complexity is ancillary input space because the program needs memory to
store input data and time values during execution. It is useful for evaluating solutions as
well as time complexity. In the case of time complexity, it is expressed using the same
Landau notation as shown above.

As with time complexity, there are different types of spatial complexity, depending on the
memory consumed by each algorithm. An example of an algorithm with a certain amount of
space complexity is a selection sort because it works on the same array without any other
memory space. Merge sort is an example of an algorithm with linear space complexity. You
need to create many arrays that are part of the original array. Therefore, the larger the array,
the more memory space is required.

Singarasa Joyalraj Data structure and algorithms Page 76 of 81


HND in Computing and Systems
Development

Trade-off of types
Trade-off is a situational decision that involves reducing or eliminating one quality,
quantity, or property of a set or design in exchange for gains in other areas. In layman's
terms, a tradeoff occurs when one thing increases while another must decrease. Tradeoffs
arise from a variety of sources, including simple physics. For example, because only a
certain volume of objects can fit into a given space, a full container must remove some
items in order to accept any more, and vessels can carry a few large items or multiple small
items. Tradeoffs are also commonly used to refer to different configurations of a single
item, such as tuning the strings on a guitar to allow different notes to be played, as well as
allocating time and attention to different tasks.

The term is also widely used in evolutionary contexts, where natural selection and sexual
selection are referred to as the ultimate determining factors. The concepts of tradeoffs and
constraints are frequently intertwined in biology. A trade-off is commonly expressed in
economics in terms of the opportunity cost of one potential choice, which is the loss of the
best available alternative.

Advantages of independent data

1. A single storage location for all data also means that there is only one primary record for
a particular dataset, maximizing data integrity and minimizing data redundancy. This
ensures that your data is more reliable because you can maintain it accurately and
consistently.
2. A single data storage location is common because it means that the database can only be
attacked in one place and a set of data can be stolen or tampered with. Data security is
increased.
3. Data backup and maintenance is easier and less time consuming, allowing for better data
storage than distributed.
4. End-user ease of use due to the simplicity of a single database design.
5. In general, it facilitates data portability and database management.

Singarasa Joyalraj Data structure and algorithms Page 77 of 81


HND in Computing and Systems
Development

6. It is more cost effective than other types of database systems because it minimizes labor
costs, power supplies, and maintenance costs.
7. Data held in the same location is easy to edit, update, reorganize, mirror, or analyze.
8. All information can be accessed from the same location at the same time.
9. Updates for a particular dataset will be received immediately by all end users.

Singarasa Joyalraj Data structure and algorithms Page 78 of 81


HND in Computing and Systems
Development

Reference
Algorithms and Complexities. 2022. Algorithms and Complexities. [ONLINE] Available
at: https://www.tutorialspoint.com/Algorithms-and-Complexities. [Accessed 7 January 2022].

Big-O Notation, Omega Notation and Big-O Notation (Asymptotic Analysis). 2022. Big-O
Notation, Omega Notation and Big-O Notation (Asymptotic Analysis). [ONLINE] Available
at: https://www.programiz.com/dsa/asymptotic-notations. [Accessed 7 January 2022].

Guru99. 2022. Encapsulation in Java OOPs with Example. [ONLINE] Available


at: https://www.guru99.com/java-oops-encapsulation.html. [Accessed 7 January 2022].

Java Tutorial. 2022. Java Tutorial. [ONLINE] Available


at: https://www.tutorialspoint.com/java/index.htm. [Accessed 05 January 2022].
PCMag. 2022. Definition of error handling | PCMag. [ONLINE] Available
at: https://www.pcmag.com/encyclopedia/term/error-handling. [Accessed 05 January 2022].
Rajinikanth. 2022. Data Structures Tutorials - Selection Sort Algorithm with an example.
[ONLINE] Available at: http://www.btechsmartclass.com/data_structures/selection-sort.html.
[Accessed 7 January 2022].

Scientech Easy. 2022. Encapsulation in Java | Realtime Example, Advantage - Scientech


Easy. [ONLINE] Available at: https://www.scientecheasy.com/2020/07/encapsulation-in-
java.html/. [Accessed 7 January 2022].

Shortest-path algorithm. 2022. Shortest-path algorithm. [ONLINE] Available


at: https://www.cs.cornell.edu/courses/JavaAndDS/shortestPath/shortestPath.html. [Accessed
7 January 2022].

www.javatpoint.com. 2022. Bubble Sort - javatpoint. [ONLINE] Available


at: https://www.javatpoint.com/bubble-sort. [Accessed 7 January 2022].

www.javatpoint.com. 2022. Exception Handling in Java | Java Exceptions - javatpoint.


[ONLINE] Available at: https://www.javatpoint.com/exception-handling-in-java. [Accessed
7 January 2022].

www.javatpoint.com. 2022. Test Case - javatpoint. [ONLINE] Available


at: https://www.javatpoint.com/test-case. [Accessed 7 January 2022].

Singarasa Joyalraj Data structure and algorithms Page 79 of 81


HND in Computing and Systems
Development

Singarasa Joyalraj Data structure and algorithms Page 80 of 81


HND in Computing and Systems
Development

Singarasa Joyalraj Data structure and algorithms Page 81 of 81

You might also like