Design Analysis of Different Algorithms

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

Design analysis of

different algorithms and


there time and space
complexity
Team Members
• Jyotiraditya Chopra-211113
• Saksham Gupta-211120
Introduction
This project aims to compare and
analyse the performance of various
data structures including linked
lists, stacks, queues, trees, and
graphs. Each of these data
structures will be implemented and
tested using various input sizes and
types of data. The performance
metrics to be measured include time
complexity, space complexity, and
memory usage. The results of the
analysis will be presented and
discussed to determine which data
structures are best suited for
different types of problems and
applications.

07/30/2023 Annual Review 2


Application
Area & Motivation
• The program is a C++ implementation of basic data structures: linked list, stack, queue, and
graph.

• The linked list implementation uses a Node struct and head/tail pointers to add and remove
elements.

• The stack implementation uses a vector to store elements and has push, pop, top, and empty
functions.

• The queue implementation also uses a vector and a head variable to store elements and has
push, pop, front, and empty functions.

• The graph implementation uses an adjacency list and has add_edge, dfs, and bfs functions.

• The program includes performance tests for each data structure with increasing input sizes and
measures the time to perform operations.

• The elapsed time is outputted for each data structure and input size.

07/30/2023 Annual Review 3


Pseudocode:
Define constants for the maximum input size and maximum value for random input data.
Define a function to generate random input data of a given size.
Define classes for the data structures to be tested (linked list, stack, queue, and graph), along with their methods.
In the main function, initialize the random seed using the current time.
For each data structure (linked list, stack, queue, and graph), perform the following performance test:
For each input size n in powers of 10 from 10 to the maximum input size:
Generate random input data of size n.
Create an instance of the data structure.
Start a timer.
Insert each element of the input data into the data structure.
Perform a sequence of operations on the data structure (e.g. remove each element for the linked list, pop each element for
the stack, etc.).
Stop the timer and record the elapsed time.
Print the input size and elapsed time for the test.
End the program.
Algorithm:

There are no specific algorithm names mentioned


in this code. However, the code includes various
data structures such as linked list, stack, queue,
and graph along with their implementations.
Additionally, the code also includes performance
tests for these data structures.
Code
These are header files that define
various standard C++ data
structures and algorithms.

This line is a using declaration that


allows us to use names from the std
namespace without needing to
qualify them explicitly.

These are constants that define the


maximum size of the input data
and the maximum value for
random input data

This is a function that generates


A satisfied customer random input data of size n. It
creates a vector of size n and fills it
with random integers between 0
and MAX_VALUE.
This is a class that implements a linked list.
It has private member variables head and
tail that point to the first and last nodes in
the list. It has public member functions
insert and remove that add and remove
nodes from the list, respectively.

A satisfied customer
This is a class that implements a stack. It has a
private member variable data that is a vector of
integers. It has public member functions push,
top, pop, and empty that add elements to the
top of the stack, return the top element of the
stack, remove the top element of the stack, and
check whether the stack is empty, respectively.

The code defines a class called queue that


implement queue data structure the queue is
implemented using vector data structure to
hold the elements and an integer variable head
to keep track of front queue

A satisfied customer
The above code defines a Graph class with an
adjacency list representation. The class has a
constructor that takes the number of vertices and
initializes an empty adjacency list. It also has an
add_edge method to add an edge between two
vertices. The Graph class has two methods, dfs
and bfs, to perform depth-first search and breadth-
first search traversal on the graph starting from a
given vertex. The dfs and bfs methods use stack
and queue data structures, respectively, to keep
track of visited vertices and traverse the graph.

A satisfied customer
1.int main(): This is the main function
where the program execution starts.
2.srand(time(nullptr));: This line sets
the seed for the random number
generator. It uses the current time
(time(nullptr)) as the seed to ensure
different random numbers are
generated each time the program runs.
3.for (int n = 10; n <= N; n *= 10) {:
This is the start of the first loop that
iterates over a range of values for
variable n, starting from 10 and
multiplying it by 10 in each iteration
until it reaches or exceeds the value of
N.

A satisfied customer
1.vector<int> input = generate_input(n);: This line
generates a vector input containing n elements by
calling a function generate_input(n). The specifics
of the generate_input function are not provided in
the code snippet, but it likely generates a vector of
random integers.
2.LinkedList ll;: This line declares an object ll of
type LinkedList, presumably a custom
implementation of a linked list.
3.auto start =
chrono::high_resolution_clock::now();: This line
records the current time using the
high_resolution_clock from the chrono library. It
marks the start of the performance test for the
linked list.
4.for (int x : input) { ll.insert(x); }: This loop
inserts each element from the input vector into the
A satisfied customer linked list ll using the insert function.
5.for (int x : input) { ll.remove(x); }: This loop
removes each element from the linked list ll using
the remove function.
Output

A satisfied customer
Conclusion
Overall, this program is a useful tool for comparing the performance of different data
structures on various input sizes and operations. By measuring
the execution time of each data structure on a large number of inputs, it can help
developers select the best data structure for their specific use case and optimize their
algorithms for the best performance.

07/30/2023 Annual Review 13

You might also like