jquery_report_final
jquery_report_final
Dhurthi [1AT23CG039}
Prof. Niranjani M
Assistant professor, CSE Dept
Last but not the least, the project would not have been a
success without the support of our parents and friends.
Our sincere thanks should be rendered to everyone who
helpedus in all possible ways.
2. Introduction
2.1. Research And Significance
2.2. Aim & Scope
3. Implementation
3.1. Proposed System
3.2. Requirement Specification
3.3. System Functionalities
3.4. Sorting Algorithms
6. Conclusion
7. References
Implementation
There have been a lot of studies and animation tools on visualizing sorting
algorithms. Some are based on how to make such an application and others on
different technologies which were aimed for increasing the understanding of
the concept.
Proposed System
The proposed system consists of various features which makes this web
application efficient for the user. The entire user interface is entirely done by
front end technologies (HTML, CSS, Bootstrap and JavaScript). The user
interface has various components: The main navbar allows the user to set the
size of the array and to control the speed of visualization, the buttons to
generate a new random array, to stop the visualization and the sorting
algorithm buttons.
Requirement Specification
This proposed software runs effectively on a computing system that has the
minimum requirements. Undertaking all the equipment necessities are not
satisfied but rather exist in their systems administration between the user’s
machines already. So, the main need is to introduce appropriate equipment for
the product.
System Functionalities
The first row of the Navbar section has the range unit to set the size of the
array with a minimum size of 10 and a maximum of 50 elements the wide
range is mainly to show how these algorithms work for larger data visually as
it’s impossible to show students how an array with over 100 elements gets
sorted but visually seeing it people can understand how they work.
The second part has the range controller to set the speed of visualization with
the slowest speed at showing every swap in detail so that students can grasp
the idea of what's going on and the fastest to show how different algorithms
quickly sort an array at larger data, for example trying to sort an array of 100
elements by bubble sort can take a really long time as the slowest setting and
can be time consuming but merge sort can do it in couple of seconds by this
even students can get an idea of how algorithms differ between each other in
speed.
The third part has the buttons to generate new array and to stop the sorting
midway. The fourth part contains all buttons for the selectable algorithms:
Bubble Sort, Selection Sort, Insertion Sort, Merge Sort & Quick Sort by
default no algorithm is selected, user needs to select the desired algorithm to
see it visually. The fifth part is the color palette. The colors used on the graph
where blue represents the default array, yellow represents the current element
in which the
Sorting Algorithms
A Sorting Algorithms main purpose is to reposition a given array or list of
elements in ascending or descending order. Now taking about the algorithms
itself we are using 5 sorting algorithms in this visualizer namely Bubble Sort,
Selection Sort, Insertion Sort, Quick Sort & Merge Sort. These algorithms are
the commonly used algorithms for sorting.
Bubble Sort
Bubble sort also known as sinking sort from time to time, is a simple sorting
algorithm that repeatedly steps through the list, compares adjacent elements
and swaps them if they are in the wrong order. The pass through the list is
repeated until the list is sorted. But the algorithm is not suitable for amounts of
data as its average complexity is of Ο(n2 ), Where n is the number of elements.
The pseudocode of bubble sort is shown below
Insertion Sort
Insertion Sort is an in-place comparison sorting algorithm. In this algorithm, a
sub array is kept which is always sorted. An element which needs to be
inserted in this sub array, has to find its right position were it should be and
then it will to be inserted in that position. Hence, it's called Insertion Sort. The
pseudo code of it is shown below in Figure 4.6.
Merge Sort
Merge Sort is one the most efficient sorting algorithms among all the
algorithms as even its worst-case time complexity being O(n log n). It follows
the divide and conquer method as it divides the array into smaller sub arrays
and compares these sub arrays and sorts them accordingly and merges these
sorted sub arrays to get the final array. The pseudo code is shown below in
Figure 4.8.
Model
The Model is incorporated of one object, called sorter. This object holds all the
sorting algorithm code arranged as individual methods. A centralized
algorithm buttons when clicked goes to a switch case of sorting algorithm
methods, and then calls the appropriate one.
The 5 buttons labeled as the 5 sorting algorithms (Bubble sort, Selection Sort,
Insertion Sort, Quick Sort, Merge Sort) on the user interface directly control
this object. When the user selects a sorting algorithm, the corresponding
sorting algorithm method is called, and the time complexities, swaps,
comparisons and time taken for the algorithm to take place are calculated.
All of this is stored as a variable named as best, avg, worst, swaps, comp and
two other variables named t0 ad t1 to calculate the time taken to execute the
algorithm, this is public and attainable for the methods connected to the
buttons on the web application user interface.
The divs array is the kind of interface through which the user interface
connects with the back end code. The result is a visualization of the bars
comparing with each other and moving to its correct position thus giving us
the sorted bar graph.
</head>
<header>
<h1 align="center">Sorting Visualizer</h1>
<nav>
<div class="row">
<div class="col gap-2 d-sm-flex" id="newArray">
<button
type="button
"
class="btn btn-outline-success btn-light newArray"
>
New Array
</button>
</div>
<div class="col" id="input">
<span id="size"
>Size
<input
id="arr_sz"
type="range
" min="10"
max="50"
step="1"
value="40" /></span
><span id="speed"
CSS CODE
body {
font-family:
Lato,Merriweather,Roboto,Montserrat; font-
size: 20px;
padding: 0 20px 30px 0;
line-height: 1.4;
/* Lato,Merriweather,Roboto,Montserrat */
}
.flex-container {
display: flex;
flex-wrap:
nowrap; width:
100%; height:
400px;
justify-content: center;
align-items: flex-end; /* Aligns bars from the bottom */
transition: 2s all ease;
}
.flex-item {
background: cyan;
border: 0.5pt solid #000;
width: 10px;
transition: 0.1s all ease;
}
#input {
display: flex;
padding: 10px;
justify-content: space-around;
}
.h1,
.col span {
display: flex;
flex-direction:
column; justify-
content: center;
align-items: center;
padding: 10px;
}
.row {
display: inline;
text-align:
center;
}
.flex-container
{ margin-
top: 0;
}
#input {
display: inline;
text-align:
center;
}
.justify-content-
end { margin-
top: 0;
}
.btn {
margin-bottom: 10px;
}
}
// bubble sort
async function bubble() {
const ele = document.querySelectorAll(".bar");
for (let i = 0; i < ele.length - 1; i++) {
for (let j = 0; j < ele.length - i - 1; j++)
{ console.log("In jth loop");
ele[j].style.background = "blue";
ele[j + 1].style.background = "blue";
if (parseInt(ele[j].style.height) > parseInt(ele[j +
1].style.height)) {
await waitforme(delay);
swap(ele[j], ele[j +
1]);
}
ele[j].style.background = "cyan";
Dept. of CS&D, AIT 22
ele[j + 1].style.background = "cyan";
}
ele[ele.length - 1 - i].style.background = "green";
}
ele[0].style.background = "green";
}
const bubSortbtn = document.querySelector(".bubbleSort");
bubSortbtn.addEventListener("click", async function () {
disableSortingBtn();
disableSizeSlider();
disableNewArrayBtn()
; await bubble();
enableSortingBtn();
enableSizeSlider();
enableNewArrayBtn();
});
// insertion sort
async function insertion() {
const ele = document.querySelectorAll(".bar");
ele[0].style.background = "green";
for (let i = 1; i < ele.length; i+
+) { let j = i - 1;
let key = ele[i].style.height;
ele[i].style.background =
"blue"; await waitforme(delay);
while (j >= 0 && parseInt(ele[j].style.height) > parseInt(key))
{ ele[j].style.background = "blue";
ele[j + 1].style.height =
ele[j].style.height; j--;
await waitforme(delay);
for (let k = i; k >= 0; k--) {
ele[k].style.background = "green";
}
}
ele[j + 1].style.height = key;
ele[i].style.background = "green";
}
}
const inSortbtn = document.querySelector(".insertionSort");
inSortbtn.addEventListener("click", async function () {
disableSortingBtn();
disableSizeSlider();
disableNewArrayBtn()
; await insertion();
// merge sort
async function merge(e, t, r, a)
{ const n = r - t + 1,
l = a - r;
let o = new
Array(n), g =
new Array(l);
for (let r = 0; r < n; r++)
await waitforme(delay),
(e[t + r].style.background =
"orange"), (o[r] = e[t +
r].style.height);
for (let t = 0; t < l; t++)
await waitforme(delay),
(e[r + 1 + t].style.background =
"yellow"), (g[t] = e[r + 1 +
t].style.height);
await
waitforme(delay);
let i = 0,
s = 0,
y = t;
for (; i < n && s < l; )
await waitforme(delay),
parseInt(o[i]) <=
parseInt(g[s])
? (n + l === e.length
? (e[y].style.background = "green")
: (e[y].style.background =
"lightgreen"), (e[y].style.height =
o[i]),
i++,
y++)
: (n + l === e.length
? (e[y].style.background = "green")
: (e[y].style.background =
"lightgreen"), (e[y].style.height =
g[s]),
s++,
y++);
for (; i < n; )
await
Dept. of CS&D, AIT 24
waitforme(delay),
n + l === e.length
? (e[y].style.background = "green")
: (e[y].style.background = "lightgreen"),
(e[y].style.height = o[i]),
i++,
y++;
// quick sort
async function partitionLomuto(e, t,
a) { let n = t - 1;
e[a].style.background = "red";
for (let r = t; r <= a - 1; r++)
(e[r].style.background = "yellow"),
await waitforme(delay),
parseInt(e[r].style.height) < parseInt(e[a].style.height)
? (console.log("In partitionLomuto for j
if"), n++,
swap(e[n], e[r]),
(e[n].style.background =
"orange"),
n != r && (e[r].style.background = "orange"),
await waitforme(delay))
Dept. of CS&D, AIT 26
: (e[r].style.background = "pink");
// selection sort
async function selection() {
const e = document.querySelectorAll(".bar");
for (let t = 0; t < e.length; t++)
{ let n = t;
e[t].style.background = "blue";
for (let a = t + 1; a < e.length; a++)
(e[a].style.background = "red"),
await waitforme(delay),
parseInt(e[a].style.height) < parseInt(e[n].style.height)
Dept. of CS&D, AIT 28
? (n !== t && (e[n].style.background = "cyan"), (n =
a))
: (e[a].style.background = "cyan");
await waitforme(delay),
swap(e[n], e[t]),
(e[n].style.background = "cyan"),
(e[t].style.background = "green");
}
}
const selectionSortbtn =
document.querySelector(".selectionSort");
selectionSortbtn.addEventListener("click", async function () {
disableSortingBtn(),
disableSizeSlider(),
disableNewArrayBtn(),
await selection(),
enableSortingBtn(),
enableSizeSlider(),
enableNewArrayBtn();
});
1. https://sist.sathyabama.ac.in/sist_naac/documents/1.3.4/b.e-cse-batchno-
26.pdf
2. https://theses.cz/id/3w4s3a/Mykhailo-Klunko-bc-thesis.pdf
3. Introduction to the Design and Analysis of Algorithms, By Anany
Levitin, 3rd Edition (Indian), 2017, Pearson.
4. Computer Algorithms/C++, Ellis Horowitz, SatrajSahni and
Rajasekaran, 2nd Edition, 2014, Universities Press.
5. Introduction to Algorithms, Thomas H. Cormen, Charles E.
Leiserson, Ronal L. Rivest, Clifford Stein, 3rd Edition, PHI.
6. Design and Analysis of Algorithms, S. Sridhar, Oxford (Higher Education)