You are on page 1of 19

Author-Rajith Karunarathne

TASK 01

What is Data Structure?

A data structure is a specialized format for organizing, processing, retrieving and storing data. In
computer science and computer programming, a data structure may be selected or designed to
store data for the purpose of using it with various algorithms. In some cases, the algorithm's basic
operations are tightly coupled to the data structure's design. Each data structure contains details
about the data values, relationships between the data and -- in some cases -- functions that can be
applied to the data.

Types of data structures?

Stack Data Structure/Queue Data Structure/Linked List Data Structure


Explain these things

Briefly with pseudocode, algorithms etc.

Which data structure is most suitable for the above scenario?

The main functions are,

1.Register Car Details


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

ABC Pvt ltd organize a car event with 6 participants so they decide to build an application for that. In
that application basic method, the first thing is required to register car detail’s function is called first
in first out. That can be also used as a queue also it can’t be use as a queue because other function
cannot be use what mentioned in here. If we use LinkedList we can do it as we want. While we
entering data about car also, we can enter several car details at once. As example Enter the drivers
NIC number as string, but we have to enter his age as the integer. We have to enter different types

1|Page
Author-Rajith Karunarathne

of details at once then I recommended possible function is LinkedList Next function is Delete a car
from the application function. For that we can use all the three stacks, queues and LinkedList for our
need. While using stack function we can only delete last element of the given list. The reason
because it comes as First in last out or Last in First out theory and also queue cannot be used
because it common theory was First thing First out. That means we can delete what data in the first
in the list. So, we can LinkedList Function for this then we can easily manage what we want to do.

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

Task 2

Basic functions are,


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

Codes And Test Case for Register Car Details

Methods has been used,

•Add Method

• Addtolist Method

Add Method

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

2|Page
Author-Rajith Karunarathne

Addtolist Method

What I did utilizing this technique was to add details to this strategy utilizing the Add () method
above and afterward check in case it is feasible to enter the data in the linked list that coordinates
with the applicable car ID. In case there is no space in the linked list, the PC screen will re-yield that
the pertinent client cannot enter additional details into the system.

3|Page
Author-Rajith Karunarathne

4|Page
Author-Rajith Karunarathne

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

Test Case for Add Car details

Test Feature Add car


Testing Car Details Add
Inputs Car Id = C2
Brand = Mitsubishi

5|Page
Author-Rajith Karunarathne

Sponsor = ABC PVT LTD


Driver’s First Name = Thilina
Driver’s Last Name= Dhananjaya
Driver’s Age = 28
Expected Outcome Successfully add Car Details You Added Details
are: [C2, Mitsubishi, ABC PVT LTD , Thilina,
Dhananjaya,28]
Actual Outcome Successfully add Car Details You Added Details
are: [C2, Mitsubishi, ABC PVT LTD , Thilina,
Dhananjaya,28]
Tester Name Rajith Karunarathne 2021/10/11 20.23P.M
Test successful Yes/No Yes

Code for deleting a car

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

6|Page
Author-Rajith Karunarathne

7|Page
Author-Rajith Karunarathne

Test Case for Delete a car

Test Feature Deleting a Car


Testing Car Deleted
Inputs Car Id = C2
Expected Outcome Car deleted Successfully
Actual Outcome Car deleted Successfully
Tester Name Rajith Karunarathne 2021/10/11 20.23P.M
Test successful Yes/No Yes

Codes And Test Case for Search a Car Details

Code for Search a Car

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

8|Page
Author-Rajith Karunarathne

9|Page
Author-Rajith Karunarathne

Test Feature Search a Car


Testing Searching a car
Inputs Car Id = C1
Expected Outcome [C1, Mitsubishi Lancer, ABC PVT LTD, Thilina
Dhananjaya,28]
Actual Outcome [C1, Mitsubishi Lancer, ABC PVT LTD, Thilina
Dhananjaya,28]
Tester Name Rajith Karunarathne 2021/10/11 20.23P.M
Test successful Yes/No Yes

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 system. I then, at that point, planned
the system so that toward the finish of the last round the car ID s of the principal, second and third
spot finishers in the opposition could be shown on the PC screen by the client.

10 | P a g e
Author-Rajith Karunarathne

Test Case for Inserting 3 rounds results and finding the winners

Test Feature Start Race


Testing Selecting winners
Inputs Round 1 last car Id = C3
Round 2 last car Id = C1
Round 3 last car Id = C5
Expected Outcome Winners Are: [C2, C4, C6]
Actual Outcome Winners Are: [C2, C4, C6]
Tester Name Rajith Karunarathne 2021/10/11 20.23P.M
Test successful Yes/No Yes

11 | P a g e
Author-Rajith Karunarathne

Error Handling techniques used

There are several error handling techniques used in this regard and they are given below.

• Try

• Catch

• Finally

12 | P a g e
Author-Rajith Karunarathne

Test Case for error handling techniques

Test Feature Home


Testing Error Handling
Inputs A
Expected Outcome Warning...! You Can’t Enter Letters
Actual Outcome Warning...! You Can’t Enter Letters
Tester Name Rajith Karunarathne 2021/10/11 20.23P.M
Test successful Yes/No Yes

Task 3

What is the sorting?

Sorting refers to the operation or technique of arranging and rearranging sets of data in some
specific order.

Types of sorting techniques

Write these sorting techniques (Algorithms, pseudocodes, Operations etc)

Insertion sort/Merge Sort/Radix Sort/Shell Sort/Heap Sort/Selection sort/Bubble sort

13 | P a g e
Author-Rajith Karunarathne

Best sorting method for the above scenario

Thinking about the above situation, picking the most reasonable sorting method was extremely
hard. The reason for this is that when we register every car here, we used 6 separate LinkedList for
every car, one LinkedList for every car. Then, at that point, the dates on which these cars are enlisted
are entered independently in 6 LinkedList. Along these lines, when we sort this LinkedList 6, it is
unimaginable to expect to do everything simultaneously and we need to change this LinkedList 6 to
suit quite possibly the most well-known common sorting methods we can used. Thus, I changed this
LinkedList 6 to a collection sorting that permits you to enter any kind of information. Then, at that
point, I arranged the information of these 6 cars by the assortment sorting methods and with this
assortment sort I used the collection sorting method. The principal reason I used this collection
sorting method is that we need to sort this is a direct result of a tiny number of items like 6 articles.
Since utilizing this sorting method we can do this sort rapidly. That is, it doesn't take long to sort the
6 LinkedList used for sorting independently. Along these lines, the primary justification for utilizing
the choice sort for this sorting was that this sort could undoubtedly apply the pertinent arranging
rapidly. The fundamental justification for why this collection sorting is so appropriate to this
situation is that we need to sort a tiny measure of information in this situation. Also, when utilizing
this sorting method, we don't need to compose an extremely long measure of code so we can run
this system exceptionally quick in the PC when running. That is another justification for why I picked
collection sorting for this sorting. In any case, in the event that I used one more sorting method for
this, I will actually want to do this errand. However, I understood that other sorting method don't
make this sorting as quick and quick as the collection sorting. I likewise understood that in the event
that I used one more sorting method for this, it very well may be exceptionally adverse to the
running rate of the system because of their long code. Therefore, I decide that the collection sorting
is very suitable for this scenario. Below are the codes and test cases of the sorting method I created
for this system.

Why we are using ADT in java programming?

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

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 used to pass collections around

14 | P a g e
Author-Rajith Karunarathne

and manipulate them where maximum generality is desired. But if we do this using an ADT, we can
use a very limited number of variables and store the relevant data in a single variable until we get
the time we need.

What is the encapsulation?

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

Write Advantages of Encapsulations

What is the Data Hiding?

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


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

Write Advantages of data hiding

Is Encapsulation and Data hiding being advantage for above scenario?

Definitely, then discuss the valid justifications

What is the OOP?

Advantages of Object-Oriented Programming

What are the imperative Abstract Data types?

In the "imperative" view, which is closer to the philosophy of imperative programming languages, an
abstract data structure is conceived as an entity that is mutable — meaning that it may be in
different states at different times. Some operations may change the state of the ADT; therefore, the
order in which operations are evaluated is important, and the same operation on the same entities
may have different effects if executed at different times — just like the instructions of a computer,
or the commands and procedures of an imperative language.

Imperative ADTs are basis for object orientation

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


procedures are used to represent data and procedural interfaces provide information hiding and
abstraction. This technique is complementary to ADTs, in which concrete algebras are used to
represent data, and type abstraction provides information hiding. The two paradigms can be derived
from a fundamental dichotomy in decomposing a matrix of ob-servers and constructors that specify
abstract data.

15 | P a g e
Author-Rajith Karunarathne

Task 4

Algorithm used to find the shortest path

Dijkstra's algorithm solves the shortest-path problem for any weighted, directed graph with non-
negative weights. It can handle graphs consisting of cycles, but negative weights will cause this
algorithm to produce incorrect results. Consequently, we assume that w(e) ≥ 0 for all e ∈ E here.
Dijkstra’s algorithm requires a priority queue at each of N iterations, where N is the number of
network nodes.

Write the Algorithm

Graph to find the shortest path

Write the method of C1 (Start) to C3

Insertion vs Selection

Basis for comparison Insertion Sort Selection Sort


Basic The data is sorted by inserting The data is sorted by selecting
the data into an existing sorted and placing the consecutive
file. elements in sorted location
Nature Stable Unstable
Process to be followed It cannot deal with immediate Location is previously known
data; it needs to be present at while elements are searched
the beginning.
Immediate data Insertion sort is live sorting It cannot deal with immediate
technique which can deal with data; it needs to be present at
immediate data. the beginning.
Best case complexity O(n) O(n2 )

16 | P a g e
Author-Rajith Karunarathne

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.

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

✓ Worst case: In this case, it defines the input for which the algorithm takes a huge time.
✓ Average case: In this case, it takes average time for the program execution.
✓ Best case: In this case, it defines the input for which the algorithm takes the lowest time

Asymptotic Notations (O)

Big oh Notation (O)/ Omega Notation (Ω)/ Theta Notation (θ)

17 | P a g e
Author-Rajith Karunarathne

Big oh Notation (O)

Big O notation is an asymptotic notation that measures the performance of an algorithm by simply
providing the order of growth of the function.

Omega Notation (Ω)

It basically describes the best-case scenario which is opposite to the big o notation. It is the formal
way to represent the lower bound of an algorithm's running time.

Theta Notation (θ)

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

18 | P a g e
Author-Rajith Karunarathne

Analyzing the performance of a program

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


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

Importance of Performance Analysis

Importance-performance analysis (IPA) is an accepted method for measuring service quality well
known for its simplicity and stress-free application. Thus, IPA focuses on the gap between the
customer expectation on the importance and judgment on performing specific attribute of service
consumed.

Average performance of a program

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

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

The best algorithm, hence best program to solve a given problem is one that requires less space in
memory and takes less time to execute its instruction or to generate output. But in practice, it is not
always possible to achieve both of these objectives. As said earlier, there may be more than one
approaches to solve a same problem. One such approach may require more space but takes less
time to complete its execution. Thus, we may have to sacrifice one at the cost of the other. That is
what we can say that there exists a time space trade off among algorithms.

Compressed Vs Un compressed data

Problem of data storage can also be handling by using space and time tradeoff of algorithms. If data
is stored is not compressed, it takes more space but access takes less time than if the data were
stored compressed (since compressing the data reduces the amount of space it takes, but it takes
time to run the decompression algorithm).

Re Rendering Vs Stored images

In this case storing only the SVG source of a vector image and rendering it as a bitmap image every
time the page is requested would be trading time for space; more time used, but less space.
Rendering the image when the page is changed and storing the rendered images would be trading
space for time; more space used, but less time. This technique is more generally known as caching.

Benefits of using independent data structures for implementation

Write it

Representation Independence/ Modularity/ Interchangeability of Parts/ Data structure that changes


over time/ Deletion and insertion/ No Memory Wastage/ Implementation

19 | P a g e

You might also like