Professional Documents
Culture Documents
Submitted by:
Kunal (02955202719)
Gaurav Chamoli (04555202719)
Kartik Gupta (04955202719)
BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE AND ENGINEERING
At
BHAGWAN MAHAVEER COLLEGE OF ENGINEERING AND
MANAGEMENT
JAGDISHPUR, SONEPAT
AFFILIATED TO GGSIPU DWARKA, DELHI
Declaration
Kunal (02955202719)
Chapter 7: BIBLIOGRAPHY
INTRODUCTION
Purpose
o The purpose of this project is to help the other students as well as
teachers to have a better understanding of how different algorithm
works and which algorithm takes more time and which takes less time
to complete the given task. While learning some new skills, if you
visualize its working and approach then you will have a better
understanding of that particular skill and it will also have a long-
lasting impact and stays in your one’s mind for quite a long time.
Objective
o The objective of this project is to improve my knowledge of different
algorithms, learn to implement them in real-world problems and
create a project where I can keep all algorithms in one place for easy
access.
Project Scope
o This project is quite useful as it makes the learning process quite easy
and attractive which makes learning fun. Hence this project has a
good scope
Technologies Used
o LANGUAGES
JavaScript
HTML
CSS
o FRAMEWORK
React JS
o OPERATING SYSTEM
Windows 10
o IDE
Visual Studio Code
LITERATURE SURVEY
Existing System
o There are existing systems which are similar to my project but some
do not have many algorithms in one place, others do not have a user-
friendly interface and most importantly most of them do not have
visually appealing graphics and layouts.
Propose System
o In this project I added many paths to finding algorithms as well as
sorting algorithms in one place so that the user does not have to visit
the different websites to learn different algorithms as I will provide all
of them in one place with a user-friendly interface and visually
appealing graphics and layout.
Feasibility Study
o As in this project, I am combining multiple algorithms in one place
and visualizing the working of the algorithm with quite a simple and
interactive interface. So, this is a unique and useful project, hence this
project is feasible.
METHODOLOGY & PLANNING
Installation
o The application installation scripts have to be generated from the current
server where the application source code is saved and installed in the main
server from where the application to be run. This was done using special
code, which generate all to insert preliminary data at server and the
operational modules of the application made available to the end users
successfully
User Interface
o User interface design creates an effective communication medium between a
human and a computer. Following asset of interface design principles,
design identifies objects and actions and then creates a screen layout that
forms the bases for a user interface prototype.
o Interface design of Path Finding and Sorting Algorithm Visualizer is based
on the following three principles
Place the user in control
Reduce the User memory load
Make the interface consistent
Minimum Requirement
o DVD-ROM Drive
o Windows 7 or above
Experimental Analysis
Dijkstra’s Algorithm
o It is used to find the shortest path between nodes in a graph, it Maintain two
sets, one set contains vertices included in the shortest-path tree, other set
includes vertices not yet included in the shortest-path tree. At every step of
the algorithm, find a vertex that is in the other set (set not yet included)
and has a minimum distance from the source.
o It Create a set sptSet (shortest path tree set) that keeps track of vertices
included in the shortest-path tree, i.e., whose minimum distance from the
source is calculated and finalized. Initially, this set is empty.
o Assign a distance value to all vertices in the input graph. Initialize all
distance values as INFINITE. Assign the distance value as 0 for the source
vertex so that it is picked first.
o While sptSet doesn’t include all vertices
Pick a vertex u which is not there in sptSet and has a minimum distance
value.
Include u to sptSet.
Note: We use a boolean array sptSet[] to represent the set of vertices included in
SPT. If a value sptSet[v] is true, then vertex v is included in SPT, otherwise not.
Array dist[] is used to store the shortest distance values of all vertices
Code
#include <iostream>
using namespace std;
#include <limits.h>
return min_index;
}
Before Execution:
Processing
Result
A* Algorithm
o A* Search algorithm is one of the best and popular technique used in path-
finding and graph traversals. Informally speaking, A* Search algorithms,
unlike other traversal techniques, it has “brains”. What it means is that it is
really a smart algorithm which separates it from the other conventional
algorithms. This fact is cleared in detail in below sections.
And it is also worth mentioning that many games and web-based maps use
this algorithm to find the shortest path very efficiently (approximation).
o Consider a square grid having many obstacles and we are given a starting
cell and a target cell. We want to reach the target cell (if possible) from the
starting cell as quickly as possible. Here A* Search Algorithm comes to the
rescue.
What A* Search Algorithm does is that at each step it picks the node
according to a value-‘f’ which is a parameter equal to the sum of two other
parameters – ‘g’ and ‘h’. At each step it picks the node/cell having the
lowest ‘f’, and process that node/cell.
We define ‘g’ and ‘h’ as simply as possible below
g = the movement cost to move from the starting point to a given square on
the grid, following the path generated to get there.
h = the estimated movement cost to move from that given square on the grid
to the final destination. This is often referred to as the heuristic, which is
nothing but a kind of smart guess. We really don’t know the actual distance
until we find the path, because all sorts of things can be in the way (walls,
water, etc.). There can be many ways to calculate this ‘h’ which are
discussed in the later sections.
Code
function astar(nodes, start, target, nodesToAnimate, boardArray, name,
heuristic) {
if (!start || !target || start === target) {
return false;
}
nodes[start].distance = 0;
nodes[start].totalDistance = 0;
nodes[start].direction = "up";
let unvisitedNodes = Object.keys(nodes);
while (unvisitedNodes.length) {
let currentNode = closestNode(nodes, unvisitedNodes);
while (currentNode.status === "wall" && unvisitedNodes.length) {
currentNode = closestNode(nodes, unvisitedNodes)
}
if (currentNode.distance === Infinity) return false;
nodesToAnimate.push(currentNode);
currentNode.status = "visited";
if (currentNode.id === target) {
return "success!";
}
updateNeighbors(nodes, currentNode, boardArray, target, name, start,
heuristic);
}
}
function closestNode(nodes, unvisitedNodes) {
let currentClosest, index;
for (let i = 0; i < unvisitedNodes.length; i++) {
if (!currentClosest || currentClosest.totalDistance >
nodes[unvisitedNodes[i]].totalDistance) {
currentClosest = nodes[unvisitedNodes[i]];
index = i;
} else if (currentClosest.totalDistance ===
nodes[unvisitedNodes[i]].totalDistance) {
if (currentClosest.heuristicDistance >
nodes[unvisitedNodes[i]].heuristicDistance) {
currentClosest = nodes[unvisitedNodes[i]];
index = i;
}
}
}
unvisitedNodes.splice(index, 1);
return currentClosest;
}
function updateNeighbors(nodes, node, boardArray, target, name, start,
heuristic) {
let neighbors = getNeighbors(node.id, nodes, boardArray);
for (let neighbor of neighbors) {
if (target) {
updateNode(node, nodes[neighbor], nodes[target], name, nodes,
nodes[start], heuristic, boardArray);
} else {
updateNode(node, nodes[neighbor]);
}
}
}
function updateNode(currentNode, targetNode, actualTargetNode, name, nodes,
actualStartNode, heuristic, boardArray) {
let distance = getDistance(currentNode, targetNode);
if (!targetNode.heuristicDistance) targetNode.heuristicDistance =
manhattanDistance(targetNode, actualTargetNode);
let distanceToCompare = currentNode.distance + targetNode.weight +
distance[0];
if (distanceToCompare < targetNode.distance) {
targetNode.distance = distanceToCompare;
targetNode.totalDistance = targetNode.distance +
targetNode.heuristicDistance;
targetNode.previousNode = currentNode.id;
targetNode.path = distance[1];
targetNode.direction = distance[2];
}
}
function getNeighbors(id, nodes, boardArray) {
let coordinates = id.split("-");
let x = parseInt(coordinates[0]);
let y = parseInt(coordinates[1]);
let neighbors = [];
let potentialNeighbor;
if (boardArray[x - 1] && boardArray[x - 1][y]) {
potentialNeighbor = `${(x - 1).toString()}-${y.toString()}`
if (nodes[potentialNeighbor].status !== "wall")
neighbors.push(potentialNeighbor);
}
if (boardArray[x + 1] && boardArray[x + 1][y]) {
potentialNeighbor = `${(x + 1).toString()}-${y.toString()}`
if (nodes[potentialNeighbor].status !== "wall")
neighbors.push(potentialNeighbor);
}
if (boardArray[x][y - 1]) {
potentialNeighbor = `${x.toString()}-${(y - 1).toString()}`
if (nodes[potentialNeighbor].status !== "wall")
neighbors.push(potentialNeighbor);
}
if (boardArray[x][y + 1]) {
potentialNeighbor = `${x.toString()}-${(y + 1).toString()}`
if (nodes[potentialNeighbor].status !== "wall")
neighbors.push(potentialNeighbor);
}
return neighbors;
}
function getDistance(nodeOne, nodeTwo) {
let currentCoordinates = nodeOne.id.split("-");
let targetCoordinates = nodeTwo.id.split("-");
let x1 = parseInt(currentCoordinates[0]);
let y1 = parseInt(currentCoordinates[1]);
let x2 = parseInt(targetCoordinates[0]);
let y2 = parseInt(targetCoordinates[1]);
if (x2 < x1 && y1 === y2) {
if (nodeOne.direction === "up") {
return [1, ["f"], "up"];
} else if (nodeOne.direction === "right") {
return [2, ["l", "f"], "up"];
} else if (nodeOne.direction === "left") {
return [2, ["r", "f"], "up"];
} else if (nodeOne.direction === "down") {
return [3, ["r", "r", "f"], "up"];
} else if (nodeOne.direction === "up-right") {
return [1.5, null, "up"];
} else if (nodeOne.direction === "down-right") {
return [2.5, null, "up"];
} else if (nodeOne.direction === "up-left") {
return [1.5, null, "up"];
} else if (nodeOne.direction === "down-left") {
return [2.5, null, "up"];
}
} else if (x2 > x1 && y1 === y2) {
if (nodeOne.direction === "up") {
return [3, ["r", "r", "f"], "down"];
} else if (nodeOne.direction === "right") {
return [2, ["r", "f"], "down"];
} else if (nodeOne.direction === "left") {
return [2, ["l", "f"], "down"];
} else if (nodeOne.direction === "down") {
return [1, ["f"], "down"];
} else if (nodeOne.direction === "up-right") {
return [2.5, null, "down"];
} else if (nodeOne.direction === "down-right") {
return [1.5, null, "down"];
} else if (nodeOne.direction === "up-left") {
return [2.5, null, "down"];
} else if (nodeOne.direction === "down-left") {
return [1.5, null, "down"];
}
}
if (y2 < y1 && x1 === x2) {
if (nodeOne.direction === "up") {
return [2, ["l", "f"], "left"];
} else if (nodeOne.direction === "right") {
return [3, ["l", "l", "f"], "left"];
} else if (nodeOne.direction === "left") {
return [1, ["f"], "left"];
} else if (nodeOne.direction === "down") {
return [2, ["r", "f"], "left"];
} else if (nodeOne.direction === "up-right") {
return [2.5, null, "left"];
} else if (nodeOne.direction === "down-right") {
return [2.5, null, "left"];
} else if (nodeOne.direction === "up-left") {
return [1.5, null, "left"];
} else if (nodeOne.direction === "down-left") {
return [1.5, null, "left"];
}
} else if (y2 > y1 && x1 === x2) {
if (nodeOne.direction === "up") {
return [2, ["r", "f"], "right"];
} else if (nodeOne.direction === "right") {
return [1, ["f"], "right"];
} else if (nodeOne.direction === "left") {
return [3, ["r", "r", "f"], "right"];
} else if (nodeOne.direction === "down") {
return [2, ["l", "f"], "right"];
} else if (nodeOne.direction === "up-right") {
return [1.5, null, "right"];
} else if (nodeOne.direction === "down-right") {
return [1.5, null, "right"];
} else if (nodeOne.direction === "up-left") {
return [2.5, null, "right"];
} else if (nodeOne.direction === "down-left") {
return [2.5, null, "right"];
}
}
function manhattanDistance(nodeOne, nodeTwo) {
let nodeOneCoordinates = nodeOne.id.split("-").map(ele => parseInt(ele));
let nodeTwoCoordinates = nodeTwo.id.split("-").map(ele => parseInt(ele));
let xOne = nodeOneCoordinates[0];
let xTwo = nodeTwoCoordinates[0];
let yOne = nodeOneCoordinates[1];
let yTwo = nodeTwoCoordinates[1];
let xChange = Math.abs(xOne - xTwo);
let yChange = Math.abs(yOne - yTwo);
return (xChange + yChange);
}
module.exports = astar;
Before Execution
Processing
Result
Breadth First Search
public:
Graph(int V); // Constructor
Graph::Graph(int V)
{
this->V = V;
adj.resize(V);
}
void Graph::BFS(int s)
{
// Mark all the vertices as not visited
vector<bool> visited;
visited.resize(V, false);
// Create a queue for BFS
list<int> queue;
while (!queue.empty()) {
// Dequeue a vertex from queue and print it
s = queue.front();
cout << s << " ";
queue.pop_front();
Before Execution
Processing
Result
Depth First Search
#include <bits/stdc++.h>
using namespace std;
void Graph::DFS(int v)
{
// Mark the current node as visited and
// print it
visited[v] = true;
cout << v << " ";
Processing
Result
Merge Sort
o The Merge Sort algorithm is a sorting algorithm that is based on the Divide
and Conquer paradigm. In this algorithm, the array is initially divided into
two equal halves and then they are combined in a sorted manner.
Before Execution
Processing
Result
Quick Sort
QS(input, 0, size-1);
}
Before Execution
Procession
Result
Bubble Sort
Code
using namespace std;
Processing
Result
Heap Sort
o Heap sort is a comparison-based sorting technique based on Binary Heap
data structure. It is similar to the selection sort where we first find the
minimum element and place the minimum element at the beginning. Repeat
the same process for the remaining elements.
Heap sort is an in-place algorithm.
Its typical implementation is not stable, but can be made stable (See this)
Typically 2-3 times slower than well-implemented QuickSort. The
reason for slowness is a lack of locality of reference.
Code
#include <iostream>
using namespace std;
// left = 2*i + 1
int l = 2 * i + 1;
// right = 2*i + 2
int r = 2 * i + 2;
Processing
Result
FUTURE ENHANCEMENT
Future Enhancement
I will also improve the interface and will make it more interactive.
A short term use case would definitely be, explaining what happens in a
video, frame by frame.
I will also try to make this project dynamic where we can take inputs
from users and outputs its visualization for a better understanding of the
user
BIBLIOGRAPHY
Bibliography
o React Documentation: https://reactjs.org/docs/getting-started.html
o JavaScript Documentation MDN: https://developer.mozilla.org/en-
US/docs/Web/JavaScript
o CSS Documentation MDN: https://developer.mozilla.org/en-
US/docs/Web/CSS
o Clement Mihailescu: https://www.youtube.com/watch?v=n4t_-
NjY_Sg&list=PLuKxoRxTXB7i6iBOBIAlS97peMPrViIL5&index=8&t=92
8s
o Path Finding Algorithms:
Dijkstra’s Algorithm: https://www.geeksforgeeks.org/dijkstras-shortest-
path-algorithm-greedy-algo-7/
A* Algorithm: https://neo4j.com/docs/graph-data-
science/current/algorithms/astar/
DFS: https://www.hackerearth.com/practice/algorithms/graphs/depth-
first-search/tutorial/
BFS: https://www.freecodecamp.org/news/exploring-the-applications-
and-limits-of-breadth-first-search-to-the-shortest-paths-in-a-weighted-
1e7b28b3307/
All Algorithms: https://medium.com/omarelgabrys-blog/path-finding-
algorithms-f65a8902eb40
o Sorting Algorithms:
Merge Sort: https://www.geeksforgeeks.org/merge-sort/
Bubble Sort: https://www.geeksforgeeks.org/bubble-sort/
Quick Sort: https://www.geeksforgeeks.org/quick-sort/
Heap Sort: https://www.geeksforgeeks.org/heap-sort/