-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2351 lines (2007 loc) · 89.2 KB
/
index.html
File metadata and controls
2351 lines (2007 loc) · 89.2 KB
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sortieralgorithmen</title>
<!-- bootstrap-->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.7/codemirror.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Sortieralgorithmen visualisiert">
<meta name="keywords" content="Sortieralgorithmen, Sortieren, Algorithmen, Visualisierung">
<meta name="author" content="Leon Rabe">
<!-- meta tags für den link-->
<meta property="og:title" content="Sortieralgorithmen">
<meta property="og:description" content="Sortieralgorithmen visualisiert">
<meta property="og:image" content="https://image2.slideserve.com/5308501/sortieralgorithmen-l.jpg">
<meta property="og:type" content="website">
<meta property="og:site_name" content="Sortieralgorithmen">
<meta property="og:locale" content="de_DE">
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap');
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: #f7f9fa;
}
::-webkit-scrollbar-thumb {
background: #888;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
body {
font-family: 'Poppins', sans-serif;
background: #f7f9fa;
color: #333;
}
#sortArea{
height: 100%;
display: flex;
overflow: hidden;
align-items: flex-end;
}
#sort{
min-height: 200px;
height: calc(100vh - 240px);
border: 1px solid black;
margin: 0 10px 10px;
display: flex;
flex-direction: column;
background: #efefef;
border-radius: 5px;
overflow: hidden;
}
#sortArea > div{
background: black;
transition: height 0.15s, opacity 0.15s, border 0.15s;
overflow: hidden;
}
.bar-selected{
opacity: 0.75;
border-left: 1px solid white;
border-right: 1px solid white;
}
#sortArea > div:hover{
opacity: 0.75;
border-left: 1px solid white;
border-right: 1px solid white;
}
label{
margin-bottom: 0;
}
.line{
border-top: 1px solid black;
margin: 10px 0;
}
#explanation h2{
margin-top: 20px;
font-weight: bold;
}
#explanation h3{
margin-top: 40px;
}
#explanation h3:after{
content: "";
display: block;
width: 100%;
height: 1px;
background: black;
margin-top: 5px;
}
#explanation h5{
margin-top: 25px;
}
table{
width: 100%;
/*alle spalten gleich breit aber nicht zu klein*/
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
th{
background: #9f9f9f;
}
#explanation > div > div{
margin-top: 10px;
width: 100%;
}
#explanation > div > div > a > img{
max-height: 300px;
width: 100%;
/*bild format beibehalten*/
object-fit: contain;
max-width: 500px;
margin-top: 10px;
background: #f6f7f8;
border-radius: 5px;
}
header {
background-color: #f2f3f4;
padding: 20px;
text-align: center;
border-bottom: 1px solid #dee2e6;
overflow-wrap: break-word;
hyphens: auto;
}
.header-container {
max-width: 960px;
margin: 0 auto;
}
header h1 {
font-size: 2.5em;
margin-bottom: 0.5em;
}
header p {
font-size: 1.2em;
color: #6c757d;
}
pre{
border-radius: 5px;
}
:not(pre)>code[class*=language-], pre[class*=language-] {
background: #ffffff;
}
.CodeMirror {
height: auto;
border: 1px solid #ccc;
}
</style>
</head>
<header>
<div class="header-container">
<h1>Sortieralgorithmen Visualisierung</h1>
<p>Eine Webanwendung zur Visualisierung verschiedener Sortieralgorithmen</p>
</div>
</header>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-javascript.min.js"></script>
<div style="display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 10px">
<p><span style="color: blue">■</span> <span>Lesen</span></p>
<p><span style="color: red">■</span> <span>Tauschen</span></p>
<p><span style="color: yellow">■</span> <span>Schreiben</span></p>
<p><span style="color: green">■</span> <span>Fertig</span></p>
</div>
<div id="sort">
<div>
<span style="color: blue">■</span> Reads: <span id="reads" style="font-variant-numeric: tabular-nums; font-family: 'Courier New', Courier, monospace; font-weight: 600">0</span> |
<span style="color: yellow">■</span><span style="color: red">■</span><span style="font-size: 10px"></span> Writes: <span id="writes" style="font-variant-numeric: tabular-nums; font-family: 'Courier New', Courier, monospace; font-weight: 600">0</span> |
Without Async Delay: <span id="delay" style="font-variant-numeric: tabular-nums; font-family: 'Courier New', Courier, monospace; font-weight: 600">0</span>
<button onclick="resetStats()" class="btn btn-danger" style="height: 20px; font-size: 11px; padding: 0 4px; margin: 0 5px">
Reset
</button>
</div>
<div id="sortArea">
</div>
<div id="tableContainer">
</div>
</div>
<div class="container">
<div style="display: flex; align-items: center; margin: 10px 0; justify-content: space-evenly; flex-wrap: wrap; gap: 10px">
<div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap">
<div class="input-group" style="width: auto">
<label class="input-group-text" for="input">How many Bars:</label>
<input type="number" class="form-control" id="input" placeholder="How many Bars" min="2" value="256" max="5000" style="width: 100px; flex: none" onchange="createBars(this.value)">
</div>
<label for="twiceNumbers">Twice Numbers</label>
<input type="checkbox" id="twiceNumbers" class="" style="margin-left: 10px">
</div>
<div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap">
<button onclick="createBars(document.getElementById('input').value)" class="btn btn-primary">
Create Bars
</button>
<button id="stopButton" class="btn btn-danger" onclick="stopSorting()" style="width: 125px">Stop Sorting</button>
</div>
</div>
<div style="display: flex; align-items: center; margin: 10px 0; justify-content: space-evenly; flex-wrap: wrap; gap: 10px">
<div style="display: flex; align-items: center; gap: 10px;">
<label for="speed" id="speedLabel">Delay: </label>
<input type="checkbox" id="delayEnabled" style="margin-right: 10px" title="Wenn deaktiviert, wird der Algorithmus ohne Verzögerung ausgeführt (Nur die Systemgeschwindigkeit)" checked>
<input type="range" min="1" max="1000" value="20" step="1" oninput="updateSpeed()" id="speed" style="width: 250px" class="custom-range" title="Delay in ms">
</div>
<div>
<label for="highlightCorrect" id="algorithmLabel">Highlight Correct: </label>
<input type="checkbox" id="highlightCorrect" style="margin-right: 10px" title="Wenn aktiviert, werden die Balken grün, wenn sie an der richtigen Position sind" checked onclick="
let bars = document.getElementById('sortArea').children;
for(let i = 0; i < bars.length; i++){
setDefaultColor(i);
}
if (!this.checked){
if (isSorted()){
bars[at].style.backgroundColor = 'green';
}else {
bars[at].style.backgroundColor = 'black';
}
}
">
<label for="playSound">Play Sound: </label>
<input type="checkbox" id="playSound" style="margin-right: 10px" title="Wenn aktiviert, wird ein Sound abgespielt, wenn ein Balken getauscht wird" checked>
</div>
</div>
<span style="width: 100%; text-align: center; display: block;">
<b>Inputs</b> (Yellow buttons add equal values):
</span>
<div style="display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin-bottom: 20px">
<button onclick="shuffle()" class="btn btn-primary">
Shuffle
</button>
<button onclick="reverse()" class="btn btn-primary">
Reverse
</button>
<button onclick="sawtoothInputs()" class="btn btn-primary">
Sawtooth
</button>
<button onclick="sineWaveInputs()" class="btn btn-warning">
Set Sin Wave
</button>
<button onclick="cosineWaveInputs()" class="btn btn-warning">
Set Cos Wave
</button>
<button onclick="setTriangleInputs()" class="btn btn-warning">
Set Triangle
</button>
<button onclick="addLowRandomChangesToInputs()" class="btn btn-warning">
Add Low Random Changes
</button>
</div>
<span style="width: 100%; text-align: center; display: block;">
<b>Sortieralgorithmen:</b>
</span>
<div style="display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap">
<!-- Sortieralgorithmen-->
<button onclick="bogoSort()" class="btn btn-secondary">
Bogo Sort
</button>
<button onclick="bubbleSort()" class="btn btn-secondary">
Bubble Sort
</button>
<button onclick="minSort()" class="btn btn-secondary">
Min Sort
</button>
<button onclick="selectionSort()" class="btn btn-secondary">
Selection Sort
</button>
<button onclick="insertionSort()" class="btn btn-secondary">
Insertion Sort
</button>
<button onclick="mergeSort()" class="btn btn-secondary">
Merge Sort
</button>
<button onclick="quickSort()" class="btn btn-secondary">
Quick Sort
</button>
<button onclick="heapSort()" class="btn btn-secondary">
Heap Sort
</button>
<button onclick="radixSort()" class="btn btn-secondary">
Radix Sort
</button>
<button onclick="shellSort()" class="btn btn-secondary">
Shell Sort
</button>
<button onclick="countingSort()" class="btn btn-secondary">
Counting Sort
</button>
<button onclick="cocktailSort()" class="btn btn-secondary">
Cocktail Sort
</button>
<button onclick="combSort()" class="btn btn-secondary">
Comb Sort
</button>
<button onclick="gnomeSort()" class="btn btn-secondary">
Gnome Sort
</button>
<button onclick="oddEvenSort()" class="btn btn-secondary">
Odd-Even Sort
</button>
<button onclick="cycleSort()" class="btn btn-secondary">
Cycle Sort
</button>
<button onclick="stoogeSort()" class="btn btn-secondary">
Stooge Sort
</button>
<button onclick="pancakeSort()" class="btn btn-secondary">
Pancake Sort
</button>
</div>
<br>
<div class="line"> </div>
<h3>Eigener Algorithmus:</h3>
<label for="code">JavaScript</label><textarea id="code" name="code">
//Anleitung:
//Verwenden Sie die gegebenen Funktionen, um die Balken zu animieren
//Die gegebenen Funktionen benötigen ein await, um die Animation zu verzögern
//Wenn eigene Funktionen erstellt werden, müssen diese asynchron sein
//gegebene Funktionen:
//await swap(i, j): Vertauscht die Balken an den Positionen i und j.
//await readAt(i): Gibt den wert an der Position i zurück.
//await writeAt(i, value): Schreibt den Wert value an die Position i.
//Globale Variablen:
//array: Das Array, das sortiert werden soll.
//n: Die Länge des Arrays.
async function mySort(){
for(let i = 0; i < n; i++){
let min = i;
for(let j = i+1; j < n; j++){
if(await readAt(j) < await readAt(min)){
min = j;
}
}
if(min !== i){
await swap(i, min);
}
}
}
mySort();</textarea>
<a href="#sort" onclick="runCode()" class="btn btn-primary mt-2">Run Code</a>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.7/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.7/mode/javascript/javascript.min.js"></script>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
mode: "javascript",
theme: "default"
});
async function runCode() {
var array = valueArray;
var n = array.length;
var code = editor.getValue();
try {
await eval(code);
} catch (e) {
console.error(e);
alert('Error: ' + e.message);
}
}
</script>
<div class="line"> </div>
</div>
<div class="container" id="explanation">
<h2>Erklärungen: <span style="font-size: 10px">Texte von ChatGPT</span></h2>
<div>
<h3>Sortieralgorithmen:</h3>
<p>Sortieralgorithmen sind Algorithmen, die eine Liste von Elementen in einer bestimmten Reihenfolge anordnen. Es gibt viele verschiedene Sortieralgorithmen, die sich in ihrer Effizienz, ihrem Speicherbedarf und ihrer Stabilität unterscheiden. Einige der bekanntesten Sortieralgorithmen sind hier aufgeführt.</p>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> Die Zeitkomplexität eines Algorithmus gibt an, wie sich die Laufzeit des Algorithmus in Abhängigkeit von der Größe der Eingabe verhält. Sie wird oft in der sogenannten Big-O-Notation angegeben, die das Wachstum des Algorithmus in Bezug auf die Anzahl der Elemente in der Eingabe beschreibt.
<ul>
<li>
<strong>O</strong> steht dabei für "Ordnung von" und gibt an, wie schnell der Algorithmus im schlimmsten Fall ausgeführt wird. Zum Beispiel bedeutet O(n^2), dass der Algorithmus quadratisch wächst, was bedeutet, dass die Laufzeit quadratisch mit der Anzahl der Elemente in der Eingabe zunimmt.
</li>
<li>
<strong>n</strong> steht dabei für die Anzahl der Elemente in der Eingabe.
</li>
<li>
<strong>k</strong> steht für die Anzahl der möglichen Werte, die die Elemente annehmen können.
</li>
</ul>
</li>
<li><strong>Autor:</strong> Der Autor des Algorithmus, falls bekannt.</li>
<li><strong>Jahr:</strong> Das Jahr, in dem der Algorithmus entwickelt wurde.</li>
</ul>
<h5>Benutzte Farben:</h5>
<ul>
<li><span style="color: blue">■</span> Lesen: Ein Lesezugriff auf ein Element der Liste.</li>
<li><span style="color: red">■</span> Tauschen: Ein Tauschvorgang zwischen zwei Elementen der Liste.</li>
<li><span style="color: yellow">■</span> Schreiben: Ein Schreibzugriff auf ein Element der Liste.</li>
<li><span style="color: green">■</span> Fertig: Ein Element ist an der richtigen Position.</li>
</ul>
<h5>Benutzte Methoden der Math Klasse:</h5>
<ul>
<li><strong><a href="https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Math/random" target="_blank" style="text-decoration: underline">Math.random()</a></strong>: Gibt eine Pseudozufallszahl zwischen 0 und 1 zurück.</li>
<li><strong><a href="https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Math/floor" target="_blank" style="text-decoration: underline">Math.floor()</a></strong>: Rundet eine Zahl auf die nächstkleinere Ganzzahl ab.</li>
<li><strong><a href="https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Math/max" target="_blank" style="text-decoration: underline">Math.max()</a></strong>: Gibt die größte Zahl einer Liste von Zahlen zurück.</li>
<li><strong><a href="https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Math/min" target="_blank" style="text-decoration: underline">Math.min()</a></strong>: Gibt die kleinste Zahl einer Liste von Zahlen zurück.</li>
</ul>
<h5>Eigene Methoden:</h5>
<ul>
<li><strong>swap(i, j)</strong>: Vertauscht die Balken an den Positionen i und j.</li>
</ul>
</div>
<div>
<h3>Shuffle</h3>
<p>Der Shuffle-Algorithmus ist ein einfacher Algorithmus, der die Elemente einer Liste zufällig neu anordnet. Er wird oft verwendet, um eine Liste vorzubereiten, bevor ein Sortieralgorithmus angewendet wird, um sicherzustellen, dass der Algorithmus nicht von der ursprünglichen Reihenfolge der Elemente beeinflusst wird.</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> O(n)</li>
</ul>
</div>
<h5>Psuedocode:</h5>
<pre class=" p-2"><code class="language-javascript">for i from 0 to n-1:
randomIndex = random number between i and n-1
swap elements at index i and randomIndex</code></pre>
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">for(let i = 0; i < n; i++){
let randomIndex = Math.floor(Math.random() * n);
swap(i, randomIndex);
}</code></pre>
<a href="#sort" onclick="(async () => { createBars(64); await shuffle(); })()" class="btn btn-success">Teste den Shuffle</a>
</div>
<div>
<h3>Bogo Sort:</h3>
<p>Der Bogo Sort, auch bekannt als Permutation Sort oder Monkey Sort, ist ein äußerst ineffizienter Sortieralgorithmus, der die Elemente einer Liste zufällig neu anordnet und prüft, ob sie sortiert sind. Dieser Prozess wird so lange wiederholt, bis die Liste sortiert ist. Aufgrund seiner zufälligen Natur und der Tatsache, dass er im schlimmsten Fall eine nahezu unendliche Anzahl von Permutationen durchlaufen muss, hat der Bogo Sort keinen praktischen Nutzen und wird meist als Lehrbeispiel verwendet, um zu zeigen, wie ineffizient ein Algorithmus sein kann.</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität im besten Fall:</strong> O(n)</li>
<li><strong>Zeitkomplexität im schlechtesten Fall:</strong> Unendlich</li>
</ul>
</div>
Wikipedia: <a href="https://de.wikipedia.org/wiki/Bogosort" target="_blank">Bogo Sort</a>
<h5>Psuedocode:</h5>
<pre class=" p-2"><code class="language-javascript">while(!isSorted()){
shuffle();
}
</code></pre>
<!-- JavaScript-->
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">while(!isSorted()){
shuffle();
}
</code></pre>
<div>
<h5>Beispiel:</h5>
<a href="https://upload.wikimedia.org/wikipedia/commons/0/0e/ExperimentalBogosort.png" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/0/0e/ExperimentalBogosort.png" alt="" loading="lazy">
</a>
</div>
<a href="#sort" onclick="(async () => { createBars(5); await shuffle(); resetStats(); await bogoSort(); })()" class="btn btn-success">Teste den Bogo Sort</a>
</div>
<div>
<h3>Bubble Sort:</h3>
<p>Der Bubble Sort ist ein einfacher, aber ineffizienter Sortieralgorithmus, der wiederholt benachbarte Elemente vergleicht und vertauscht, wenn sie in der falschen Reihenfolge sind. Dies wird so lange wiederholt, bis keine Vertauschungen mehr nötig sind, was bedeutet, dass die Liste sortiert ist. Der Name "Bubble Sort" kommt daher, dass die kleineren Elemente wie Blasen an die Oberfläche steigen.</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> O(n^2)</li>
<li><strong>Autor:</strong> Ivan Sutherland und Bob Floyd</li>
<li><strong>Jahr:</strong> 1962</li>
</ul>
</div>
Wikipedia: <a href="https://de.wikipedia.org/wiki/Bubblesort" target="_blank">Bubble Sort</a>
<h5>Psuedocode:</h5>
<pre class=" p-2"><code class="language-javascript">for i ← 0 to A[].Len-1 do
for j ← 1 to A[].Len-1 do
if A[j-1] > A[j] Then
lastJ ← A[j-1]
A[j-1] ← A[j]
A[j] ← lastJ
End if
End for
End for</code></pre>
<!-- JavaScript-->
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">for(let i = 0; i < n; i++){
for(let j = 1; j < n; j++){
if(array[j-1] > array[j]){
swap(j-1, j);
}
}
}</code></pre>
<div>
<h5>Beispiel:</h5>
<a href="https://upload.wikimedia.org/wikipedia/commons/c/c8/Bubble-sort-example-300px.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c8/Bubble-sort-example-300px.gif" alt="" loading="lazy">
</a>
<a href="https://upload.wikimedia.org/wikipedia/commons/3/37/Bubble_sort_animation.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/3/37/Bubble_sort_animation.gif" alt="" loading="lazy">
</a>
</div>
<a href="#sort" onclick="(async () => { createBars(64); await shuffle(); resetStats(); await bubbleSort(); })()" class="btn btn-success">Teste den Bubble Sort</a>
</div>
<div>
<h3>Selection Sort:</h3>
<p>Der Selection Sort ist ein Sortieralgorithmus, der die Liste in zwei Teile teilt: den sortierten und den unsortierten Teil. Der Algorithmus wiederholt den Prozess, das kleinste Element aus dem unsortierten Teil zu finden und es an die richtige Position im sortierten Teil zu verschieben. Dieser Prozess wird fortgesetzt, bis die gesamte Liste sortiert ist.</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> O(n^2)</li>
<li><strong>Autor:</strong> Edward H. Friend</li>
<li><strong>Jahr:</strong> 1956</li>
</ul>
</div>
Wikipedia: <a href="https://de.wikipedia.org/wiki/Selectionsort" target="_blank">Selection Sort</a>
<h5>Pseudocode:</h5>
<pre class=" p-2"><code class="language-javascript">for i from 0 to n-1:
min = i
for j from i+1 to n:
if array[j] < array[min]:
min = j
if min != i:
swap elements at index i and min</code></pre>
<!-- JavaScript-->
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">for(let i = 0; i < n; i++){
let min = i;
for(let j = i+1; j < n; j++){
if(array[j] < array[min]){
min = j;
}
}
if(min !== i){
swap(i, min);
}
}</code></pre>
<div>
<h5>Beispiel:</h5>
<a href="https://upload.wikimedia.org/wikipedia/commons/9/94/Selection-Sort-Animation.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/9/94/Selection-Sort-Animation.gif" alt="" loading="lazy">
</a>
<a href="https://upload.wikimedia.org/wikipedia/commons/b/b0/Selection_sort_animation.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/b/b0/Selection_sort_animation.gif" alt="" loading="lazy">
</a>
</div>
<a href="#sort" onclick="(async () => { createBars(64); await shuffle(); resetStats(); await selectionSort(); })()" class="btn btn-success">Teste den Selection Sort</a>
</div>
<div>
<h3>Insertion Sort:</h3>
<p>Der Insertion Sort ist ein einfacher Sortieralgorithmus, der die Elemente der Liste nacheinander durchgeht und jedes Element in die richtige Position in der bereits sortierten Teilliste einfügt. Dies wird erreicht, indem man die Elemente mit den vorhergehenden Elementen vergleicht und sie so lange verschiebt, bis das aktuelle Element an der richtigen Stelle steht.</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> O(n^2)</li>
<li><strong>Autor:</strong> John von Neumann</li>
<li><strong>Jahr:</strong> 1946</li>
</ul>
</div>
Wikipedia: <a href="https://de.wikipedia.org/wiki/Insertionsort" target="_blank">Insertion Sort</a>
<h5>Psuedocode:</h5>
<pre class=" p-2"><code class="language-javascript">for i from 1 to n-1:
key = array[i]
j = i - 1
while j >= 0 and array[j] > key:
array[j+1] = array[j]
j = j - 1
array[j+1] = key</code></pre>
<!-- JavaScript-->
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">for(let i = 1; i < n; i++){
let key = array[i];
let j = i - 1;
while(j >= 0 && array[j] > key){
array[j+1] = array[j];
j = j - 1;
}
array[j+1] = key;
}</code></pre>
<div>
<h5>Beispiel:</h5>
<a href="https://upload.wikimedia.org/wikipedia/commons/0/0f/Insertion-sort-example-300px.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/0/0f/Insertion-sort-example-300px.gif" alt="" loading="lazy">
</a>
<a href="https://upload.wikimedia.org/wikipedia/commons/4/42/Insertion_sort.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/4/42/Insertion_sort.gif" alt="" loading="lazy">
</a>
</div>
<a href="#sort" onclick="(async () => { createBars(64); await shuffle(); resetStats(); await insertionSort(); })()" class="btn btn-success">Teste den Insertion Sort</a>
</div>
<div>
<h3>Merge Sort:</h3>
<p>Der Merge Sort ist ein effizienter, vergleichsbasierter Sortieralgorithmus, der auf dem Prinzip "Teile und herrsche" basiert. Er teilt die Liste wiederholt in zwei Hälften, sortiert jede Hälfte rekursiv und führt die beiden sortierten Hälften zusammen. Der Algorithmus zeichnet sich durch seine stabile Sortierung und seine Zeitkomplexität von O(n log n) aus.</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> O(n log n)</li>
<li><strong>Autor:</strong> John von Neumann</li>
<li><strong>Jahr:</strong> 1945</li>
</ul>
</div>
Wikipedia: <a href="https://de.wikipedia.org/wiki/Mergesort" target="_blank">Merge Sort</a>
<!-- JavaScript-->
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">function mergeSort(array){
if(array.length <= 1){
return array;
}
let middle = Math.floor(array.length / 2);
let left = array.slice(0, middle);
let right = array.slice(middle);
return merge(mergeSort(left), mergeSort(right));
}
function merge(left, right){
let result = [];
let i = 0;
let j = 0;
while(i < left.length && j < right.length){
if(left[i] < right[j]){
result.push(left[i]);
i++;
}else{
result.push(right[j]);
j++;
}
}
return result.concat(left.slice(i)).concat(right.slice(j));
}</code></pre>
<div>
<h5>Beispiel:</h5>
<a href="https://upload.wikimedia.org/wikipedia/commons/c/cc/Merge-sort-example-300px.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/c/cc/Merge-sort-example-300px.gif" alt="" loading="lazy">
</a>
<a href="https://upload.wikimedia.org/wikipedia/commons/c/c5/Merge_sort_animation2.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c5/Merge_sort_animation2.gif" alt="" loading="lazy">
</a>
</div>
<a href="#sort" onclick="(async () => { createBars(64); await shuffle(); resetStats(); await mergeSort(); })()" class="btn btn-success">Teste den Merge Sort</a>
</div>
<div>
<h3>Quick Sort:</h3>
<p>Der Quick Sort ist ein effizienter, vergleichsbasierter Sortieralgorithmus, der ebenfalls auf dem Prinzip "Teile und herrsche" basiert. Er wählt ein "Pivot"-Element aus der Liste aus, teilt die Liste in zwei Unterlisten – eine mit Elementen, die kleiner sind als das Pivot, und eine mit Elementen, die größer sind – und sortiert diese Unterlisten rekursiv. Der Algorithmus ist bekannt für seine gute durchschnittliche Leistung und seine Zeitkomplexität von O(n log n).</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> O(n log n)</li>
<li><strong>Autor:</strong> Tony Hoare</li>
<li><strong>Jahr:</strong> 1960</li>
</ul>
</div>
Wikipedia: <a href="https://de.wikipedia.org/wiki/Quicksort" target="_blank">Quick Sort</a>
<!-- JavaScript-->
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">function quickSort(array, low, high){
if(low < high){
let pi = partition(array, low, high);
quickSort(array, low, pi - 1);
quickSort(array, pi + 1, high);
}
}
function partition(array, low, high){
let pivot = array[high];
let i = low - 1;
for(let j = low; j < high; j++){
if(array[j] < pivot){
i++;
swap(array, i, j);
}
}
swap(array, i + 1, high);
return i + 1;
}</code></pre>
<div>
<h5>Beispiel:</h5>
<a href="https://upload.wikimedia.org/wikipedia/commons/9/9c/Quicksort-example.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/9/9c/Quicksort-example.gif" alt="" loading="lazy">
</a>
<a href="https://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif" alt="" loading="lazy">
</a>
</div>
<a href="#sort" onclick="(async () => { createBars(64); await shuffle(); resetStats(); await quickSort(); })()" class="btn btn-success">Teste den Quick Sort</a>
</div>
<div>
<h3>Heap Sort:</h3>
<p>Der Heap Sort ist ein effizienter, vergleichsbasierter Sortieralgorithmus, der die Elemente der Liste in einen Heap umwandelt und sie dann sortiert, indem er wiederholt das größte Element entfernt und an das Ende der sortierten Liste stellt.</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> O(n log n)</li>
<li><strong>Autor:</strong> J. W. J. Williams</li>
<li><strong>Jahr:</strong> 1964</li>
</ul>
</div>
Wikipedia: <a href="https://de.wikipedia.org/wiki/Heapsort" target="_blank">Heap Sort</a>
<!-- JavaScript-->
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">function heapSort(array){
let n = array.length;
for(let i = Math.floor(n / 2) - 1; i >= 0; i--){
heapify(array, n, i);
}
for(let i = n - 1; i >= 0; i--){
swap(array, 0, i);
heapify(array, i, 0);
}
}
function heapify(array, n, i){
let largest = i;
let l = 2 * i + 1;
let r = 2 * i + 2;
if(l < n && array[l] > array[largest]){
largest = l;
}
if(r < n && array[r] > array[largest]){
largest = r;
}
if(largest !== i){
swap(array, i, largest);
heapify(array, n, largest);
}
}</code></pre>
<div>
<h5>Beispiel:</h5>
<a href="https://upload.wikimedia.org/wikipedia/commons/4/4d/Heapsort-example.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/4/4d/Heapsort-example.gif" alt="" loading="lazy">
</a>
<a href="https://upload.wikimedia.org/wikipedia/commons/1/1b/Sorting_heapsort_anim.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/1/1b/Sorting_heapsort_anim.gif" alt="" loading="lazy">
</a>
</div>
<a href="#sort" onclick="(async () => { createBars(64); await shuffle(); resetStats(); await heapSort(); })()" class="btn btn-success">Teste den Heap Sort</a>
</div>
<div>
<h3>Radix Sort:</h3>
<p>Der Radix Sort ist ein nicht vergleichsbasierter Sortieralgorithmus, der die Elemente nach ihren Ziffern sortiert, beginnend mit der niederwertigsten Ziffer. Er verwendet einen stabilen Hilfssortieralgorithmus wie Counting Sort, um die Elemente basierend auf ihren Ziffern zu sortieren.</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> O(nk)</li>
<li><strong>Autor:</strong> Herman Hollerith</li>
<li><strong>Jahr:</strong> 1887</li>
</ul>
</div>
Wikipedia: <a href="https://de.wikipedia.org/wiki/Radixsort" target="_blank">Radix Sort</a>
<!-- JavaScript-->
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">function countingSort(array, exp){
let output = new Array(array.length);
let count = new Array(10).fill(0);
for(let i = 0; i < array.length; i++){
count[Math.floor(array[i] / exp) % 10]++;
}
for(let i = 1; i < 10; i++){
count[i] += count[i - 1];
}
for(let i = array.length - 1; i >= 0; i--){
output[count[Math.floor(array[i] / exp) % 10] - 1] = array[i];
count[Math.floor(array[i] / exp) % 10]--;
}
for(let i = 0; i < array.length; i++){
array[i] = output[i];
}
}
function radixSort(array){
let max = Math.max(...array);
for(let exp = 1; Math.floor(max / exp) > 0; exp *= 10){
countingSort(array, exp);
}
} </code></pre>
<div>
<h5>Beispiel:</h5>
<a href="https://upload.wikimedia.org/wikipedia/commons/0/04/%E5%9F%BA%E6%95%B0%E6%8E%92%E5%BA%8F.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/0/04/%E5%9F%BA%E6%95%B0%E6%8E%92%E5%BA%8F.gif" alt="" loading="lazy">
</a>
<a href="https://en.oi-wiki.org/basic/images/radix-sort-1.png" target="_blank">
<img src="https://en.oi-wiki.org/basic/images/radix-sort-1.png" alt="" loading="lazy">
</a>
</div>
<a href="#sort" onclick="(async () => { createBars(64); await shuffle(); resetStats(); await radixSort(); })()" class="btn btn-success">Teste den Radix Sort</a>
</div>
<div>
<h3>Shell Sort:</h3>
<p>Der Shell Sort ist ein effizienter, vergleichsbasierter Sortieralgorithmus, der die Liste in mehrere Teile teilt und diese Teile separat sortiert. Er verwendet eine sich verringernde Sequenz von Intervallen, um die Liste zu sortieren, was dazu führt, dass die Liste schneller konvergiert.</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> O(n log n)</li>
<li><strong>Autor:</strong> Donald Shell</li>
<li><strong>Jahr:</strong> 1959</li>
</ul>
</div>
Wikipedia: <a href="https://de.wikipedia.org/wiki/Shellsort" target="_blank">Shell Sort</a>
<!-- JavaScript-->
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">function shellSort(array){
let n = array.length;
for(let gap = Math.floor(n / 2); gap > 0; gap = Math.floor(gap / 2)){
for(let i = gap; i < n; i++){
let temp = array[i];
let j;
for(j = i; j >= gap && array[j - gap] > temp; j -= gap){
array[j] = array[j - gap];
}
array[j] = temp;
}
}
}</code></pre>
<div>
<h5>Beispiel:</h5>
<a href="https://upload.wikimedia.org/wikipedia/commons/d/d8/Sorting_shellsort_anim.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/d/d8/Sorting_shellsort_anim.gif" alt="" loading="lazy">
</a>
</div>
<a href="#sort" onclick="(async () => { createBars(64); await shuffle(); resetStats(); await shellSort(); })()" class="btn btn-success">Teste den Shell Sort</a>
</div>
<div>
<h3>Counting Sort:</h3>
<p>Der Counting Sort ist ein nicht vergleichsbasierter Sortieralgorithmus, der die Elemente der Liste nach ihrer Häufigkeit sortiert. Er verwendet ein Zähl-Array, um die Häufigkeit jedes Elements zu zählen und diese Zählungen dann zu verwenden, um die Elemente in die richtige Reihenfolge zu bringen.</p>
<div>
<h5>Details:</h5>
<ul>
<li><strong>Zeitkomplexität:</strong> O(n + k)</li>
<li><strong>Jahr:</strong> Unbekannt</li>
</ul>
</div>
Wikipedia: <a href="https://de.wikipedia.org/wiki/Countingsort" target="_blank">Counting Sort</a>
<!-- JavaScript-->
<h5>JavaScript:</h5>
<pre class=" p-2"><code class="language-javascript">function countingSort(array){
let n = array.length;
let max = Math.max(...array);
let min = Math.min(...array);
let range = max - min + 1;
let count = new Array(range).fill(0);
let output = new Array(n).fill(0);
for(let i = 0; i < n; i++){
count[array[i] - min]++;
}
for(let i = 1; i < count.length; i++){
count[i] += count[i - 1];
}
for(let i = n - 1; i >= 0; i--){
output[count[array[i] - min] - 1] = array[i];
count[array[i] - min]--;
}
for(let i = 0; i < n; i++){
array[i] = output[i];
}
} </code></pre>
<div>
<h5>Beispiel:</h5>
<a href="https://upload.wikimedia.org/wikipedia/commons/6/60/Counting_Sort_Animation.gif" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/6/60/Counting_Sort_Animation.gif" alt="" loading="lazy">
</a>
<a href="https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210219152324/ezgif.com-gif-maker2.gif" target="_blank">
<img src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210219152324/ezgif.com-gif-maker2.gif" alt="" loading="lazy">
</a>
</div>
<a href="#sort" onclick="(async () => { createBars(64); await shuffle(); resetStats(); await countingSort(); })()" class="btn btn-success">Teste den Counting Sort</a>
</div>
<div>
<h3>Cocktail Sort:</h3>