-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquicksort.html
228 lines (182 loc) · 7.78 KB
/
quicksort.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/ScrollTrigger.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
</head>
<body>
<div id="mySidebar" class="sidebar">
<h1><a href="/index.html">Home</a></h1>
<h3 class="text-light ps-3">LOGARITHMIC</h3>
<a href="/quicksort.html">Quick Sort</a>
<a href="/merge.html">Merge Sort</a>
<a href="/heap.html">Heap Sort</a>
<h3 class="text-light ps-3">QUADRATIC</h3>
<a href="/selection.html">Selection Sort</a>
<a href="/bubble.html">Bubble Sort</a>
<a href="/insertion.html">Insertion Sort</a>
</div>
<nav class="fixed-top navbar navbar-dark bg-dark">
<div class="container-fluid">
<div class="d-flex">
<button id="togglebutton" class="openbtn bg-dark text-light" onclick="toggleNav()">☰</button>
<a class="navbar-brand float-start mx-4" href="#">Sort Visualiser</a>
</div>
</div>
</nav>
<div>
<div id="box">
<div class="title">Quick Sort</div>
<div style="float: right; white-space: nowrap;">
<button class="sort-btns" id="shuffle-btn" onclick="selectionplay()"><img src="/images/play.png"
alt="Play"></button>
<button class="sort-btns" id="run-btn" onclick="pause()"><img src="/images/pause.png" alt=""></button>
<div class="slider-container">
<div id="elements-text">
Elements: <label for="size" id="label"></label>
</div>
<input type="range" value="100" min="10" max="1000" step="5" name="item-num" id="slider">
<div id="elements-text">
Time: <label for="speed" id="speed"></label> sec
</div>
<input type="range" min="10" max="1000" name="speed" value="500" id="speedSlider"
onchange="setSpeed(this.value)">
</div>
</div>
<div style="clear: both; padding-top: 20px;">
<div id="container"></div>
</div>
</div>
</div>
<div id="cover">
<div class="info ">
<div class="description">
<div style="font-family: 'Jura', Courier, monospace; font-size: 35px;">DESCRIPTION</div>
<p>
Quick Sort is a sorting algorithm based on splitting the data structure in smaller partitions and
sort them
recursively until the data structure is sorted.
</p>
<p>
This division in partitions is done based on an element, called pivot:
all the elements bigger than the pivot get placed on the right side of the structure, the smaller
ones to the
left, creating two partitions.
Next, this procedure gets applied recursively to the two partitions and so on.
</p>
<p>
This partition technique based on the pivot is called <a
href="https://en.wikipedia.org/wiki/Divide-and-conquer_algorithm" target="_blank">Divide and
conquer</a>.
It's a performant strategy also used by other sorting algorithms, such as <a
href="/merge.html">Merge
Sort</a>.
</p>
</div>
<div class="comp-table">
<div style="font-family: 'Jura', Courier, monospace; font-size: 35px;">COMPLEXITY</div>
<table class="sort-table">
<tbody>
<tr>
<th>
Average Complexity
</th>
<td>
O(n × log n)
</td>
</tr>
<tr>
<th>
Best Case
</th>
<td>
O(n × log n)
</td>
</tr>
<tr>
<th>
Worst Case
</th>
<td>
O(n<sup>2</sup>)
</td>
</tr>
<tr>
<th>
Space Complexity
</th>
<td>
O(n)
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="menu-box">
<div style="font-family: 'Jura', Courier, monospace; font-size: 35px;">IMPLEMENTATIONS (C++)</div>
<div id="menu-code">
<div class="code pt-5">
<pre>
void swap(int* a, int* b)
{
int t = *a;
*a = *b;
*b = t;
}
int partition (int arr[], int low, int high)
{
int pivot = arr[high];
int i = (low - 1);
for (int j = low; j <= high- 1; j++) {
if (arr[j] <=pivot) {
i++;
swap(&arr[i], &arr[j]);
}
}
swap(&arr[i + 1],&arr[high]);
return (i + 1);
}
void quickSort(int arr[], int low, int high) {
if (low < high) {
int pivot=partition(arr, low, high);
quickSort(arr, low, pivot - 1);
quickSort(arr, pivot + 1, high);
}
}
</pre>
</div>
</div>
</div>
</div>
<footer class="footer bg-dark">
<div class="container">
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 h-4 text-secondary ">
<div class="float-start">© Pravocodes</div>
<div class="float-end">
<div class="d-flex footer-content">
<img src="/images/Github_icon.png" alt="">
<p>Github</p>
</div>
</div>
</footer>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<script src="script.js"></script>
</body>
</html>