Spaces:
Running
Running
File size: 11,719 Bytes
d961f8b | 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sorting Algorithms - Algorithm Animator</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>
<style>
body {
background-color: #0f172a;
color: #e2e8f0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.algorithm-selector {
background-color: #1e293b;
border-radius: 8px;
transition: all 0.3s ease;
}
.algorithm-selector:hover {
background-color: #334155;
}
.active-algorithm {
background-color: #334155;
border-left: 4px solid #60a5fa;
}
.visualization-area {
background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.array-bar {
background: linear-gradient(to top, #3b82f6, #60a5fa);
border-radius: 4px 4px 0 0;
transition: height 0.3s ease, background-color 0.3s ease;
}
.comparing {
background: linear-gradient(to top, #f59e0b, #fbbf24);
}
.swapping {
background: linear-gradient(to top, #ef4444, #f87171);
}
.sorted {
background: linear-gradient(to top, #10b981, #34d399);
}
.code-block {
background-color: #1e293b;
border-left: 4px solid #60a5fa;
font-family: 'Fira Code', monospace;
}
.complexity-badge {
background-color: #334155;
}
</style>
</head>
<body class="min-h-screen">
<!-- Navigation -->
<nav class="bg-slate-900 border-b border-slate-700 sticky top-0 z-50">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between h-16">
<div class="flex items-center">
<div class="flex-shrink-0 flex items-center">
<i data-feather="cpu" class="text-blue-400 mr-2"></i>
<span class="font-bold text-xl text-white">Algorithm Animator</span>
</div>
<div class="hidden md:block">
<div class="ml-10 flex items-baseline space-x-4">
<a href="index.html" class="text-gray-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium">Home</a>
<a href="#" class="text-white px-3 py-2 rounded-md text-sm font-medium">Sorting</a>
<a href="graph.html" class="text-gray-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium">Graph Algorithms</a>
<a href="dynamic.html" class="text-gray-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium">Dynamic Programming</a>
</div>
</div>
</div>
</div>
</div>
</nav>
<!-- Main Content -->
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div class="text-center mb-10">
<h1 class="text-3xl font-extrabold text-white sm:text-4xl">
Sorting Algorithms Visualization
</h1>
<p class="mt-3 max-w-2xl mx-auto text-xl text-gray-300">
Understand how different sorting algorithms work through interactive visualizations
</p>
</div>
<div class="flex flex-col lg:flex-row gap-8">
<!-- Algorithm Selection Panel -->
<div class="lg:w-1/4">
<div class="bg-slate-800 rounded-lg p-6 sticky top-24">
<h2 class="text-xl font-bold text-white mb-4">Sorting Algorithms</h2>
<div class="space-y-3">
<div class="algorithm-selector p-4 cursor-pointer active-algorithm">
<h3 class="font-medium text-white">Bubble Sort</h3>
<p class="text-sm text-gray-300 mt-1">Simple comparison-based algorithm</p>
</div>
<div class="algorithm-selector p-4 cursor-pointer">
<h3 class="font-medium text-white">Merge Sort</h3>
<p class="text-sm text-gray-300 mt-1">Divide and conquer approach</p>
</div>
<div class="algorithm-selector p-4 cursor-pointer">
<h3 class="font-medium text-white">Quick Sort</h3>
<p class="text-sm text-gray-300 mt-1">Efficient partitioning algorithm</p>
</div>
<div class="algorithm-selector p-4 cursor-pointer">
<h3 class="font-medium text-white">Heap Sort</h3>
<p class="text-sm text-gray-300 mt-1">Uses binary heap data structure</p>
</div>
<div class="algorithm-selector p-4 cursor-pointer">
<h3 class="font-medium text-white">Insertion Sort</h3>
<p class="text-sm text-gray-300 mt-1">Builds final sorted array one item at a time</p>
</div>
</div>
<div class="mt-8">
<h3 class="font-medium text-white mb-3">Controls</h3>
<div class="grid grid-cols-2 gap-3">
<button class="bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded">
Play
</button>
<button class="bg-slate-700 hover:bg-slate-600 text-white py-2 px-4 rounded">
Pause
</button>
<button class="bg-slate-700 hover:bg-slate-600 text-white py-2 px-4 rounded">
Reset
</button>
<button class="bg-slate-700 hover:bg-slate-600 text-white py-2 px-4 rounded">
Step
</button>
</div>
</div>
<div class="mt-8">
<h3 class="font-medium text-white mb-3">Array Size</h3>
<input type="range" min="5" max="50" value="15" class="w-full">
<div class="flex justify-between text-sm text-gray-400 mt-1">
<span>Small</span>
<span>Large</span>
</div>
</div>
</div>
</div>
<!-- Visualization Area -->
<div class="lg:w-3/4">
<div class="visualization-area p-6 rounded-xl">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-white">Bubble Sort Visualization</h2>
<div class="flex space-x-3">
<div class="complexity-badge px-3 py-1 rounded-full text-sm">
Time: O(n²)
</div>
<div class="complexity-badge px-3 py-1 rounded-full text-sm">
Space: O(1)
</div>
</div>
</div>
<!-- Array Visualization -->
<div class="mb-8">
<div class="flex items-end justify-center h-64 space-x-1">
<!-- Bars representing array elements -->
<div class="array-bar w-8 h-32"></div>
<div class="array-bar w-8 h-24"></div>
<div class="array-bar w-8 h-40 comparing"></div>
<div class="array-bar w-8 h-28 swapping"></div>
<div class="array-bar w-8 h-36"></div>
<div class="array-bar w-8 h-20"></div>
<div class="array-bar w-8 h-44"></div>
<div class="array-bar w-8 h-32 sorted"></div>
<div class="array-bar w-8 h-24"></div>
<div class="array-bar w-8 h-36"></div>
</div>
</div>
<!-- Current Step Description -->
<div class="bg-slate-800 rounded-lg p-4 mb-6">
<h3 class="font-bold text-white mb-2">Current Step</h3>
<p class="text-gray-300">Comparing elements at positions 2 and 3. Since 40 > 28, we swap them.</p>
</div>
<!-- Pseudocode -->
<div class="code-block p-4 rounded mb-6">
<h3 class="font-bold text-white mb-2">Pseudocode</h3>
<pre class="text-green-400 text-sm">
for i = 0 to n-1:
for j = 0 to n-i-2:
if array[j] > array[j+1]:
swap(array[j], array[j+1])</pre>
</div>
<!-- Mathematical Explanation -->
<div class="bg-slate-800 rounded-lg p-4">
<h3 class="font-bold text-white mb-3">Mathematical Analysis</h3>
<div class="math-display text-blue-300">
\( \text{Worst Case: } O(n^2) \)
</div>
<p class="text-gray-300 mt-3">
In the worst case (reverse sorted array), bubble sort requires \( n-1 \) passes,
with the \( i^{th} \) pass making \( n-i \) comparisons. The total number of
comparisons is:
</p>
<div class="math-display text-blue-300">
\( \sum_{i=1}^{n-1}(n-i) = \frac{n(n-1)}{2} = O(n^2) \)
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Footer -->
<footer class="bg-slate-900 border-t border-slate-800 mt-12">
<div class="max-w-7xl mx-auto py-12 px-4 sm:px-6 lg:px-8">
<div class="md:flex md:items-center md:justify-between">
<div class="flex justify-center md:justify-start">
<div class="flex items-center">
<i data-feather="cpu" class="text-blue-400 mr-2"></i>
<span class="text-white font-bold">Algorithm Animator</span>
</div>
</div>
<div class="mt-8 md:mt-0 md:order-1">
<p class="text-center text-base text-gray-400">
© 2023 Algorithm Animator. All rights reserved.
</p>
</div>
</div>
</div>
</footer>
<script>
feather.replace();
</script>
</body>
</html>
|