Professional Documents
Culture Documents
Give details:
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
LO2 Discuss the advantages, complexity of Abstract Data Type and importance concepts of
Object orientation.
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
Action Plan
Summative feedback
• 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.
• 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.
• The font size should be 12 point, and should be in the style of Time New Roman.
• 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.
• 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.
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.
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.
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
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
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
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
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
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)
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.
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.
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.
2. When we have a problem with data structures it is very unlikely that we can solve it
without the expertise of a professional.
of a car in single node. Because of this reason, dynamic implementation was selected for the
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 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
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 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
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.
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).
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.
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.
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.
Interface
Output
Output
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)
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.
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.
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.
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.
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
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
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.
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
Evidence for
test
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
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
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
Evidence
for test
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
Test case 06
No
Test name Right way to choosing Stackl Command
Test Run “java stackl” than choosing Random function in ABC(PVT) car
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
Evidence
for test
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
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
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
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
Evidence
for test
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
Evidence
for test
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
Evidence
for test
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.
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.
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.
Encapsulation
Advantages of Encapsulation
1. The attached code is very flexible and easy to change with new requirements.
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.
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.
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
Step 2
Step 3
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.
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.
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.
Step 1 - Select the first item from the list (i.e. the item in the first position in the list).
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.
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 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.
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
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
.
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.
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
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.
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.
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.
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.
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.
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].