0% found this document useful (0 votes)
140 views82 pages

ABC Same Code

Mrs. Ishani Assignment Number 1 Issue Date 01/10/2021 Submission Date 15/10/2021 Introduction This assignment aims to assess your understanding of different data structures and algorithms. You are required to implement and demonstrate some common data structures and algorithms. You need to evaluate their effectiveness and complexity. Task 1: Examine different concrete data structures and their valid operations. (P1, P2) Task 2: Discuss the advantages, complexity of Abstract Data Type and importance concepts of Object orientation. (P3, M3, D2) Task 3: Implement, demonstrate and evaluate complex ADT algorithm. (P4, P5, M

Uploaded by

Raisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views82 pages

ABC Same Code

Mrs. Ishani Assignment Number 1 Issue Date 01/10/2021 Submission Date 15/10/2021 Introduction This assignment aims to assess your understanding of different data structures and algorithms. You are required to implement and demonstrate some common data structures and algorithms. You need to evaluate their effectiveness and complexity. Task 1: Examine different concrete data structures and their valid operations. (P1, P2) Task 2: Discuss the advantages, complexity of Abstract Data Type and importance concepts of Object orientation. (P3, M3, D2) Task 3: Implement, demonstrate and evaluate complex ADT algorithm. (P4, P5, M

Uploaded by

Raisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

Higher Nationals

Internal verification of assessment decisions – BTEC (RQF)


INTERNAL VERIFICATION – ASSESSMENT DECISIONS
Programme title Higher National Diploma in Computing

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

S.P. Thilina Dhananjaya Gunasena


Student’s name
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


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

Assessor signature Date

Internal Verifier signature Date


Programme Leader signature (if required)
Date

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 1 | 82
Confirm action completed
Remedial action taken

Give details:

Assessor signature Date


Internal Verifier
signature Date

Programme Leader
signature (if required) Date

Higher Nationals - Summative Assignment Feedback Form

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 2 | 82
Student Name/ID S.P. Thilina Dhananjaya Gunasena/KANA013497

Unit Title Unit 19: Data Structures and Algorithms

Assignment 1 Assessor
Number
Date Received
Submission Date 1st
submission
Date Received 2nd
Re-submission submission
Date
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

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 3 | 82
Formative Feedback: Assessor to Student

Action Plan

Summative feedback

Feedback: Student to Assessor

Assessor Date
signature

Student Date
signature

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 4 | 82
Pearson Higher Nationals in
Computing
Unit 19: Data Structures & Algorithms
Assignment 01

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 5 | 82
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 details. eg: Figures, tables of comparison etc. Adding text boxes in
the body except for the before mentioned compulsory details 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.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 6 | 82
• 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.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 7 | 82
• 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.

[email protected] 2021/10/09
Student’s Signature: Date:
(Provide E-mail ID) (Provide Submission Date)

Higher National Diploma in Business


Assignment Brief
Student Name /ID Number S.P. Thilina Dhananjaya Gunasena/KANA-013497
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

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 8 | 82
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.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 9 | 82
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 Details hiding when using an ADT
selected for the above scenario.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 10 | 82
“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.

TASK 01__________________________________________________________________18

WHAT IS DATA STRUCTURE?____________________________________________18

WHAT ARE THE TYPES OF DATA STRUCTURES?________________________19

Stack Data Structure___________________________________________________________________________19

Queue Data Structure__________________________________________________________________________19

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 11 | 82
Linked List Data Structure_______________________________________________________________________20

Which data structure is most suitable for the above scenario?_________________________________________20

How fits Linked List Data Structure for the Given Scenario_____________________________________________21

OPERATION OF THE QUEUE_____________________________________________22


Enqueue Operation__________________________________________________________________________22
Dequeue Operation__________________________________________________________________________22
is Empty: Check if the queue is empty___________________________________________________________23
Is Full: -___________________________________________________________________________________23
Peek: -____________________________________________________________________________________23

USING THESE OPERATIONS TO GIVEN SCENARIO______________________23

TASK 2____________________________________________________________________24

CAR RACING SYSTEM FOR ABC PVT LTD________________________________24

Codes And Test Case for Register Car Details________________________________________________________24

Add Method__________________________________________________________________________________25

Addtolist Method_____________________________________________________________________________26
Test Case for Add Car details___________________________________________________________________30

Codes And Test Case for Delete a Car Details________________________________________________________31


Code for deleting a car_______________________________________________________________________31
Test Case for Delete a car_____________________________________________________________________34

Codes And Test Case for Search a Car Details_______________________________________________________35


Code for Search a Car________________________________________________________________________35
Test case for search a car_____________________________________________________________________37

Codes And Test Case for Inserting 3 rounds results and finding the winners_______________________________38
Code for Inserting 3 rounds results and finding the winners__________________________________________38

Test Case for Inserting 3 rounds results and finding the winners________________________________________41

ERROR HANDLING TECHNIQUES USED_________________________________42

Test Case for error handling techniques____________________________________________________________44

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 12 | 82
TASK 3____________________________________________________________________45

What is the sorting?___________________________________________________________________________45

Types of sorting techniques_____________________________________________________________________46


Insertion sort_______________________________________________________________________________46
Merge Sort________________________________________________________________________________47
Radix Sort_________________________________________________________________________________48
Shell Sort__________________________________________________________________________________48
Heap Sort__________________________________________________________________________________49
Selection sort______________________________________________________________________________50
Bubble sort________________________________________________________________________________51

BEST SORTING METHOD FOR THE ABOVE SCENARIO__________________51

Coding and Test case for sorting method___________________________________________________________52


Testcase for sorting__________________________________________________________________________54

What is the ADT (Abstract Data Type)?____________________________________________________________56

Why we are using ADT in java programming?_______________________________________________________58

Does our program Complexity High when using ADT? Or is it low?______________________________________58

WHAT IS THE ENCAPSULATION?________________________________________59

Advantages of Encapsulation:____________________________________________________________________60

What is the Data Hiding?_______________________________________________________________________61

IS ENCAPSULATION AND DATA HIDING BEING ADVANTAGE FOR


ABOVE SCENARIO________________________________________________________62

What is the OOP?_____________________________________________________________________________66

Advantages of Object-Oriented Programming_______________________________________________________66

OOPL – Object Oriented Programming Languages___________________________________________________66

What are the imperative Abstract Data types?______________________________________________________67

IMPERATIVE ADTS ARE BASIS FOR OBJECT ORIENTATION_____________67

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 13 | 82
TASK 4____________________________________________________________________68

ALGORITHM USED TO FIND THE SHORTEST PATH_____________________68

GRAPH TO FIND THE SHORTEST PATH__________________________________70

SORTING ALGORITHMS FOR ABC_______________________________________71

Algorithm for Insertion sorting method____________________________________________________________72

Algorithm for Selection sorting Method___________________________________________________________73

INSERTION VS SELECTION_______________________________________________74

FIGURE LIST
FIGURE 1 DATA STRUCTURE_________________________________________________________________________18
FIGURE 2 STACK DATA STRUCTURE_____________________________________________________________________19
FIGURE 3 QUEUE DATA STRUCTURE____________________________________________________________________20
FIGURE 4 QUEUE DATA STRUCTURE____________________________________________________________________20
FIGURE 5 OPERATION OF THE QUEUE__________________________________________________________________22
FIGURE 6 ADD METHOD CODE_______________________________________________________________________25
FIGURE 7 ADDTOLIST METHOD CODE 1_________________________________________________________________26
FIGURE 8 ADDTOLIST METHOD CODE 2_________________________________________________________________27
FIGURE 9 ADDTOLIST METHOD CODE 3_________________________________________________________________28
FIGURE 10 ADDTOLIST METHOD CODE 4________________________________________________________________29
FIGURE 11 CAR DETAILS OF LINKED LIST_________________________________________________________________30
FIGURE 12 LINKED LIST FOR ADD CAR IDS FOR CAR RACE_____________________________________________________30
FIGURE 13 TEST CASE FOR ADD CAR DETAILS_____________________________________________________________31
FIGURE 14 DELETING A CAR 1________________________________________________________________________32
FIGURE 15 DELETING A CAR 2________________________________________________________________________33
FIGURE 16 DELETING A CAR 3_______________________________________________________________________34
FIGURE 17 TEST CASE FOR DELETE A CAR________________________________________________________________35

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 14 | 82
FIGURE 18 SEARCH A CAR 1_________________________________________________________________________36
FIGURE 19 SEARCH A CAR 2_________________________________________________________________________37
FIGURE 20 CASE FOR SEARCHING A CAR_________________________________________________________________38
FIGURE 21 SELECT WINNERS 1_______________________________________________________________________39
FIGURE 22 SELECT WINNERS 2_______________________________________________________________________40
FIGURE 23 TEST CASE FOR INSERT 3 ROUNDS RESULTS AND FIND OUT THE WINNERS__________________________________41
FIGURE 24 USING TRY_____________________________________________________________________________43
FIGURE 25 USING CATCH___________________________________________________________________________44
FIGURE 26 TEST CASE FOR ERROR HANDLING TECHNIQUES____________________________________________________45
FIGURE 27 INSERTION SORT_________________________________________________________________________46
FIGURE 28 MERGE SORT___________________________________________________________________________47
FIGURE 29 RADIX SORT____________________________________________________________________________48
FIGURE 30 SHELL SORT____________________________________________________________________________49
FIGURE 31 HEAP SORT____________________________________________________________________________50
FIGURE 32 SELECTION SORT_________________________________________________________________________50
FIGURE 33 BUBBLE SORT___________________________________________________________________________51
FIGURE 34 SORTING CODE 1________________________________________________________________________53
FIGURE 35 SORTING CODE 2________________________________________________________________________53
FIGURE 36 TEST CASE FOR SORTING 1__________________________________________________________________55
FIGURE 37 TEST CASE FOR SORTING 2__________________________________________________________________56
FIGURE 38 ABSTRACT DATA TYPE_____________________________________________________________________57
FIGURE 39 ENCAPSULATION_________________________________________________________________________60
FIGURE 40 METHOD FOR GET CAR DETAILS_______________________________________________________________63
FIGURE 41 CODE FOR ENCAPSULATION__________________________________________________________________64
FIGURE 42 DATA HIDING___________________________________________________________________________65
FIGURE 43 DATA HIDING___________________________________________________________________________65
FIGURE 44 GRAPH_______________________________________________________________________________70

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 15 | 82
TASK 01

What is Data Structure?

A data structure is a specialized format for organizing, processing, retrieving and storing
data. There are several basic and advanced types of data structures, all designed to arrange
data to suit a specific purpose. Data structures make it easy for users to access and work with
the data they need in appropriate ways. Most importantly, data structures frame the
organization of details so that machines and humans can better understand it.

In computer science and computer programming, a data structure may be selected or


designed to store data for the purpose of using it with various algorithms. In some cases, the
algorithm's basic operations are tightly coupled to the data structure's design. Each data
structure contains details about the data values, relationships between the data and -- in some
cases -- functions that can be applied to the data.[ CITATION htt2128 \l 1033 ]

Figure 1 Data Structure

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 16 | 82
What Are the types of data structures?
The data structure type used in a particular situation is determined by the type of operations
that will be required or the kinds of algorithms that will be applied

Stack Data Structure

In stack data structure, elements are stored in the LIFO principle. That is, the last element
stored in a stack will be removed first. It works just like a pile of plates where the last plate
kept on the pile will be removed first.

Figure 2 Stack Data structure

Queue Data Structure

Unlike stack, the queue data structure works in the FIFO principle where first element stored
in the queue will be removed first. It works just like a queue of people in the ticket counter
where first person on the queue will get the ticket first.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 17 | 82
Figure 3 Queue Data Structure

Linked List Data Structure

In linked list data structure, data elements are connected through a series of nodes. And, each
node contains the data items and address to the next node.

Figure 4 Queue Data Structure

Which data structure is most suitable for the above scenario?


While deciding which is suitable for given scenario, I suggest Linked List data structured is
the most suitable for the given system. Here I’m outline the suitable reasons for choose
structure.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 18 | 82
How fits Linked List Data Structure for the Given Scenario
I mentioned above Linked list is suitable for the scenario because it execute like every
functions in the system given below;

The main functions are,

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
ABC Pvt ltd organize a car event with 6 participants so they decide to build an application for
that. In that application basic method, the first thing is required to register car detail’s
function is called first in first out. That can be also used as a queue also it can’t be use as a
queue because other function cannot be use what mentioned in here. If we use LinkedList
we can do it as we want. While we entering data about car also, we can enter several car
details at once.
As example Enter the drivers NIC number as string, but we have to enter his age as the
integer. We have to enter different types of details at once then I recommended possible
function is LinkedList
Next function is Delete a car from the application function. For that we can use all the three
stacks, queues and LinkedList for our need. While using stack function we can only delete
last element of the given list. The reason because it comes as First in last out or Last in First
out theory and also queue cannot be used because it common theory was First thing First
out. That means we can delete what data in the first in the list. So, we can LinkedList
Function for this then we can easily manage what we want to do.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 19 | 82
For the next function Insert 3 rounds result. We can use Stack functions method Last in first
Out But same process can be done using the LinkedList function here.
The next step is we want to find out winners and position as 1,2,3. As I mentioned earlier
the three functions can be used for this but most suitable function is Linked List because
other functions cannot do what require here.
The last function will be Search Particular Car from the list. In here we cannot use other 2
structures because none of that 2 can do what require. So, for that most suitable structure is
the Linked list. So, I choose LinkedList for the following function.

Operation Of the Queue

Figure 5 Operation of the Queue

Enqueue Operation

Enqueue means inserting an element in the queue. In a Avarage queue at a ticket counter,
where does a new person go and stand to become a part of the queue? The person goes and
stands in the back. Similarly, a new element in a queue is inserted at the back of the queue.

Dequeue Operation

Dequeue means removing an element from the queue. Since queue follows the FIFO
principle we need to remove the element of the queue which was inserted at first. Naturally,
the element inserted first will be at the front of the queue so we will remove the front
element and let the element behind it be the new front element.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 20 | 82
is Empty: Check if the queue is empty

To prevent performing operations on an empty queue, the programmer is required to


internally maintain the size of the queue which will be updated during enqueue and deque
operations accordingly. is Empty () conventionally returns a Boolean value: True if size is 0,
else False.

Is Full: -
This is used to determine if the queue is full. That is, when we use this operation, the relevant
queue will be displayed as true or false if it is completely filled. This is because it is also
activated by Boolean indicators. This is mostly used to identify whether a queue is full before
entering data into it.

Peek: -
This will get the first element of the relevant queue. This is very important to identify the
original value of an element after removing it from the relevant queue. Because after
removing any value from the queue, it is very important to identify the next original value.

Using these operations to given Scenario


The require functions are given by the scenario is Register Car Details, delete a car, insert 3
Rounds Results, Find out the winners (1st, 2nd, 3rd)

Search a car while we using single queue to create the following system, we can use
Enqueue, Dequeue, is empty, is full or Peek functions to accesses the “Insert 3 rounds of car
Results”. This allows only the data of those who completed the first round at the end of one
round to be entered into this queue.

Find out who in the winner by displaying only the data that remaining in the relevant queue
at the end of match using function Dequeue.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 21 | 82
We can use Is full function to check whether there is possibility to registering another person
in the queue before entering the data before using the function Register Car Details.

While we creating the functions Delete a car and Search for a Particular Car, we can use Is
empty to check that queue is empty or Peek function, find if there is new peek when delete a
car function activated.

Likewise, the list of the operations queue can be used for the given scenario as it needs.

Task 2

Car Racing system for ABC Pvt ltd


For ABC private limited below I’m showing what system I have been created. I hope to show
the codes related to the key components that should be included in the system and the test
cases to test them. I’m showing the codes that will apply for the system and some basic
functions.

1. Car Registration Details


2. Deleting a Car
3. Search a Car
4. Inserting 3 rounds results and finding the winners (1st, 2nd ,3rd)

Codes And Test Case for Register Car Details


I have been used some methods for this section and basic functions in the system and also if
impossible to1 create this section properly it will interrupt the proposed system. Because the
data we get from this section applies to the last part of the system. “Finding the winners (1st,
2nd ,3rd)”. Along these lines, on the off chance that we don't make this segment appropriately
here, in the end all the data we get from this system is bound to be off-base. Along these
lines, I tried to make this part with extreme attention to detail while making it. As needs be, I

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 22 | 82
have used two fundamental strategies for this segment and I desire to clarify independently
what occurs with them.

Methods has been used,

 Add Method
 Addtolist Method

Add Method
This is finished by making sure that the details given by the client is right and presenting
every one of the details to the Addtolist method. In like manner, I will get all the ID, Brand,
Sponsor, Driver Name, Driver Age and Registered Date data of the applicable enrolled
registered car and afterward it will be given to the Addtolist method.

Figure 6 Add Method code

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 23 | 82
Addtolist Method
What I did utilizing this technique was to add details to this strategy utilizing the Add ()
method above and afterward check in case it is feasible to enter the data in the linked list that
coordinates with the applicable car ID. In case there is no space in the linked list, the PC
screen will re-yield that the pertinent client cannot enter additional details into the system.

Figure 7 Addtolist Method code 1

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 24 | 82
Figure 8 Addtolist Method code 2

Figure 9 Addtolist Method code 3

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 25 | 82
Figure 10 Addtolist Method code 4

Below are 6 basic linked lists for entering all the data mentioned above. When data is added
to the system with the new car, the relevant carid is included in a separate linked list

Figure 11 Car details of Linked List

Figure 12 Linked List for Add car Ids for Car race

Test Case for Add Car details


Test Feature Add car
Testing Car Details Add
Inputs Car Id = C2
Brand = Mitsubishi
Sponsor = ABC PVT LTD
Driver’s First Name = Thilina
Driver’s Last Name= Dhananjaya
Driver’s Age = 28
Expected Outcome Successfully add Car Details
You Added Details are:
[C2, Mitsubishi, ABC PVT LTD
, Thilina, Dhananjaya,28]

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 26 | 82
Successfully add Car Details
Actual Outcome
You Added Details are:
[C2, Mitsubishi, ABC PVT LTD
, Thilina, Dhananjaya,28]
Tester Name Thilina Dhananjaya
Test successful Yes/No Yes

Figure 13 Test case for Add car Details

Codes And Test Case for Delete a Car Details


Code for deleting a car
This function is likewise a significant piece of this system. This is since, in such a case that
we at any point need to eliminate data about an unwanted car from this system, we need this
"Deleting a Car" section. Likewise, I was extremely cautious in making this part, in light of
the fact that main the car data that the significant user enters here ought to have the option to
be appropriately taken out from this system. since I have entered the ID of the cars here as
C1, C2, C3, C4, C5 and C6, the significant data ought to be appropriately eliminated from
the system regardless of how the client enters this ID. I have used one method to do this and
it takes the car Id entered by the client. car ID coordinating with the ID is to eliminate the car

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 27 | 82
ID from the LinkedList that incorporates the applicable car ID for the race and delete the
details from the LinkedList made for that car Id.

Figure 14 deleting a car 1

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 28 | 82
Figure 15 deleting a car 2

Figure 16 Deleting a car 3

Test Case for Delete a car


Test Feature Deleting a Car
Testing Car Deleted
Inputs Car Id = C2
Expected Outcome Car deleted Successfully

Actual Outcome Car deleted Successfully

Tester Name Thilina Dhananjaya


Test successful Yes/No Yes

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 29 | 82
Figure 17 Test case for Delete a car

Codes And Test Case for Search a Car Details


Code for Search a Car
This function is additionally a vital component in this system and it permits the clients of the
pertinent system to look for the data of the cars remembered for the system whenever. In the
entering the ID of the cars we need to know the details in this system, the client will actually
want to see the pertinent data of the cars in which details is put away in this system under the
significant Car Id. Subsequently, I was more cautious in making this function. This is on the
grounds that this segment ought to give the client the specific details that coordinates with
the cars ID entered by the client. Thus, I used one technique for this too so when the relevent
client signs into the system it will show the Id's of the cars that have been added to the
system and the applicable client can enter the necessary Car ID into the system so the
individual can appropriately see the necessary data.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 30 | 82
Figure 18 Search a car 1

Figure 19 Search a car 2

Test case for search a car

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 31 | 82
Search a Car
Test Feature
Testing Searching a car
Inputs Car Id = C1

Expected Outcome [C1, Mitsubishi Lancer, ABC PVT


LTD, Thilina Dhananjaya,28]
Actual Outcome [C1, Mitsubishi Lancer, ABC PVT
LTD, Thilina Dhananjaya,28]
Tester Name Thilina Dhananjaya

Test successful Yes/No Yes

Figure 20 Case for Searching a car

Codes And Test Case for Inserting 3 rounds results and finding the winners
Code for Inserting 3 rounds results and finding the winners
This is the main function of this system. Since this is the essential function anticipated from
this system. That is, after we have entered every one of the details, this is the technique that
we will at long last use to choose the champs of the car race. Consequently, this function is
vital and extraordinary consideration ought to be taken while making this part. In this way, I
have essentially used one technique here and the client should enter the details of car 6
preceding beginning the game. Else, I have made this piece of the system so that it can't be
opened. As needs be, in the entering every one of the details and opening this segment, I
have made a LinkedList that I have made above to consequently duplicate the LinkedList I
made above to enter the Car ID s, and the car Id of the player who finished that round toward
the finish of each round of the opposition. I have planned it to be remembered for this

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 32 | 82
system. I then, at that point, planned the system so that toward the finish of the last round the
car ID s of the principal, second and third spot finishers in the opposition could be shown on
the PC screen by the client.

Figure 21 Select winners 1

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 33 | 82
Figure 22 Select winners 2

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 34 | 82
Test Case for Inserting 3 rounds results and finding the winners
Test Feature Start Race
Testing Selecting winners
Inputs Round 1 last car Id = C3
Round 2 last car Id = C1
Round 3 last car Id = C5
Expected Outcome Winners Are: [C2, C4, C6]
Actual Outcome Winners Are: [C2, C4, C6]
Tester Name Thilina Dhananjaya

Test successful Yes/No Yes

Figure 23 Test Case for Insert 3 Rounds Results and Find out the winners

Error Handling techniques used


This technique is important while creating a program. Because we can use error handling
techniques to avoid the recurrence of the eror that we difficult to detect. There are several
error handling techniques used in this regard and they are given below.

 Try
 Catch
 Finally

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 35 | 82
 Throw

Although there are so many error handling techniques, when I was creating this system, the
two main methods I used were try and catch. The code below is a basic example of how I
used those two error handling techniques.

Figure 24 Using Try

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 36 | 82
Figure 25 Using catch

Using the codes are giving Im used 2 techniques to display the error massage stating that
when once users have to entered the system, they will not be able to enter letters for the
relevant location if they enter a letter in the number field. The following testcase can be used
as an example for an error message to appear.

Test Case for error handling techniques


Test Feature Home
Testing Error Handling
Inputs A
Expected Outcome Warning...! You Can’t Enter Letters
Actual Outcome Warning...! You Can’t Enter Letters
Tester Name Thilina Dhananjaya

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 37 | 82
Test successful Yes/No Yes

Figure 26 Test Case for error handling techniques

Task 3
What is the sorting?

Sorting refers to the operation or technique of arranging and rearranging sets of data in some
specific order. A collection of records called a list where every record has one or more fields.
The fields which contain a unique value for each record is termed as the key field. For
example, a phone number directory can be thought of as a list where each record has three
fields - 'name' of the person, 'address' of that person, and their 'phone numbers'. Being unique
phone number can work as a key to locate any record in the list.

Sorting is the operation performed to arrange the records of a table or list in some order
according to some specific ordering criterion. Sorting is performed according to some key
value of each record. The records are either sorted either numerically or alphanumerically.
The records are then arranged in ascending or descending order depending on the numerical
value of the key. Here is an example, where the sorting of a lists of marks obtained by a
student in any particular subject of a class. [ CITATION htt2181 \l 1033 ]

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 38 | 82
Types of sorting techniques
Insertion sort
Insertion sort is a simple sorting algorithm that works similar to the way you sort playing
cards in your hands. The array is virtually split into a sorted and an unsorted part. Values
from the unsorted part are picked and placed at the correct position in the sorted part.

Algorithm

To sort an array of size n in ascending order:

1: Iterate from arr[1] to arr[n] over the array.

2: Compare the current element (key) to its predecessor.

3: If the key element is smaller than its predecessor, compare it to the elements before. Move
the greater elements one position up to make space for the swapped element.

Figure 27 Insertion Sort

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 39 | 82
Merge Sort
Like Quicksort, Merge Sort is a Divide and Conquer algorithm. It divides the input array into
two halves, calls itself for the two halves, and then merges the two sorted halves. The merge
() function is used for merging two halves. The merge (arr, l, m, r) is a key process that
assumes that arr[l..m] and arr[m+1..r] are sorted and merges the two sorted sub-arrays into
one. See the following C implementation for details.

Merge sort can be done in two types both having similar logic and way of implementation.
These are:

 Top-down implementation
 Bottom-up implementation

Figure 28 Merge Sort

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 40 | 82
Radix Sort
Radix sort is an integer sorting algorithm that sorts data with integer keys by grouping the
keys by individual digits that share the same significant position and value (place value).
Radix sort uses counting sort as a subroutine to sort an array of numbers. Because integers
can be used to represent strings (by hashing the strings to integers), radix sort works on data
types other than just integers. Because radix sort is not comparison based, it is not bounded
by Ω(nlogn)\Omega (n \log n)Ω(nlogn) for running time — in fact, radix sort can perform in
linear time.

Figure 29 Radix Sort

[ CITATION htt2182 \l 1033 ]

Shell Sort
Shell Sort is mainly a variation of Insertion Sort. In insertion sort, we move elements only
one position ahead. When an element has to be moved far ahead, many movements are
involved. The idea of shell Sort is to allow exchange of far items. In shell Sort, we make the
array h-sorted for a large value of h. We keep reducing the value of h until it becomes 1. An
array is said to be h-sorted if all sub lists of every h’th element is sorted.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 41 | 82
Figure 30 Shell sort

Heap Sort
Heap sort is a comparison-based sorting technique based on Binary Heap data structure. It is
similar to selection sort where we first find the minimum element and place the minimum
element at the beginning. We repeat the same process for the remaining elements.

What is Binary Heap?

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 42 | 82
Let us first define a Complete Binary Tree. A complete binary tree is a binary tree in which
every level, except possibly the last, is completely filled, and all nodes are as far left as
possible (Source Wikipedia)

A Binary Heap is a Complete Binary Tree where items are stored in a special order such that
the value in a parent node is greater (or smaller) than the values in its two children’s nodes.
The former is called max heap and the latter is called min-heap. The heap can be represented
by a binary tree or array.

Figure 31 Heap Sort

[ CITATION htt2182 \l 1033 ]

Selection sort
The selection is a straightforward process of sorting values. In this method, to sort the data in
ascending order, the 0th element is compared with all other elements. If the 0th element is
found to be greater than the compared element, the two values get interchanged. In this way
after the first iteration, the smallest element is placed at 0th position. The technique is
repeated until the full array gets sorted.[ CITATION htt2183 \l 1033 ]

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 43 | 82
Figure 32 Selection Sort

Bubble sort
Bubble Sort Algorithm is used to arrange N elements in ascending order, and for that, you
have to begin with 0th element and compare it with the first element. If the 0th element is
found greater than the 1st element, then the swapping operation will be performed, i.e., the
two values will get interchanged. In this way, all the elements of the array get compared.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 44 | 82
Figure 33 Bubble Sort

[ CITATION htt2184 \l 1033 ]

Best sorting method for the above scenario


Thinking about the above situation, picking the most reasonable sorting method was
extremely hard. The reason for this is that when we register every car here, we used 6
separate LinkedList for every car, one LinkedList for every car. Then, at that point, the dates
on which these cars are enlisted are entered independently in 6 LinkedList. Along these lines,
when we sort this LinkedList 6, it is unimaginable to expect to do everything simultaneously
and we need to change this LinkedList 6 to suit quite possibly the most well-known common

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 45 | 82
sorting methods we can used. Thus, I changed this LinkedList 6 to a collection sorting that
permits you to enter any kind of information. Then, at that point, I arranged the information
of these 6 cars by the assortment sorting methods and with this assortment sort I used the
collection sorting method. The principal reason I used this collection sorting method is that
we need to sort this is a direct result of a tiny number of items like 6 articles. Since utilizing
this sorting method we can do this sort rapidly. That is, it doesn't take long to sort the 6
LinkedList used for sorting independently. Along these lines, the primary justification for
utilizing the choice sort for this sorting was that this sort could undoubtedly apply the
pertinent arranging rapidly. The fundamental justification for why this collection sorting is so
appropriate to this situation is that we need to sort a tiny measure of information in this
situation. Also, when utilizing this sorting method, we don't need to compose an extremely
long measure of code so we can run this system exceptionally quick in the PC when running.
That is another justification for why I picked collection sorting for this sorting. In any case,
in the event that I used one more sorting method for this, I will actually want to do this
errand. However, I understood that other sorting method don't make this sorting as quick and
quick as the collection sorting. I likewise understood that in the event that I used one more
sorting method for this, it very well may be exceptionally adverse to the running rate of the
system because of their long code. Therefore, I decide that the collection sorting is very
suitable for this scenario. Below are the codes and test cases of the sorting method I created
for this system.

Coding and Test case for sorting method


I have made a linked list of cars as the usual here and have remembered the data of the
important cars for 6 such Linked-list. The client is then shown to enter the number '1'
assuming they need to sort the Linked-list 6 as the freshest to the most seasoned or '0'
assuming they need to sort the most established to the most seasoned and the LinkedList 6
sorts and returns as per the number they enter. The manner in which I planned this system.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 46 | 82
Figure 34 Sorting Code 1

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 47 | 82
Figure 35 Sorting Code 2

Testcase for sorting


Test Feature Sorting
Testing Oldest to newest
Inputs 0

Expected Outcome Car details of order by Oldest to Newest


Car Details [Registered Date=1993, Car Id=1]
Car Details [Registered Date=1996, Car Id=2]
Car Details [Registered Date=1996, Car Id=1]
Car Details [Registered Date=1998, Car Id=3]

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 48 | 82
Car Details [Registered
Date=1998, Car Id=4]
Car Details [Registered Date=2005, Car Id=5]
Actual Outcome Car details of order by Oldest to Newest
Car Details [Registered Date=1993, Car Id=1]
Car Details [Registered Date=1996, Car Id=2]
Car Details [Registered Date=1996, Car Id=1]
Car Details [Registered Date=1998, Car Id=3]
Car Details [Registered Date=1998, Car Id=4]
Car Details [Registered Date=2005, Car Id=5]
Tester Name Thilina Dhananjaya
Test successful Yes/No Yes

Figure 36 Test Case for sorting 1

Test Feature Sorting


Testing Newest To oldest
Inputs 1

Expected Outcome Car details of order by Newest to oldest


Car Details [Registered Date=2005, Car Id=5]
Car Details [Registered Date=1998, Car Id=4]
Car Details [Registered Date=1998, Car Id=3]
Car Details [Registered Date=1996, Car Id=1]
Car Details [Registered Date=1996, Car Id=2]

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 49 | 82
Car Details [Registered
Date=1993, Car Id=1]
Actual Outcome Car details of order by Newest to oldest
Car Details [Registered Date=2005, Car Id=5]
Car Details [Registered Date=1998, Car Id=4]
Car Details [Registered Date=1998, Car Id=3]
Car Details [Registered Date=1996, Car Id=1]
Car Details [Registered Date=1996, Car Id=2]
Car Details [Registered Date=1993, Car Id=1]
Tester Name Thilina Dhananjaya

Test successful Yes/No Yes

Figure 37 test case for sorting 2

What is the ADT (Abstract Data Type)?

Abstract Data type (ADT) is a type (or class) for objects whose behaviors is defined by a set
of value and a set of operations. The definition of ADT only mentions what operations are to
be performed but not how these operations will be implemented. It does not specify how data
will be organized in memory and what algorithms will be used for implementing the
operations. It is called “abstract” because it gives an implementation-independent view. The
process of providing only the essentials and hiding the details is known as abstraction.

 Stack −
o isFull(), This is used to check whether stack is full or not

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 50 | 82
o isEmpry(), This is used to check whether stack is empty or not
o push(x), This is used to push x into the stack
o pop(), This is used to delete one element from top of the stack
o peek(), This is used to get the top most element of the stack
o size(), this function is used to get number of elements present into the stack
 Queue −
o isFull(), This is used to check whether queue is full or not
o isEmpry(), This is used to check whether queue is empty or not
o insert(x), This is used to add x into the queue at the rear end
o delete(), This is used to delete one element from the front end of the queue
o size(), this function is used to get number of elements present into the queue
 List −
o size(), this function is used to get number of elements present into the list
o insert(x), this function is used to insert one element into the list
o remove(x), this function is used to remove given element from the list
o get(i), this function is used to get element at position i
o replace(x, y), this function is used to replace x with y value

.[ CITATION htt2185 \l 1033 ]

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 51 | 82
Figure 38 Abstract Data Type

Why we are using ADT in java programming?

Abstract Datatypes are the datatypes where you can logically work with the datatype, but you
would not know the inner workings of the datatype. There are many different types of
abstract data types in Java. We will talk about them in this article. Simply vertexing, if you
define a datatype with the help of a programming language and then hide its implementation,
then it is an abstract datatype. Java library has Abstract Data Types such as List, Stack,
Queue, Set, Map as inbuilt interfaces which are being implemented using various data
structures.

In Java, Abstract Data Types extend the Collections Interface which represents the data type.
It is part of the Java Collections system and is the root interface in the collection hierarchy. A
collection represents a group of objects, known as its elements.

The JDK does not provide any direct implementations of this interface. It provides
implementations of more specific sub interfaces like List, Set. This interface is typically

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 52 | 82
used to pass collections around and manipulate them where maximum generality is desired.
But if we do this using an ADT, we can use a very limited number of variables and store the
relevant data in a single variable until we get the time we need. And using this ADT allows us
to run our program very fast. This is because we have to use a limited number of variables
and use a very short number of lines of code, so the amount of space that this program runs
on the RAM of our computer is very small. Due to this we are able to increase the running
speed of the program very much.

Does our program Complexity High when using ADT? Or is it low?

While using ADT, we can enormously diminish the intricacy of our program. This is on the
grounds that the quantity of variables and methods we need to use while making a program
utilizing any ADT is exceptionally restricted. For instance, assume we get the name, address
and contact number of a few groups and use them for a specific cycle. It must be put away
independently in every factor. Then, at that point, the intricacy of our program turns out to be
extremely high. However, in the event that we use an ADT for that, we don't have to save
separate factors for every individual's data. We can make just the necessary number of factors
per individual and supplement any pertinent individual information into an ADT utilizing
while loop in the system so we needn't bother with countless factors. Hence, I presume that
the intricacy of the system when we use ADT That is extremely low.

What is the encapsulation?

Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance,
polymorphism, and abstraction.

Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the
data (methods) together as a single unit. In encapsulation, the variables of a class will be
hidden from other classes, and can be accessed only through the methods of their current
class. Therefore, it is also known as data hiding.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 53 | 82
To achieve encapsulation in Java −

 Declare the variables of a class as private.


 Provide public setter and getter methods to modify and view the variables values.

Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism
that binds together code and the data it manipulates. Another way to think about
encapsulation is, it is a protective shield that prevents the data from being accessed by the
code outside this shield.

 Technically in encapsulation, the variables or data of a class is hidden from any other
class and can be accessed only through any member function of its own class in
which it is declared.
 As in encapsulation, the data in a class is hidden from other classes using the data
hiding concept which is achieved by making the members or methods of a class
private, and the class is exposed to the end-user or the world without providing any
details behind implementation using the abstraction concept, so it is also known as a
combination of data-hiding and abstraction.
 Encapsulation can be achieved by Declaring all the variables in the class as private
and writing public methods in the class to set and get the values of variables

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 54 | 82
Figure 39 Encapsulation

Advantages of Encapsulation:

 Data Hiding: The user will have no idea about the inner implementation of the class.
It will not be visible to the user how the class is storing values in the variables. The
user will only know that we are passing the values to a setter method and variables
are getting initialized with that value.
 Increased Flexibility: We can make the variables of the class read-only or write-only
depending on our requirement. If we wish to make the variables read-only then we
have to omit the setter methods like setName(), setAge(), etc. from the above program
or if we wish to make the variables as write-only then we have to omit the get
methods like getName(), getAge(), etc. from the above program
 Reusability: Encapsulation also improves the re-usability and is easy to change with
new requirements.
 Testing code is easy: Encapsulated code is easy to test for unit testing.[ CITATION
Har21 \l 1033 ]

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 55 | 82
What is the Data Hiding?

Data hiding is a software development technique specifically used in object-oriented


programming (OOP) to hide internal object details (data members). Data hiding ensures
exclusive data access to class members and protects object integrity by preventing
unintended or intended changes. Data hiding also reduces system complexity for increased
robustness by limiting interdependencies between software components. Data hiding is also
known as data encapsulation or information hiding.

Data hiding takes certain parts of code and hides those parts from the objects. The objects
cannot directly access any data that is hidden. If an object does access hidden data, it will
return an error. This is because the object cannot see the data, so any functions or data that
are labeled as hidden will look invisible to the object. Most of the time, the data being hidden
are the internal components that are not needed by the user and can prove dangerous if the
data are laid open for the user.

The advantage for programmers is that there is no way for a programmer to accidentally link
to incorrect data. Data hiding ensures that, if a programmer does make this link, the program
will simply return an error so the programmer can quickly correct the mistake. This also
ensures that all of the objects are truly isolated units, which is the main concept of object-
oriented coding. Volatile data are typically hidden because, if such data were made public, it
could damage the object and destroy the entire program.

Another advantage of data hiding is heightened security against hackers. If all internal data
are public, a hacker can easily squeeze into the internal data and make any changes to
manipulate the program maliciously. By hiding the data, it's much harder to crack the code,
because the data will appear invisible to the objects and the hacker.

The disadvantage of data hiding is that it can sometimes force programmers to use extra
coding. If a programmer is able to link to hidden data, it can make objects work faster or cut

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 56 | 82
down on a large amount of code. Most programmers do not keep all information public,
though, because of all the problems associated with this type of coding.[ CITATION
htt2186 \l 1033 ]

Is Encapsulation and Data hiding being advantage for above scenario


Definitely it was best benefit for me while creating the system. Reason why is when we talk
about encapsulation first, it has been very important while creating the system. Because when
entering the details of the new driver and his car in to the system that helps a lot. I wasn’t
able to the enter the data’s directly to the LinkedList separately. At the beginning I’m not
been able to get the ID s of the cars only via the separate LinkedList. The reason for that if I
enter the data of the drivers in the LinkedList in the first time, it was impossible to enter the
ID of the Cars in a separate LinkedList in that moment. So, I got the relevant data from the
main method and included all data to the add car function move only the ID of the Car inside
that link to another LinkedList. Then No problem to the user can access the LinkedList
containing only the CarID and he must use Add car function, so furthermore, it can be termed
as encapsulation and the relevant code is given below.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 57 | 82
Figure 40 method for get car details

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 58 | 82
Detailing the code given below, I first concentrate the pertinent Data to a method planned as
Addtolist. The pertinent data is then added to the significant LinkedList. Simultaneously the
datas are added to the LinkedList named CarsInRace of the important car Id. This can be
named as encapsulation as we can't associate with this part in the immediate main method.
The following are the codes identified with the Addtolist Method referenced previously.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 59 | 82
Figure 41 Code for encapsulation

Then, at that point, considering the data hiding techniques I have use here, I can tell you the
best way to embed the CarID of the above Car Details into CarsInRace. C1, C2, C3, C4, C5
and C6 IDs are made to be added independently of course inside the system. As needs be,
nobody can change the CarID whenever and no user can see the work that is being finished.
The important code is given beneath.

Figure 42 Data Hiding

In addition, the car race is one of the instances where I have used the data hiding technique in
this system. This is because when the car race starts here, the LinkedList included in the
above carid is compiled to another LinkedList. This is also a data hiding technique used in
this system as it is not visible to the user at any time. The relevant code is given below

Figure 43 Data Hiding

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 60 | 82
What is the OOP?

Object-oriented programming (OOP) is a computer programming model that organizes


software design around data, or objects, rather than functions and logic. An object can be
defined as a data field that has unique attributes and behavior. OOP focuses on the objects
that developers want to manipulate rather than the logic required to manipulate them. This
approach to programming is well-suited for programs that are large, complex and actively
updated or maintained. This includes programs for manufacturing and design, as well as
mobile applications; for example, OOP can be used for manufacturing system simulation
software. The organization of an object-oriented program also makes the method beneficial
to collaborative development, where projects are divided into groups. Additional benefits of
OOP include code reusability, scalability and efficiency.

Advantages of Object-Oriented Programming

One of the principal advantages of object-oriented programming techniques over procedural


programming techniques is that they enable programmers to create modules that do not need
to be changed when a new type of object is added. A programmer can simply create a new
object that inherits many of its features from existing objects. This makes object-oriented
programs easier to modify.

OOPL – Object Oriented Programming Languages

An OOPL is a high-level programming language based on the object-oriented model. To


perform object-oriented programming, one needs an object-oriented programming language.
Many modern programming languages are object-oriented, however some older
programming languages, such as Pascal, do offer object-oriented versions. Examples of
object-oriented programming languages include Java, C++ and Smalltalk.

[ CITATION htt2187 \l 1033 ]

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 61 | 82
What are the imperative Abstract Data types?

In the "imperative" view, which is closer to the philosophy of imperative programming


languages, an abstract data structure is conceived as an entity that is mutable — meaning that
it may be in different states at different times. Some operations may change the state of the
ADT; therefore, the order in which operations are evaluated is important, and the same
operation on the same entities may have different effects if executed at different times — just
like the instructions of a computer, or the commands and procedures of an imperative
language. To underscore this view, it is customary to say that the operations are executed or
applied, rather than evaluated the imperative style is often used when describing abstract
algorithms.

.[ CITATION htt2188 \l 1033 ]

Imperative ADTs are basis for object orientation

Yes, the essence of object-oriented programming is procedural data abstraction, in which


procedures are used to represent data and procedural interfaces provide information hiding
and abstraction. This technique is complementary to ADTs, in which concrete algebras are
used to represent data, and type abstraction provides information hiding. The two paradigms
can be derived from a fundamental dichotomy in decomposing a matrix of ob-servers and
constructors that specify abstract data. PDA decomposes this matrix into constructors: a class
is associated with each constructor and the observations become attributes, or methods, of the
class’s instances. In effect, the values in the abstraction are nothing more or less than the
collection of legal observations on them. ADTs, on the other hand, decompose the matrix into
observations: each observation is an operation defined on an abstract type that includes the
constructors as representational variants.

This is on the grounds that Imperative ADTs are fundamental for object orientation. This is
on the grounds that ADT is one of the key components that are principal to object orientation.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 62 | 82
Here ADT accomplishes the work that we do inside the system from an external perspective
of the system, imperceptible to the gatherings. Accept our system for instance. That is, all the
food we put into our mouths by hand is processed by the stomach related system however we
can't see it. This is additionally the situation with Abstraction. That is, regardless of whether
we enter information into one method, its interaction happens in another technique. So
regardless of whether we consider object orientation, there is a cycle like this. In this way, the
significance of these Imperative ADTs for object orientation can be plainly expressed. Also,
one of the essential elements of ADT is to limit the intricacy of the code we compose and to
keep up with the quality and speed of the system. Thus, we additionally allude to that
capacity as an essential capacity of item direction. This is on the grounds that the system we
make can be separated into individual items to kill the intricacy of our system and
superfluous lines of code. Then, at that point, there will be no issue with the speed and
proficiency of our system. This is on the grounds that the pointless system line size has been
taken out. In this way, these components incorporate the using of object orientation with
ADT, which can prompt an unmistakable end that Imperative ADTs start to lead the pack for
object orientation and that ADT is the fundamental mainstay of the Object Orientations.

Task 4

Algorithm used to find the shortest path


Dijkstra's algorithm solves the shortest-path problem for any weighted, directed graph with
non-negative weights. It can handle graphs consisting of cycles, but negative weights will
cause this algorithm to produce incorrect results. Consequently, we assume that w(e) ≥ 0 for
all e ∈ E here. Dijkstra’s algorithm requires a priority queue at each of N iterations, where N
is the number of network nodes. The graph can either be directed or undirected. One
stipulation to using the algorithm is that the graph needs to have a nonnegative weight on
every edge. I believe that this algorithm is the most suitable way of finding the shortest path,
therefore, I have implemented it in my scenario. Below are the steps to be followed for
solving using Dijkstra’s algorithm:

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 63 | 82
1. Algorithm
Convert any problem to its graph equivalent representation.
2. Maintain a list of unvisited vertices. Assign a vertex as “source” and also allocate a
maximum possible cost (infinity) to every other vertex. The cost of the source to itself
will be zero as it actually takes nothing to go to itself.
3. In every step of the algorithm, it tries to minimize the cost for each vertex.
4. For every unvisited neighbor (V2, V3) of the current vertex (V1) calculate the new
cost from V1.
5. The new cost of V2 is calculated as:

Minimum (existing cost of V2, (sum of cost of V1 + the cost of edge from V1 to V2))

7. When all the neighbors of the current node are visited and cost has been calculated,
mark the current node V1 as visited and remove it from the unvisited list.
8. Select next vertex with smallest cost from the unvisited list and repeat from step 4.
9. The algorithm finally ends when there are no unvisited nodes left.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 64 | 82
Graph to find the shortest path

Figure 44 Graph

Table 1 Dijkstra graph to find the shortest path

Vertex Shortest path from C1 Previous


Vertex
C1 0
C2 12
C3 29 C2
C4 19 C2
C5 17
C6 23 C5

I used above graph to explain graphically about the distance and routes that used to travel
vertex to vertex. Firstly, I use starting location as named C1 from here I showed shortest
paths to vertex to vertex.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 65 | 82
When explaining about shortest path to from C1 to C2 is directly can travel because both
vertexes are point next to other. So that can travel easily vertex to vertex fast.

Then from C1 to C3 shortest path is 29. There are two paths that can travel vertex to vertex.
One is from C1 to C2 and C3 and it will be 29 and another path is From C1 to C2 and C4 and
finally to C3 it will be same as 29. But when considering shortest path, it will be C1 to C2
and C3 vertex to vertex.

From C1 to C4 short path difference will be 19. It travels through the starting point C1 to C2
and finally to C4.

From C1 to C5 short path different will be 17. It travels directly to C5 because those vertex
points near to the C1.

From C1 to C6 short path difference will be 23. That also have two paths and one is C1 to C5
and finally to C6 that vertex difference is 29 and next path is through the starting with C1 to
C2 to C4 and lastly comes to vertex difference 23. So short path will be C1 to C6 will be 23

Sorting algorithms for ABC


In here I am focusing to create sort list according to above given scenario in order which cars

are registered to race. For that I am hoping to use two basic sorting methods and that will be

selection and insertion sorting methods. Below is given algorithms for those sorting methods.

Algorithm for Insertion sorting method

Step – 1: create a LinkedList for CarList

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 66 | 82
Step – 2: insert the car numbers to LinkedList

Step – 3: create variables s, t, u, v and w

Step – 4: u= 0, w=0

Step – 5: checking if(w<6)

Step – 6: if Step 5 is true

Step – 7: step 7 is true then v=u+1

Step – 8: s= CarList[u], y=CarList[v]

Step – 9: checking if (t<s)

Step – 10: if Step 7 is true, then CarList. Remove(t) and CarList. Add (u, t)

Step – 11: w=w+1 and u=u+1 and go Step 5

Step – 12: else Step 7 is false, then go step10

Step – 13: else Step 5 is false, then print sorted Linked List

Step – 14: End

Algorithm for Selection sorting Method

Step – 1: Create the LinkedList CarList

Step – 2: Insert car numbers to LinkedList

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 67 | 82
Step – 3: Create variables s, t, u, v and w

Step – 4: u= 0, w=0, v=0

Step – 5: Checking if(w<6)

Step – 6: If Step 5 is true

Step – 7: Step 7 is true then s= CarList[u], t=CarList[v]

Step – 8: Checking if (t<s)

Step – 9: If Step 7 is true, then CarList. Remove(t) and CarList. Remove(s)

Step – 10: Then CarList. Add (u, t) and CarList. Add (v, s)

Step – 11: w=w+1, u=u+1, v=v+1 and go Step 5

Step – 12: Else Step 7 is false, then go step10

Step – 13: Else Step 5 is false, then print sorted Linked List

Step – 14: End

Insertion vs Selection
Table 2 Insertion vs Selection

Basis for comparison Insertion Sort Selection Sort

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 68 | 82
The data is sorted by inserting The
the data into an existing sorted data is sorted by selecting and
Basic
file. placing the consecutive
elements in sorted location.

Nature Stable Unstable

Process to be followed Elements are known Location is previously known


beforehand while location to while elements are searched.
place them is searched.

Immediate data Insertion sort is live sorting It cannot deal with immediate
technique which can deal with data; it needs to be present at
immediate data. the beginning.

Best case complexity O(n) O(n2)

Insertion sort works by inserting the set of values in the existing sorted file. It constructs the
sorted array by inserting a single element at a time. This process continues until whole array
is sorted in some order. The primary concept behind insertion sort is to insert each item into
its appropriate place in the final list. The insertion sort method saves an effective amount of
memory. The Selection sort perform sorting by searching for the minimum value number
and placing it into the first or last position according to the order (ascending or descending).
The process of searching the minimum key and placing it in the proper position is continued
until the all the elements are placed at right position.

The best-case complexity of insertion sort is O(n) times, i.e., when the array is previously
sorted. In the same way, when the array is sorted in reverse order, the first element of the
unsorted array is to be compared with each element in the sorted set. So, in the worst case,
running time of Insertion sort is quadratic, i.e., O(n2). In average case also it has to make the

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 69 | 82
minimum (k-1)/2 comparisons. Hence, the average case also has quadratic running time
O(n2).

As the working of selection, sort does not depend on the original order of the elements in the
array, so there is not much difference between best case and worst case complexity of
selection sort.The selection sort selects the minimum value element, in the selection process
all the ‘n’ number of elements are scanned; therefore n-1 comparisons are made in the first
pass. Then, the elements are interchanged. Similarly in the second pass also to find the
second smallest element we require scanning of rest n-1 elements and the process is
continued till the whole array sorted.

Among both of the sorting algorithm, the insertion sort is fast, efficient, stable while selection
sort only works efficiently when the small set of elements is involved or the list is partially
previously sorted. The number of comparisons made by selection sort is greater than the
movements performed whereas in insertion sort the number of times an element is moved or
swapped is greater than the comparisons made.

TASK 5

Asymptotic analysis

As we know that data structure is a way of organizing the data efficiently and that efficiency
is measured either in terms of time or space. So, the ideal data structure is a structure that
occupies the least possible time to perform all its operation and the memory space. Our focus

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 70 | 82
would be on finding the time complexity rather than space complexity, and by finding the
time complexity, we can decide which data structure is the best for an algorithm. The main
question arises in our mind that on what basis should we compare the time complexity of
data structures? The time complexity can be compared based on operations performed on
them. Let's consider a simple example. Suppose we have an array of 100 elements, and we
want to insert a new element at the beginning of the array. This becomes a very tedious task
as we first need to shift the elements towards the right, and we will add new element at the
starting of the array.

Suppose we consider the linked list as a data structure to add the element at the beginning.
The linked list contains two parts, i.e., data and address of the next node. We simply add the
address of the first node in the new node, and head pointer will now point to the newly added
node. Therefore, we conclude that adding the data at the beginning of the linked list is faster
than the arrays. In this way, we can compare the data structures and select the best possible
data structure for performing the operations.

Usually, the time required by an algorithm comes under three types:

Worst case: In this case, it defines the input for which the algorithm takes a huge time.

Average case: In this case, it takes average time for the program execution.

Best case: In this case, it defines the input for which the algorithm takes the lowest time

Asymptotic Notations (O)


Big oh Notation (O)

 Big O notation is an asymptotic notation that measures the performance of an


algorithm by simply providing the order of growth of the function.
 This notation provides an upper bound on a function which ensures that the function
never grows faster than the upper bound. So, it gives the least upper bound on a
function so that the function never grows faster than this upper bound.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 71 | 82
Figure 45 Big oh Notation (O)

Omega Notation (Ω)


 It basically describes the best-case scenario which is opposite to the big o notation.
 It is the formal way to represent the lower bound of an algorithm's running time. It
measures the best amount of time an algorithm can possibly take to complete or the
best-case time complexity.

Figure 46 Omega Notation (Ω)

Theta Notation (θ)


 The theta notation mainly describes the average case scenarios.
 It represents the realistic time complexity of an algorithm. Every time, an algorithm
does not perform worst or best, in real-world problems, algorithms mainly fluctuate
between the worst-case and best-case, and this gives us the average case of the
algorithm.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 72 | 82
Figure 47 Theta Notation (θ)

[ CITATION htt2189 \l 1033 ]

Analyzing the performance of a program

Performance analysis is the technique of studying or comparing the performance of a specific


situation in contrast to the aim and yet executed. In Human Resource, performance analysis
can help to review an employee’s contribution towards a project or assignment, which they
allotted him or her.

Importance of Performance Analysis

Importance-performance analysis (IPA) is an accepted method for measuring service quality


well known for its simplicity and stress-free application. Thus, IPA focuses on the gap
between the customer expectation on the importance and judgment on performing specific
attribute of service consumed.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 73 | 82
We distinguish three basic steps in the performance analysis process: data collection, data
transformation, and data visualization. Data collection is the process by which we get data
about program performance from an executing program. Data collected in a file, either
during or after execution, although in these situations it is presented to the user in real time.

Therefore, programmers always target for the average case.

Average performance of a program

Worst-case scenario and best-case execution times are used for totally unexpected purposes
in comparison to average-case execution. To advance programming, Average execution is
utilized. Average-case execution information is particularly applicable when it is recorded for
program units as opposed to the full program. Average-case conduct can be utilized to
recognize areas of interest brought about by awful algorithms, wrong codes, improper
guidance choice, or different variables.

Most cases, we aren't keen on the best situation since it happens only from time to time and is
regularly excessively hopeful for a significant evaluation of the algorithm's running term. To
put it another way, an examination focused on the best situation is probably not going to be
intelligent of the algorithm's 's conduct. There are, all things considered, a couple of events in
which a best-case analysis is fitting.

Most worst-case analysis may not be an agent proportion of the algorithm’s exhibition,
particularly when we need to total the expense of executing the program ordinarily on
numerous unmistakable data sources. We habitually wish to know the running time in the
worst-case outcome imaginable. This implies we'd prefer to know what the algorithm’s
average conduct is. To play out an Average case analysis, we should initially decide how the
program's real information sources are appropriated comparable to the arrangement of every
possible info.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 74 | 82
In the Average scenario, we take the Average of the amount of running occasions for all
possible information blends. The execution time fills in as both a lower and upper bound on
the algorithm’s transient intricacy in this situation.

To sum up, the lower a algorithm’s time complexity is, the quicker it will do the job
practically. When making or keeping up with algorithms, you should remember this, since it
can have a significant effect between a helpful calculation and one that is altogether useless.

What sort of trade-offs exists when using an ADT?

The best algorithm, hence best program to solve a given problem is one that requires less
space in memory and takes less time to execute its instruction or to generate output. But in
practice, it is not always possible to achieve both of these objectives. As said earlier, there
may be more than one approaches to solve a same problem. One such approach may require
more space but takes less time to complete its execution. Thus, we may have to sacrifice one
at the cost of the other. That is what we can say that there exists a time space trade off among
algorithms.
Therefore, if space is our constraints, then we have to choose a program that requires less
space at the cost of more execution time. Other than that, if time is our constraint, then we
have to choose a program that takes less time to complete its execution of statements at the
cost of more space.
In the analysis of algorithms, we are interested in the average case, the amount of time a
program might be expected to take on typical input data and in the worst case the total time
required by the program or the algorithm would take on the worst possible inputs of that
algorithm.
Types of Trade-offs
Lookup tables Vs Recalculation
An algorithm involving a lookup table is an implementation can include the entire table,
which reduces computing time, but increases the amount of memory needed, or it can

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 75 | 82
compute table entries as needed, increasing computing time, but reducing memory
requirements.
Compressed Vs Un compressed data
Problem of data storage can also be handling by using space and time tradeoff of algorithms.
If data is stored is not compressed, it takes more space but access takes less time than if the
data were stored compressed (since compressing the data reduces the amount of space it
takes, but it takes time to run the decompression algorithm). It is depending upon the
particular instance of the problem, either way is practical. There are also rare instances where
it is possible to directly work with compressed data, such as in the case of compressed
bitmap indices, where it is faster to work with compression than without compression.
Re Rendering Vs Stored images
In this case storing only the SVG source of a vector image and rendering it as a bitmap image
every time the page is requested would be trading time for space; more time used, but less
space. Rendering the image when the page is changed and storing the rendered images would
be trading space for time; more space used, but less time. This technique is more generally
known as caching.
Smaller code Vs loop unrolling
This technique is commonly used to makes the code longer for each iteration of a loop, but it
saves the computation time required for jumping back to the beginning of the loop at the end
of each iteration. Larger code size can be traded for higher program speed when applying
loop unrolling
Others types are:
 Add and store data
 Access data
 Remove data
 It works as specified
 It is easy to understand and modify
 It is reasonably efficient

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 76 | 82
 Implementations of ADTs can be changed (e.g., for efficiency) without requiring
changes to the program that uses the ADTs
 ADTs can be reused in future programs

Benefits of using independent data structures for implementation

programme?

Representation Independence
One purpose of type checking in programming languages is to guarantee a degree of
"representation independence:" programs should not depend on the way stacks are
represented, only on the behavior of stacks with respect to push and pop operations. In
languages with abstract data type declarations, representation independence should hold for
user-defined types as well as built-in types. We study the representation independence
properties of a typed functional language (second-order lambda calculus) with polymorphic
functions and abstract data type declarations in which data type implementations (packages)
may be passed as function parameters and returned as results.

Modularity
Basic rule for programming is that a routine should not ever exceed a page. This is achieved
by breaking the program down into modules. Each module is a logical unit and can perform a
specific job. ADTs can be viewed as a modular design.

Interchangeability of Parts
Varied implementations of an abstract data type may have different performance
characteristics. It becomes easier for each component of a program to utilize an
implementation of its data types that is more efficient for that part of the program using
abstract data types.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 77 | 82
Data structure that changes over time
As a dynamic data structure, a linked list can grow and shrink at runtime by allocating and
deallocating memory. As a result, there is no need to specify the linked list's initial size. With
regards to the scenario, if the participants of the event should be increased there won’t be any
issue when doing this.

Deletion and insertion


Insertion and deletion at the front or back of a linked list is a single operation.
Insertion and deletion in the middle may involve iterating forward or backward from the end
up to n-1 nodes, but it is generally more efficient than insertion and deletion into an array,
because you must shift all members to the right of the insertion forward, or to the left for a
deletion. For the scenario, it is required to delete a vehicle from any position, so the use of
linked lists have enabled this.

No Memory Wastage

In the Linked list, efficient memory utilization can be achieved since the size of the linked
list increase or decrease at run time so there is no memory wastage and there is no need to
pre-allocate the memory.

Implementation

Linear data structures like stack and queues are often easily implemented using a linked list.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 78 | 82
GANTT CHART

Figure 48 GANTT CHART

Grading Rubric

Grading Criteria Achieved Feedback

LO1. Examine abstract data types,


concrete data structures and
algorithms.

P1 Create a design specification for data

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 79 | 82
structures explaining the valid
operations that can be carried out on
the structures.

P2 Determine the operations of a


memory stack and how it is used to
implement function calls in a computer.

M1 Illustrate, with an example, a


concrete data structure for a First In
First out (FIFO) queue.

M2 Compare the performance of two


sorting algorithms.
D1 Analyse the operation, using
illustrations, of two network shortest
path algorithms, providing an example
of each.

LO2. Specify abstract data types and


algorithms in a formal notation.

P3 Using an imperative definition,


specify the abstract data type for a
software stack.

M3 Examine the advantages of


encapsulation and
details hiding when using an
ADT.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 80 | 82
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.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 81 | 82
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.

DATA STRUCTURE AND ALGORYTHEM


S.P. THILINA DHANANJAYA GUNASENA
KANA/013497 P a g e 82 | 82

You might also like