DSA Assignment
DSA Assignment
SOFTWARE ENGINEERING
Acknowledgement
I’m really grateful because I managed to complete my Data Structures & Algorithms
within the time given by my lecture Praveena this assignment can’t be completed without
the assistance and the support of my lecture. I would like to thank my lecture for the
guidance and encouragement given, and also for teaching us in this course. Finally, I
would like to express my gratitude to my friends and respondents for the support and
willingness to spend some time with me to full fill my assignment.
Introduction
Data structures are a programmatic way of storing data so that data can be used
effectively. Almost every enterprise application uses different types of data structures in
one way or another.
The algorithm is often combined with terms that refer to the function in which the set of
rules is designed. A search algorithm, for example, is a process of determining what kind
of information is retrieved from a large amount of data. An encryption method is a set of
rules that encrypts information or messages so that unauthorized persons cannot read
them.
TASK 01
1. Abstract data types
Abstract data types (ADT) is a kind (or class) of object whose behavior is
specified by a set of values and a set of operations. The definition of ADT merely
says what operations must be completed, not how these operations will be carried
out. It does not specify how data will be stored in memory or which algorithms
will be utilized to carry out the actions. It is named "abstract" because it provides
a view that is independent of implementation.
2. Data structure
A data structure is a method of organizing data so that it may be used efficiently.
1. Mathematical/ Logical/ Abstract models/ Views: A data structure is a method of
organizing data that necessitates the use of protocols or rules. These rules, which
fall under the logical/abstract model, must be modeled.
2. The second section is the implementation section. The rules must be written in a
computer language.
Why data structure?
1. These are the necessary factors for developing quick and powerful algorithms.
2. They assist us in managing and organizing data.
3. Data structures make the code more readable and understandable.
Some examples where the data structure used in the computer technologies:
a) Storing data
b) Managing resources and services
c) Data exchange
d) Ordering and sorting
e) Indexing
f) Searching
g) Scalability
3. Differentiate ADT and DS
Abstract Data Type Data Structure
A data type is one of the forms of a A data structure is a collection of
variable to which only values of a various data kinds. This set of data can
specific type can be assigned. This be represented by an object and used
value can be used throughout the throughout the program.
program.
The implementation of data type is The implementation of data structure
known as an abstract implementation. is known as a concrete
implementation.
It is capable of storing value but not It can store several sorts of data in a
data. As a result, we can say that it is single object.
data-free.
In the case of data types, a value can Certain operations are performed in
be explicitly assigned to the variables. the context of data structures to
allocate data to data structure objects.
There is no issue with temporal When dealing with a data structure
complexity. object, temporal complexity is crucial.
Data types include int, float, and char. Stack, queue, tree, and graph are
examples of data structures.
Figure 1
Traversal in a Stack:
Figure 2
Figure 3
Searching in a Stack:
Figure 4
Figure 5
Language, in general, allows us to define our own data type. Such data
types are classified as non-primitive data structures.
hence, these are the more advanced data structure. They are descended
from the basic data structure. Non-primitive data structures highlight the
organization of a collection of homogenous or heterogeneous data objects.
a) Float
A float is a data structure term used in various programming
languages that defines a variable with a partial value.
So, if you add, subtract or multiply two integers, the result will
always be an integer.
c) Character
A character in a data structure represents a character and symbol
such as a, B, f, R, ""., "-" and space. Therefore, it can store the
basic character set. It can hold a letter/symbol like n, F,d.
Characters can also be of different types.
d) Pointer
A pointer represents a memory storage location (RAM). The RAM
contains several cells in which the values are stored. Because each
memory cell is 1 byte in size and the memory address is always an
unsigned integer, each cell has a unique address to identify it.
a) Arrays
An array is defined as a collection of items stored in adjacent
memory locations. Arrays are also defined as a collection of
homogeneous data items stored in RAM; thus, they can only hold
one sort of data.
Figure 6
Figure 7
Figure 8
b) Lists
A list is defined as a collection of data objects with a variable
number of items. Lists or sequences are abstract data types that
Figure 9
c) Files
Files contain information, which is permanently kept on the Hard
Disk and Floppy Disk, which is also known as a secondary storage
device. Secondary devices can store both a single byte and a
significant amount of data.
Figure 10
d) Stacks
Figure 11
e) Queues
Queue defined (FIFO) First In First Out type of data structure.
Queues are also the part of non-primitive linear data structure, so in
Queues process, we can put an element in a queue from the REAR
end and delete an element from the FRONT end only.
Therefore, implement queues with using two ways:
1. Pointers
2. Arrays
Figure 12
f) Graphs
1. Connected Graph
2. Non-Connected Graph
3. Directed Graph
4. Non-Directed Graph
g) Trees
Trees are classified as non-primitive and non-linear data structures
in data structure categorization. We can depict a hierarchical
relationship between data components using trees.
Figure 13
As a result, the most widely used operations are broadly classified into
four classes in the Classification of Data Structure:
1. Create
2. Delete
3. Selection
4. Update
CREATE operation
DELETE operation
SELECTION operation
a) Searching
b) Sorting
c) Merging
a) Data Storage.
Data structures facilitate efficient data persistence, like specifying attribute
collections and corresponding structures used in database management
systems to store records.
b) Data Exchange.
Organized information, defined by data structures, can be shared between
applications like TCP/IP packets.
c) Resource and Service Management.
Data structures such as linked lists can enable core operating systems
resources and services to perform functions like file directory
management, memory allocation, and processing scheduling queues.
d) Scalability.
Big data applications rely on data structures to manage and allocate data
storage across many distributed storage locations. This function guarantees
scalability and high performance.
7. Select the relevant data structure for the scenario
a. Importance of selecting proper data structure.
b. Justify why you have selected particular data structure or data
structures for the scenario
8. Explain the operations of selected data structure for the given scenario
a. Explanation should relate the operations of the stack with scenario
b. Add suitable pictures
c. Write the algorithm for the operations of selected data structure
9. Memory stack
a. Explain queue data structure with real world example (add picture)
A Queue is defined as a linear data structure that is open at both ends and
the operations are performed in First In First Out (FIFO) order.
FIFO Principle of Queue:
i. A queue is similar to a line of people waiting to buy tickets, with
the first person in line being served. (For example, first come, first
served).
ii. The position of the entry in a queue that is 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, the head of the queue), and
the position of the last entry in the queue, that is, the one most
recently added, is referred to as the rear (or the tail) of the queue.
View the diagram below.
b. Explain the operations of a queue data structure with the picture and
algorithm
1. Enqueue: Adds an item from the back of the queue.
2. Dequeue: Removes an item from the front of the queue.
3. Front/Peek: Returns the value of the item in front of the queue without
dequeuing (removing) the item.
4. IsEmpty: Checks if the queue is empty.
5. IsFull: Checks if the queue is full.
6. Display: Prints all the items in the queue.
Coding
Figure 14
Figure 15
Figure 16
Output
Figure 17
TASK 02
TASK 03
TASK 04
1. Shortest path algorithm
a. Explain about shortest path algorithm
Given a graph and a source vertex in the graph, find the shortest paths from
the source to all vertices in the given graph.
b. Specify and very briefly explain about types of shortest path algorithm
Shortest path algorithms are classified into two types: single-source and all-
pairs. Both sorts of algorithms function well in their respective ways. Because
of the extra complexity, all-pairs algorithms take longer to run. Even if the
format or form of the return values varies from method to algorithm, all
shortest path algorithms return values that can be utilized to calculate the
shortest path.
I. Single-source
If the goal of the algorithm is to find the shortest path between only
two given vertices, s and t, then the algorithm can simply be stopped
when that shortest path is found. Because there is no way to decide
which vertices to "finish" first, all algorithms that solve for the shortest
path between two given vertices have the same worst-case asymptotic
complexity as single-source shortest path algorithms.
II. All-pairs
The most common algorithm for the all-pairs problem is the floyd-
warshall algorithm.
c. Choose more suitable two shortest path algorithm to visit all the places of
the participants of the car race
I. Clearly explain selected shortest path algorithms with the algorithm
II. Draw sample graph for scenario
III. Analyse the operation, using illustrations, of two shortest path
algorithms (Trace out the shortest path algorithms to find out the
shortest paths for all participants from the ABC Pvt Ltd.)
2. Sorting Algorithm
3. Compare and Contrast both sorting algorithms
4. Analyse the performance of both sorting algorithms through Time and space
complexity of both sorting algorithms. (Discuss about Best, Average and
Worst cases of complexity).
TASK 05
1. Effectiveness of an Algorithm
a) Explain how effectiveness of algorithm measure.
b) Determine two ways in which the efficiency of an algorithm can be
measured, illustrating your answer with an example.
2. Asymptotic Analysis
a) Explain about the Asymptotic Analysis
An algorithm's asymptotic analysis pertains to defining the mathematical
boundation/framing of its run-time performance. We may very well deduce
the best case, average case, and worst case scenarios of an algorithm using
asymptotic analysis.
Usually, the time required by an algorithm falls under three types −
a. Best Case − Minimum time required for program execution.
b. Average Case − Average time required for program execution.
c. Worst Case − Maximum time required for program execution.
Figure 18
b) Omega Notation, Ω
The Ω(n) notation is a formal way to express a lower bound on the
running time of an algorithm. It measures the best case time problem
or the best time an algorithm can take to complete.
Figure 19
c) Theta Notation, θ
The notation θ(n) is a formal way to express both a lower bound and an
upper bound on the running time of an algorithm.
Figure 20
One clumsy approach would be to construct both algorithms and run the two
programs on your computer with different inputs to determine which one takes
less time. There are numerous issues with this method of algorithm analysis.
a. It is possible that the first algorithm outperforms the second for some
inputs. And second performs better for some inputs.
b. It's also possible that the first algorithm works better on one machine for
some inputs, while the second works better on another machine for others.
Asymptotic Analysis is the big idea that deals with the concerns mentioned
above while examining algorithms. In Asymptotic Analysis, we evaluate an
algorithm's performance in terms of input size (rather than real execution
time).
a) let us say:
we run the Linear Search on a fast computer A and
Binary Search on a slow computer B and
pick the constant values for the two computers so that it tells us exactly
how long it takes for the given machine to perform the search in
seconds.
b) Let’s say the constant for A is 0.2 and the constant for B is 1000 which
means that A is 5000 times more powerful than B.
c) For small values of input array size n, the fast computer may take less
time.
d) But, after a certain value of input array size, the Binary Search will
definitely start taking less time compared to the Linear Search even
though the Binary Search is being run on a slow machine.
3. Critically review the sort of trade-offs exists when you use an ADT for
implementing programs
a) What is a trade-off is when specifying an ADT using an example to
support your answer.
b) Explain about types of trade-off in ADT
4. Benefits of using independent data structures for implement a program
a) Explain about the independent data structures
b) Evaluate at least three benefits of using implementation independent
data structures