Unit 19 Dsa Assignment Reworded 2021
Unit 19 Dsa Assignment Reworded 2021
Assignment title Specification, Implementation, and Assessment of Data Structures for a sample
scenario.
Give details:
Internal Verifier
Date
signature
Programme Leader
Date
signature (if required)
LO2 Discuss the advantages, complexity of Abstract Data Type and importance concepts of
Object orientation.
LO4 Examine the advantages of Independent data structures and discuss the need of
asymptotic analysis to assess the effectiveness of an algorithm.
Pass, Merit & P6 P7 M5 D4
Distinction Descripts
Assignment Feedback
Formative Feedback: Assessor to Student
Summative feedback
Assessor Date
signature
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.
• All the assignments should be printed on A4 sized papers. Use single side printing.
• Allow 1” for top, bottom , right margins and 1.25” for the left margin of each page.
• The font size should be 12 point, and should be in the style of Time New Roman.
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.
• 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
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.
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.
In order to manage this particular event ABC Pvt Ltd decided to develop an Application.
Application functions are listed down.
Task 1: Examine and create data structure by simulating the above scenario and explain
the valid operations that can be carried out on this data structure.
Determine the operations of a queue and critically review how it is used to implement
function calls related to the above scenario.
Task 2: Implement the above scenario using the selected data structure and its valid
operations for the design specification given in task 1 by using java programming. Use
suitable error handling and Test the application using suitable test cases and illustrate the
system. Provide evidence of the test cases and the test results.
Task 3 : Registered Car details are stored from oldest to newest. Management of ABC Pvt
Ltd should be able to find from the newest to oldest registered car details. Using an
imperative definition, specify the abstract data type for the above scenario and
implement specified ADT using java programming and briefly discuss the complexity of
chosen ADT algorithm. List down the advantages of Encapsulation and Information hiding
when using an ADT selected for the above scenario.
“Imperative ADTs are basis for object orientation.” Discuss the above view stating
whether you agree or not. Justify your answer.
Task 4: ABC Pvt Ltd plans to visit all of these participants through the shortest path within
a day.
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
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.
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.
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:
Determine the operations of a queue and critically review how it is used to implement
function calls related to the above scenario
• 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:
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.
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:
Delete a Car
Input deleteCar()
Input deleteCar()
Input insertRoundResults(2)
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 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.
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,
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.
• 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.
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.
• 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.
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
Reference
Characteristics of Queue:
https://www.geeksforgeeks.org/queue-data-structure/
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