0% found this document useful (0 votes)
188 views

Unit 19 Dsa Assignment Reworded 2021

The document provides details of an internal verification of assessment decisions for a Higher National Diploma in Computing student. It includes the assessor and internal verifier names, the unit being assessed, assignment title, student name, which assessment criteria were awarded, and checklists to verify the accuracy and quality of assessment and feedback. The internal verifier confirmed the assessment decision did not need amending.

Uploaded by

Banuka Udayanga
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
188 views

Unit 19 Dsa Assignment Reworded 2021

The document provides details of an internal verification of assessment decisions for a Higher National Diploma in Computing student. It includes the assessor and internal verifier names, the unit being assessed, assignment title, student name, which assessment criteria were awarded, and checklists to verify the accuracy and quality of assessment and feedback. The internal verifier confirmed the assessment decision did not need amending.

Uploaded by

Banuka Udayanga
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Higher Nationals

Internal verification of assessment decisions – BTEC (RQF)

INTERNAL VERIFICATION – ASSESSMENT DECISIONS

Programme title Higher National Diploma in Computing

Assessor Internal Verifier


Unit 19 – Data Structures and Algorithms
Unit(s)

Assignment title Specification, Implementation, and Assessment of Data Structures for a sample
scenario.

H.A.H. Banuka Shantha Udayanga


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


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

Does the assessment decision need


Y/N
amending?

Assessor signature Date

Internal Verifier signature Date


Programme Leader signature (if required)
Date

1 Banuka Udayanga COL/E 011159


Confirm action completed
Remedial action taken

Give details:

Assessor signature Date

Internal Verifier
Date
signature

Programme Leader
Date
signature (if required)

Higher Nationals - Summative Assignment Feedback Form


Student Name/ID Banuka Udayanga COL/E 011159

2 Banuka Udayanga COL/E 011159


Unit Title Unit 19: Data Structures and Algorithms

Assignment Number 1 Assessor


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

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

Pass, Merit & P3 M3 D2


Distinction Descripts

LO3 Implement, Demonstrate and evaluate complex ADT algorithm.

Pass, Merit & P4 P5 M4 D3


Distinction Descripts

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

Grade: Assessor Signature: Date:


Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:
Signature & Date:
* Please note that grade decisions are provisional. They are only confirmed once internal and external moderation has taken place and
grades decisions have been agreed at the assessment board.

Assignment Feedback
Formative Feedback: Assessor to Student

3 Banuka Udayanga COL/E 011159


Action Plan

Summative feedback

Feedback: Student to Assessor

Assessor Date
signature

Student signature Date

Pearson Higher Nationals in

4 Banuka Udayanga COL/E 011159


Computing
Unit 19: Data Structures & Algorithms
Assignment 01

General Guidelines

• A Cover page or title page – You should always attach a title page to your assignment. Use
previous page as your cover sheet and make sure all the details are accurately filled.

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

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

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

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

Word Processing Rules

• The font size should be 12 point, and should be in the style of Time New Roman.
5 Banuka Udayanga COL/E 011159
• Use 1.5 line spacing. Left justify all paragraphs.

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

• Use footer function in the word processor to insert Your Name, Subject, Assignment No, and
Page Number on each page. This is useful if individual sheets become detached for any
reason.

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

Important Points:

• It is strictly prohibited to use textboxes to add texts in the assignments, except for the
compulsory information. eg: Figures, tables of comparison etc. Adding text boxes in the body
except for the before mentioned compulsory information will result in rejection of your work.

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

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

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

• You must take responsibility for managing your own time effectively.

• If you are unable to hand in your assignment on time and have valid reasons such as illness,
you may apply (in writing) for an extension.

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

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

• If you use other people’s work or ideas in your assignment, reference them properly using
HARVARD referencing system to avoid plagiarism. You have to provide both in-text citation
and a reference list.

• If you are proven to be guilty of plagiarism or any academic misconduct, your grade could be
reduced to A REFERRAL or at worst you could be expelled from the course

6 Banuka Udayanga COL/E 011159


Student Declaration

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

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


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

7 Banuka Udayanga COL/E 011159


Student’s Signature: Date: 23/04/2023
(Provide E-mail ID) (Provide Submission Date)

Higher National Diploma in Business


Assignment Brief
Student Name /ID Number Banuka Udayanga COL/E 011159
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 23/04/2023
IV Name & Date

Submission format

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

Unit Learning Outcomes:


8 Banuka Udayanga COL/E 011159
LO1. Examine abstract data types, concrete data structures and algorithms.
LO2. Specify abstract data types and algorithms in a formal notation.
LO3. Implement complex data structures and algorithms.
LO4. Assess the effectiveness of data structures and algorithms.

Assignment Brief and Guidance:


Scenario
ABC Pvt Ltd organizing Car Racing event across western province and they decided to have
maximum of 6 cars(participants) to compete.
There are totally 3 Rounds and at the end of each round lowest rank car will be eliminated
from the Race.
Each car has unique number, brand, sponsor and driver details.

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

1.Register Car Details


2.Delete a car
3.Insert 3 Rounds Results.

9 Banuka Udayanga COL/E 011159


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

Task 1: Examine and create data structure by simulating the above scenario and explain
the valid operations that can be carried out on this data structure.
Determine the operations of a queue and critically review how it is used to implement
function calls related to the above scenario.

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

Task 3 : Registered Car details are stored from oldest to newest. Management of ABC Pvt
Ltd should be able to find from the newest to oldest registered car details. Using an
imperative definition, specify the abstract data type for the above scenario and
implement specified ADT using java programming and briefly discuss the complexity of
chosen ADT algorithm. List down the advantages of Encapsulation and Information hiding
when using an ADT selected for the above scenario.
“Imperative ADTs are basis for object orientation.” Discuss the above view stating
whether you agree or not. Justify your answer.

Task 4: ABC Pvt Ltd plans to visit all of these participants through the shortest path within
a day.

10 Banuka Udayanga COL/E 011159


Analyse the above operation by using illustrations, of two shortest path algorithms,
specify how it operates using a sample graph diagram. Sort the cars based on numbers
with two different sorting algorithms and critically review the performances of those two
algorithms by comparing them.

Task 5: Evaluate how Asymptotic analysis can be used to assess the effectiveness of an
algorithm and critically evaluate the different ways in which the efficiency of an algorithm
can be measured.
Critically review the sort of trade-offs exists when you use an ADT for implementing
programs. You also need to evaluate the benefits of using independent data structures
for implementing programs.

Grading Rubric

Grading Criteria Achieved Feedback

LO1. Examine abstract data types,


concrete data structures and algorithms.
11 Banuka Udayanga COL/E 011159
P1 Create a design specification for data
structures explaining the valid operations
that can be carried out on the structures.

P2 Determine the operations of a memory


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

M1 Illustrate, with an example, a concrete


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

M2 Compare the performance of two


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

LO2. Specify abstract data types and


algorithms in a formal notation.

P3 Using an imperative definition, specify


the abstract data type for a software
stack.

M3 Examine the advantages of


encapsulation and
information hiding when using an ADT.

12 Banuka Udayanga COL/E 011159


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.

13 Banuka Udayanga COL/E 011159


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.

14 Banuka Udayanga COL/E 011159


Acknowledgment

Special Thanks

I am really grateful because I managed to complete my DSA assignment. I respect and thank our
HND DSA lecturer for giving we an opportunity to do this assignment work and providing us all
support and guidance which made me complete the assignment on time, we extremely grateful to him
for providing such a nice support and guidance.
Another big thanks to Esoft Metro Campus for this learning opportunities. I had a good time at class
in Esoft with many learning resources.

15 Banuka Udayanga COL/E 011159


Table of Contents
Acknowledgment .................................................................................................................................. 15
Special Thanks ...................................................................................................................................... 15
Task 01 .................................................................................................................................................. 18
Examine and create data structure by simulating the above scenario and explain the valid operations
that can be carried out on this data structure. ........................................................................................ 18
Register Car Details .......................................................................................................................... 19
Delete a Car....................................................................................................................................... 19
Insert 3 Rounds Result ...................................................................................................................... 19
Find out the Winners......................................................................................................................... 19
Search for a particular car ................................................................................................................. 20
Determine the operations of a queue and critically review how it is used to implement function calls
related to the above scenario ................................................................................................................. 20
What is Queue Data Structure? ............................................................................................................. 20
FIFO Principle of Queue:.................................................................................................................. 20
Characteristics of Queue: .................................................................................................................. 20
Task 02 .................................................................................................................................................. 22
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. .................................................................... 22
Use suitable error handling where appropriate. Test the application using suitable test cases and
illustrate the system. Provide evidence of the test cases and the test results ........................................ 23
Register Car Details .......................................................................................................................... 23
Delete a Car....................................................................................................................................... 24
Insert 3 Round Results ...................................................................................................................... 24
Task 03 .................................................................................................................................................. 29
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. ................................................................... 29
Abstract Data Types .............................................................................................................................. 29
List ADT ........................................................................................................................................... 29
Stack ADT ........................................................................................................................................ 29
Queue ADT ....................................................................................................................................... 30
Imperative Definition ............................................................................................................................ 30
16 Banuka Udayanga COL/E 011159
Java Implementation ......................................................................................................................... 31
Explanation ....................................................................................................................................... 31
List down the advantages of Encapsulation and Information hiding when using an ADT selected for
the above scenario. ................................................................................................................................ 32
What is encapsulation? ..................................................................................................................... 32
Task 04 .................................................................................................................................................. 33
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. .......................................................................................................................... 33
Dijkstra's Algorithm .......................................................................................................................... 33
Bellman-Ford Algorithm .................................................................................................................. 34
Sort the cars based on numbers with two different sorting algorithms and critically review the
performances of those two algorithms by comparing them. ................................................................. 34
Task 05 .................................................................................................................................................. 35
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. ........ 35
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. . 36
Reference .............................................................................................................................................. 38

17 Banuka Udayanga COL/E 011159


Task 01

Examine and create data structure by simulating the above scenario and explain the
valid operations that can be carried out on this data structure.

We can build a data structure to hold each round's results and automobile information. An example of
this data structure's implementation is a list of dictionaries, where each dictionary contains the
specifics of one car. Here is an example of how to define this data structure in Python:

Each dictionary in this data structure represents a single car and has four key-value pairs: "number"
(which serves as the car's unique identity), "brand," "sponsor," and "driver" (the name of the driver).
Create a separate list to keep track of the results of each round.

18 Banuka Udayanga COL/E 011159


Each inner list in this data structure represents the outcomes of a particular round. The unique
identifiers ("number") of the cars in the "cars" list are represented by the numbers in each list.
The following features that ABC Pvt Ltd needs for their application can be implemented with the help
of this data structure:

Register Car Details


One can add a new dictionary with the proper key-value pairs to the "cars" list in order to register a
newer car.

Delete a Car
So can use a car's index to remove the matching dictionary from the list of "cars" in order to delete it.
For instance, to remove the second vehicle from the list:

Insert 3 Rounds Result


We can add a new list to the "results" list in order to insert the results of a new round. For example,
below are the results of a fresh round when the cars came in at positions [2, 1, 3, 5, 4, 6]:

Find out the Winners


The "results" list can be sorted according to the results of the final round, and the top three cars can
then be extracted to determine the race winners (i.e., the ones with the lowest index values in the
sorted list).

19 Banuka Udayanga COL/E 011159


Search for a particular car
To search for a particular car, we can loop through the "cars" list

Determine the operations of a queue and critically review how it is used to implement
function calls related to the above scenario

What is Queue Data Structure?


A queue is described as a linear data structure with open ends and FIFO (First In, First Out) execution
of operations. Describe a queue as a list in which all new items are added at one end and all items are
removed from the list at the other. The operation is started on the element that is pushed into the order
first. (geeksforgeeks.org)

FIFO Principle of Queue:

• The first person in a queue gets served first, just like in a line waiting to buy tickets. (First
come, first served, etc.).
• The position of the last entry in the queue, that is, the one that was most recently added, is
known as the rear (or tail) of the queue. Similarly, the position of the entry in a queue ready to
be served, that is, the first entry that will be removed from the queue, is referred to as the
front of the queue (sometimes, head of the queue). View the image below.

Characteristics of Queue:

• Many data can be handled using queue.


• Both ends are accessible to us.
• They move quickly and easily.

20 Banuka Udayanga COL/E 011159


A queue supports the following operations:
1. Enqueue: Place an element at the end of the queue.
2. Dequeue: Take the item at the head of the line and give it back.
3. Front: Without removing it, return the element that is at the front of the queue.
4. Rear: Bring back the element at the end of the line without taking it away.
5. If the queue is empty, check this box.
6. Size: Provide the queue's element count.

A queue can be utilized to implement function calls relevant to the rounds of the car racing
competition in the scenario mentioned above. To store the list of cars that are still in the race after
each round, we can utilize a queue. Here is how it would operate:

• We can start a queue at the beginning of the race with all of the cars registered.

• The car with the lowest rank (i.e., the one that was disqualified from the race) can be
dequeued following each round, and the remaining cars can then be requeued. The round's
outcomes can also be kept in a separate data structure.

• The cars still in the queue when all rounds are finished are declared the winners.

Using a queue to implement this functionality has several advantages. First, it ensures that the cars are
removed from the race in the correct order (i.e., the car with the lowest rank is removed first). Second,
it allows us to easily keep track of the remaining cars after each round, as we can simply enqueue the
remaining cars back into the queue. Third, it simplifies the code required to manage the state of the
race, as we can rely on the built-in operations of the queue to handle the enqueue and dequeue
operations.
Overall, a queue is a good data structure for implementing the function calls linked to the automobile
racing event scenario since it enables us to control the race's status and select the winners quickly. It's
crucial to remember that not every situation will call for a queue. For instance, a queue might not be
the most effective data structure to utilize if we needed to access the automobiles in the center of the
queue (rather than just the front or back). In some circumstances, an alternative data structure (such a
linked list) could be preferable.

21 Banuka Udayanga COL/E 011159


Task 02

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.

Here's the implementation of the above scenario using the Queue data structure in Java:

22 Banuka Udayanga COL/E 011159


Use suitable error handling where appropriate. Test the application using suitable test
cases and illustrate the system. Provide evidence of the test cases and the test results

Register Car Details


Test Case 1 Register 6 cars successfully

Input register Car ("123", "Ford", "ABC Company",


"Nimal")
register Car ("456", "Toyota", "XYZ Company",
"Janidu")
register Car ("789", "Chevrolet", "PQR
Company", "Kamal")
register Car ("321", "Nissan", "LMN
Company", "Sunil")
register Car ("654", "Honda", "DEF Company",
"Perera")
register Car ("987", "Hyundai", "GHI
Company", "Saman")
Output 6 cars registered successfully

23 Banuka Udayanga COL/E 011159


Test Case 2 Register More than 6 Cars

Input register Car ("123", "Ford", "ABC Company",


"Nimal")
register Car ("456", "Toyota", "XYZ Company",
"Janidu")
register Car ("789", "Chevrolet", "PQR
Company", "Kamal")
register Car ("321", "Nissan", "LMN
Company", "Sunil")
register Car ("654", "Honda", "DEF Company",
"Perera")
register Car ("987", "Hyundai", "GHI
Company", "Saman")
register Car (“101112,” BMW”,” UVW
Company”, “Ruwan”)
Output No more than 6 cars may be registered for the
race.

Delete a Car

Test Case 1 Delete a Car Successfully

Input deleteCar()

Output Removed car: Car Number: 123, Brand: Ford,


Sponsor: ABC Company, Driver: Nimal

Test Case 2 Delete a car when no cars are registered

Input deleteCar()

Output No Cars to remove

Insert 3 Round Results

Test Case 1 Insert results for Round 1 successfully

24 Banuka Udayanga COL/E 011159


Input insertRoundResults(1)

Output Results for Round 1 inserted successfully

Test Case 2 Insert results for Round 2 successfully

Input insertRoundResults(2)

Output Results for Round 2 inserted successfully

Test Case 3 Insert results for Round 3 successfully Then


select the winner
Input insertRoundResults (3)

Output Car winner = carQueue.peek();

Car winner = carQueue.peek();


System.out.println("Winner of the race: " + winner.toString());
deleteCar();
Car secondPlace = carQueue.peek();
System.out.println("Second place: " + secondPlace.toString());
deleteCar();
Car thirdPlace = carQueue.peek();
System.out.println("Third place: " + thirdPlace.toString());
Output: Results for Round 3 inserted successfully
Winner of the race: Car Number: 654, Brand: Honda, Sponsor: DEF Company, Driver: Perera
Removed car: Car Number: 654, Brand: Honda, Sponsor: DEF Company, Driver: Perera
Second place: Car Number: 456, Brand: Toyota, Sponsor: XYZ Company, Driver: Janidu
Removed car: Car Number: 456, Brand: Toyota, Sponsor: XYZ Company, Driver: Janidu
Third place: Car Number: 123, Brand: Ford, Sponsor: ABC Company, Driver: Nimal
Removed car: Car Number: 123, Brand: Ford, Sponsor: ABC Company, Driver: Nimal

25 Banuka Udayanga COL/E 011159


This is the implementation for the Car Racing Event application, along with appropriate error
handling and test cases:

26 Banuka Udayanga COL/E 011159


27 Banuka Udayanga COL/E 011159
28 Banuka Udayanga COL/E 011159
Task 03

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.

Abstract Data Types


An object's behavior can be described by a set of values and a set of actions, and this behavior is
known as an abstract data type (ADT). The definition of ADT merely specifies the actions that must
be taken, not how they must be carried out. It is unclear what algorithms will be utilized to carry out
the operations and how the data will be structured in memory. Because it provides an implementation-
independent view, it is dubbed "abstract." (geeksforgeeks.org)
Three ADTs exist, including:

List ADT
A list with a head structure made up of a count, pointers, and the address of the comparison function
needed to compare the data in the list typically stores the data in key sequence.
The data node has a self-referential pointer that links to the next node in the list as well as a pointer to
a data structure.
get() – Return an element from the list at any given position.
insert() – Insert an element at any position of the list.
remove() – Remove the first occurrence of any element from a non-empty list.
removeAt() – Remove the element at a specified location from a non-empty list.
replace() – Replace an element at any position by another element.
size() – Return the number of elements in the list.
isEmpty() – Return true if the list is empty, otherwise return false.
isFull() – Return true if the list is full, otherwise return false.

Stack ADT
Instead of storing data in each node, the Stack ADT Implementation stores a pointer to the data.
The software allots memory for the data, and the stack ADT receives the address.
The ADT contains both the head node and the data nodes. The only thing the calling function can see
is the stack pointer.
29 Banuka Udayanga COL/E 011159
A pointer to the top and a count of how many elements are currently in the stack are also included in
the stack head structure.
push() – Insert an element at one end of the stack called top.
pop() – Remove and return the element at the top of the stack, if it is not empty.
peek() – Return the element at the top of the stack without removing it, if the stack is not empty.
size() – Return the number of elements in the stack.
isEmpty() – Return true if the stack is empty, otherwise return false.
isFull() – Return true if the stack is full, otherwise return false.

Queue ADT
The stack abstract data type's basic design is followed by the queue abstract data type (ADT).
Each node has a link pointer to the subsequent element in the queue and a void pointer to the data. It
is the duty of the software to allot memory for storing the data.
enqueue() – Insert an element at the end of the queue.
dequeue() – Remove and return the first element of the queue, if the queue is not empty.
peek() – Return the element of the queue without removing it, if the queue is not empty.
size() – Return the number of elements in the queue.
isEmpty() – Return true if the queue is empty, otherwise return false.
isFull() – Return true if the queue is full, otherwise return false.

Imperative Definition
need to create an abstract data type that allows the management of ABC Pvt Ltd to store registered car
details and retrieve them in reverse chronological order, i.e., from newest to oldest.
Name: CarRegistry

Operations:

addCarDetails(carDetails: CarDetails) -> void: Adds a new carDetails object to the registry.
getNewestCarDetails() -> CarDetails: Retrieves the details of the newest car registered.

30 Banuka Udayanga COL/E 011159


getOldestCarDetails() -> CarDetails: Retrieves the details of the oldest car registered.

Java Implementation

Explanation
a LinkedList data structure was used to construct the CarRegistry ADT in Java. Because it makes it
simple to add new elements at the start of the list and to get entries at the beginning and end of the list,
the LinkedList offers a practical solution for our needs.
defined three operations for our CarRegistry ADT - addCarDetails, getNewestCarDetails, and
getOldestCarDetails. The addCarDetails operation adds a new CarDetails object to the registry by
inserting it at the beginning of the list. The getNewestCarDetails operation retrieves the details of the
newest car registered, which is the first element of the list. The getOldestCarDetails operation
retrieves the details of the oldest car registered, which is the last element of the list.
The time complexity of adding a new CarDetails object to the registry using addCarDetails is O(1)
since it simply involves inserting the element at the beginning of the list. The time complexity of
retrieving the newest and oldest car details using getNewestCarDetails and getOldestCarDetails is
also O(1) since these operations simply involve accessing the first and last elements of the list,

31 Banuka Udayanga COL/E 011159


respectively. Therefore, the overall time complexity of our implementation is O(1) for all operations,
which makes it efficient and suitable for the given requirements.

List down the advantages of Encapsulation and Information hiding when using an ADT
selected for the above scenario.

What is encapsulation?
Encapsulation is a technique for preventing direct user access to some object components, preventing
users from seeing the state values for all of an object's variables. Data members and data functions or
methods connected to an instantiated class or object can both be concealed using encapsulation.
(sumologic.com)
Encapsulation and information hiding in the above scenario can provide multiple advantages when
utilizing the CarRegistry ADT, such as:

• Data protection: By encapsulating the CarRegistry ADT, we are able to hide its
implementation details from consumers while only exposing those interfaces that are
absolutely necessary. This aids in preventing illegal access to or modification of the data.

• Flexibility and maintainability: By encapsulating the CarRegistry ADT's data and behavior,
we can change the underlying implementation without impairing the ADT's users. This
enhances the codebase's flexibility and maintainability.

• Enhanced modularity: Information hiding and encapsulation can aid in dividing a complex
system into smaller, easier-to-manage parts. We can separate the concerns of other modules
and make the software more modular by hiding the CarRegistry ADT's internal features.

• Improved readability of the code: By utilizing encapsulation and information hiding, we


can clearly separate the various concerns and make the codebase easier to read and
comprehend. As a result, the code may become less complex and may be simpler to maintain
and debug.

• Reduced coupling: Encapsulation and information hiding can aid in decreasing the coupling
between various system components. We may decrease the dependencies between various
pieces of the code and increase the system's loose coupling by hiding the CarRegistry ADT's
internal features.

Encapsulation and information hiding are fundamental ideas in software engineering that can assist
develop codebases that are more resilient, modular, and maintainable. Encapsulation and information
hiding can increase data protection, flexibility, maintainability, modularity, code readability, and
reduced coupling when used with an ADT like the CarRegistry.
32 Banuka Udayanga COL/E 011159
Task 04

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.

Graph algorithms can be used to examine the process of determining the shortest path to visit every
participant within a day. The Dijkstra algorithm and the Bellman-Ford algorithm are two popular
methods for determining the shortest path in a graph.

Dijkstra's Algorithm
In a weighted network, the shortest path from a source node to all other nodes is determined using the
widely used Dijkstra's algorithm. The method visits the nodes in order of increasing distance from the
source node using a priority queue, updating the distances of nearby nodes if a shorter path is
discovered.

• With a distance of 0, begin at node A.


• In order to update the distances to 2 and 1, respectively, travel to the nearby nodes B and C.
• visit the following node with the smallest distance, which is node C, after adding nodes B and
C to the priority queue.
• travel to node A nearby, where update the distance to 2 + 1 = 3.
• Next, after visiting the subsequent node with the smallest distance, node B, move node A up
the priority queue.
• The distances between the neighboring nodes A, D, and E are updated to 3 + 2 = 5, 2 + 2 = 4,
and 2 + 4 = 6, respectively.
• Visit the following node with the smallest distance, which is node D, after adding nodes D
and E to the priority queue.
• Update the distances between the neighboring nodes B and E to 4 + 2 = 6 and 4 + 4 = 8,
respectively.

33 Banuka Udayanga COL/E 011159


• Visit the following node with the smallest distance, which is node B, and add node E to the
priority queue.
• update the distance to 6 + 2 = 8 by traveling to the neighboring node A.
• Place node A in the priority queue and proceed to node E, which is the next node in line in
terms of distance.
• Update the distances between the neighboring nodes B and D to 8 + 4 = 12 and 4 + 2 = 6,
respectively.
• visit node D, the last node with the smallest distance, after moving node B up the priority
queue.

Bellman-Ford Algorithm
Another well-known graph algorithm for locating the shortest route between a source node and every
other node in a weighted graph is the Bellman-Ford algorithm. The algorithm reduces the distance
estimate of each node until convergence is obtained by iteratively relaxing the graph's edges.

Sort the cars based on numbers with two different sorting algorithms and critically
review the performances of those two algorithms by comparing them.

We must give the numbers by which we are sorting in order to order the cars numerically. Assume for
the moment that we are classifying the vehicles according to their strings-based registration numbers.
QuickSort: This algorithm divides an array into two sub-arrays, one of which contains elements
smaller than a selected pivot element and the other of which contains elements greater than the pivot.
The two sub-arrays are then sorted repeatedly by the method.
MergeSort: This is a variation on the divide-and-conquer strategy that divides an array into two equal
parts, sorts each half iteratively, and then merges the two sorted halves.

34 Banuka Udayanga COL/E 011159


Task 05

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.

A mathematical method called asymptotic analysis is used to assess an algorithm's effectiveness in


terms of its time and space complexity. It entails examining the relationship between the input size
and the runtime or memory utilization of the method. Asymptotic analysis offers a mechanism to
compare algorithm performance regardless of the particular hardware or software environment in
which it is implemented, making it a useful tool for evaluating an algorithm's efficacy.
35 Banuka Udayanga COL/E 011159
Time complexity and spatial complexity are the two metrics for algorithm efficiency that are most
frequently utilized. While space complexity measures how an algorithm's memory use expands with
the amount of the input, time complexity measures how an algorithm's runtime grows with the size of
the input.
The effectiveness of an algorithm can be evaluated in a variety of ways, including:

• Big-O notation: Big-O notation is a common notation for expressing the maximum runtime or
memory requirements of an algorithm as the size of the input increases. For instance, the
runtime of an algorithm with an O(n) runtime increases exponentially as the size of the input.
• The lower bound of an algorithm's runtime or memory requirements as the size of the input
increases is expressed using the omega notation. For instance, the runtime of an algorithm
with a runtime of (n) increases at least linearly as the size of the input.
• The tight bound of an algorithm's runtime or memory use as the size of the input increases is
expressed using theta notation. An algorithm with a runtime of n, for instance, has a runtime
that increases linearly with input size but is not faster.
• Worst-case analysis: Worst-case analysis gauges how much memory or runtime an algorithm
will consume given the worst-case scenario. This gives the algorithm's performance an upper
bound.
• Average-case analysis: This technique calculates the average runtime or memory
consumption of an algorithm over all feasible inputs of a specific size. Compared to worst-
case analysis, this offers a more accurate indication of the algorithm's performance but may
be more challenging to calculate.
• Amortized analysis: Rather of calculating the cost of a single operation on an algorithm,
amortized analysis calculates the average cost of a series of operations. This can be helpful
for algorithms whose regular operations are inexpensive but occasionally involve expensive
operations.

To sum up, asymptotic analysis is an effective method for assessing an algorithm's effectiveness in
terms of both time and space complexity. The Big-O, Omega, and Theta notations, worst-case
analysis, average-case analysis, and amortized analysis are a few distinct techniques to gauge
algorithm efficiency. The choice of measure depends on the particular application and needs of the
algorithm, and each of these metrics has strengths and limitations.

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.

A fundamental idea in computer science called Abstract Data Types (ADTs) enables programmers to
group together related functions and data structures into reusable modules. However, there are
compromises to take into account while employing an ADT to carry out programs.

36 Banuka Udayanga COL/E 011159


The trade-off between abstraction and efficiency is one of the key trade-offs. ADTs offer a high level
of abstraction, which makes writing and comprehending programs easier. This abstraction
compromises efficiency, though, as the ADT might carry out more operations in order to produce the
intended outcome.
The trade-off between simplicity and versatility is another compromise. ADTs are made to be
adaptable so they can be utilized in a variety of applications. The ADT may be more sophisticated
than necessary for a given application therefore this flexibility comes at the expense of simplicity.
The trade-off between implementation and maintenance is the last factor. ADTs demand more work
during implementation than straightforward data structures. ADTs offer a standardized interface that
is independent of the implementation specifics, which can minimize the maintenance burden after
implementation.
However, there are advantages to adopting separate data structures for putting programs into action.
Independent data structures offer a more straightforward and effective way to carry out particular
tasks. They frequently are adapted to the particular needs of the application, leading to a more
effective implementation. Independent data structures are more flexible since they may be improved
and changed without affecting the rest of the application.
Additionally, independent data structures may be simpler to comprehend and keep up with than
ADTs. Their implementation details are frequently simpler since they are suited to the particular
requirements of the application, making them simpler to maintain. Additionally, since independent
data structures are tailored for particular processes, they may be more effective than ADTs in some
situations.

Conclusion: When utilizing an ADT to implement programs, there are trade-offs to take into account.
These include the trade-offs between abstraction and efficiency, flexibility and simplicity, and
implementation and maintenance. Independent data structures, however, can offer advantages
including simplicity, efficiency, and ease of maintenance. The precise requirements of the application

37 Banuka Udayanga COL/E 011159


and the trade-offs the programmer is willing to make determine whether an ADT or an independent
data structure should be used.

Reference

What is Queue Data Structure?


https://www.geeksforgeeks.org/queue-data-structure/

FIFO Principle of Queue:


https://www.geeksforgeeks.org/queue-data-structure/

Characteristics of Queue:
https://www.geeksforgeeks.org/queue-data-structure/

Abstract Data Types


https://www.geeksforgeeks.org/abstract-data-types/

What is encapsulation?
https://www.sumologic.com/glossary/encapsulation/

Bellman-Ford Algorithm
https://www.programiz.com/dsa/bellman-ford-algorithm

Dijkstra's Algorithm
https://www.programiz.com/dsa/dijkstra-algorithm

38 Banuka Udayanga COL/E 011159

You might also like