ABC Same Code
ABC Same Code
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.
Give details:
Programme Leader
signature (if required) Date
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.
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
Action Plan
Summative feedback
Assessor Date
signature
Student Date
signature
• A Cover page or title page – You should always attach a title page to your
assignment. Use previous page as your cover sheet and make sure all the details are
accurately filled.
• All the assignments should be printed on A4 sized papers. Use single side printing.
• Allow 1” for top, bottom , right margins and 1.25” for the left margin of each page.
• The font size should be 12 point, and should be in the style of Time New Roman.
• Ensure that all the headings are consistent in terms of the font size and font style.
• Use footer function in the word processor to insert Your Name, Subject,
Assignment No, and Page Number on each page. This is useful if individual sheets
become detached for any reason.
• Use word processing application spell check and grammar check function to help
editing your assignment.
Important Points:
• It is strictly prohibited to use textboxes to add texts in the assignments, except for
the compulsory 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.
• 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.
• 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.
[email protected] 2021/10/09
Student’s Signature: Date:
(Provide E-mail ID) (Provide Submission Date)
Submission format
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 01__________________________________________________________________18
How fits Linked List Data Structure for the Given Scenario_____________________________________________21
TASK 2____________________________________________________________________24
Add Method__________________________________________________________________________________25
Addtolist Method_____________________________________________________________________________26
Test Case for Add Car details___________________________________________________________________30
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
Advantages of Encapsulation:____________________________________________________________________60
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
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 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.
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.
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.
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.
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.
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.
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
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.
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 12 Linked List for Add car Ids for Car race
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
Figure 23 Test Case for Insert 3 Rounds Results and Find out the winners
Try
Catch
Finally
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.
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.
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 ]
Algorithm
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.
Merge sort can be done in two types both having similar logic and way of implementation.
These are:
Top-down implementation
Bottom-up implementation
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.
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.
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.
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 ]
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.
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
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
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.
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.
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
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 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
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.
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
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.
Task 4
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.
Figure 44 Graph
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.
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
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.
Step – 4: u= 0, w=0
Step – 10: if Step 7 is true, then CarList. Remove(t) and CarList. Add (u, t)
Step – 13: else Step 5 is false, then print sorted Linked List
Step – 10: Then CarList. Add (u, t) and CarList. Add (v, s)
Step – 13: Else Step 5 is false, then print sorted Linked List
Insertion vs Selection
Table 2 Insertion vs Selection
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.
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
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
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.
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
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.
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.
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
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.
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.
Grading Rubric