-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualization.html
More file actions
2195 lines (2103 loc) · 112 KB
/
Copy pathvisualization.html
File metadata and controls
2195 lines (2103 loc) · 112 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">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Learn Alpay's Advanced Fractal Sort algorithm through an interactive game. Visualize and understand this innovative O(n log log n) sorting method with hands-on challenges.">
<meta name="keywords" content="sorting algorithm, fractal sort, algorithm visualization, computer science, educational game, Alpay's Advanced Fractal Sort">
<meta name="author" content="Algorithm Visualizer">
<meta name="robots" content="index, follow">
<!-- Open Graph / Social Media -->
<meta property="og:type" content="website">
<meta property="og:title" content="Alpay's Fractal Sort: Interactive Algorithm Game">
<meta property="og:description" content="Master the innovative Alpay's Advanced Fractal Sort algorithm through an interactive visualization game. Perfect for computer science students and algorithm enthusiasts.">
<meta property="og:url" content="https://yourdomain.com/fractal-sort-game">
<meta property="og:image" content="https://yourdomain.com/images/fractal-sort-preview.jpg">
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Alpay's Fractal Sort: Interactive Algorithm Game">
<meta name="twitter:description" content="Master the innovative Alpay's Advanced Fractal Sort algorithm through an interactive visualization game.">
<meta name="twitter:image" content="https://yourdomain.com/images/fractal-sort-preview.jpg">
<title>Alpay's Fractal Sort: Interactive Algorithm Visualization Game</title>
<!-- Favicon -->
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22%3E%3Ctext y=%22.9em%22 font-size=%2290%22%3E%F0%9F%94%84%3C/text%3E%3C/svg%3E">
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&family=Montserrat:wght@700;800;900&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
/* ========================
THEME & BASE STYLES
======================== */
:root {
--bg-primary: #0f172a;
--bg-secondary: #1e293b;
--bg-tertiary: #334155;
--text-primary: #f8fafc;
--text-secondary: #94a3b8;
--accent-primary: #6366f1;
--accent-secondary: #8b5cf6;
--accent-tertiary: #ec4899;
--accent-quaternary: #06b6d4;
--success: #10b981;
--warning: #f59e0b;
--danger: #ef4444;
--border-radius-sm: 8px;
--border-radius: 12px;
--border-radius-lg: 16px;
--transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
--box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
--box-shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
--gradient-primary: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
--gradient-secondary: linear-gradient(135deg, var(--accent-tertiary), var(--accent-quaternary));
--bg-secondary-rgb: 30, 41, 59;
}
[data-theme="light"] {
--bg-primary: #f8fafc;
--bg-secondary: #e2e8f0;
--bg-tertiary: #cbd5e1;
--text-primary: #0f172a;
--text-secondary: #334155;
--bg-secondary-rgb: 226, 232, 240;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Poppins', sans-serif;
background-color: var(--bg-primary);
color: var(--text-primary);
line-height: 1.6;
overflow-x: hidden;
min-height: 100vh;
background-image: radial-gradient(circle at 20% 30%, rgba(99,102,241,0.15) 0%, transparent 30%),
radial-gradient(circle at 80% 70%, rgba(139,92,246,0.15) 0%, transparent 30%),
radial-gradient(circle at 50% 50%, rgba(236,72,153,0.1) 0%, transparent 50%);
background-attachment: fixed;
transition: var(--transition);
}
*:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }
.container { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }
.skip-link { position: absolute; top: -40px; left: 0; background: var(--accent-primary); color: white; padding: 8px; z-index: 100; transition: top 0.3s; }
.skip-link:focus { top: 0; }
/* ========================
HEADER
======================== */
header { position: relative; text-align: center; margin-bottom: 3rem; padding-top: 2rem; }
.theme-toggle {
position: absolute; top: 1rem; right: 1rem;
background: var(--bg-secondary); border: none; color: var(--text-primary);
padding: 0.5rem; border-radius: 50%; width: 40px; height: 40px;
cursor: pointer; display: flex; align-items: center; justify-content: center;
transition: var(--transition); box-shadow: var(--box-shadow);
}
.theme-toggle:hover { transform: scale(1.1); }
.title {
font-family: 'Montserrat', sans-serif; font-size: clamp(2.5rem, 5vw, 3.5rem);
font-weight: 800; margin-bottom: 0.5rem; line-height: 1.2;
background: var(--gradient-primary); -webkit-background-clip: text; background-clip: text;
color: transparent; text-shadow: 0 0 20px rgba(99,102,241,0.3); letter-spacing: -0.5px;
}
.subtitle { font-size: clamp(1rem, 2vw, 1.2rem); color: var(--text-secondary); font-weight: 300; max-width: 800px; margin: 0 auto 1rem; }
/* ========================
MAIN NAVIGATION
======================== */
.main-nav { display: flex; justify-content: center; margin: 2rem 0; flex-wrap: wrap; gap: 0.5rem; }
.nav-tab {
background: var(--bg-secondary); color: var(--text-primary); border: none; padding: 0.6rem 1.2rem;
border-radius: var(--border-radius); font-family: 'Poppins', sans-serif; font-weight: 500; cursor: pointer;
transition: var(--transition-fast);
}
.nav-tab:hover { background: var(--bg-tertiary); }
.nav-tab.active { background: var(--gradient-primary); color: white; }
/* ========================
GAME CONTROLS
======================== */
.game-controls {
display: flex; justify-content: center; gap: 1rem; margin: 1.5rem 0; flex-wrap: wrap;
position: sticky; top: 0; z-index: 10; padding: 1rem;
background: rgba(15,23,42,0.8); backdrop-filter: blur(10px);
border-radius: var(--border-radius); box-shadow: var(--box-shadow);
}
[data-theme="light"] .game-controls { background: rgba(248,250,252,0.8); }
.btn {
background: var(--bg-secondary); color: var(--text-primary); border: none;
padding: 0.8rem 1.5rem; border-radius: var(--border-radius);
font-family: 'Poppins', sans-serif; font-weight: 500; cursor: pointer;
transition: var(--transition); display: flex; align-items: center; gap: 0.5rem;
box-shadow: var(--box-shadow); min-width: 140px; justify-content: center;
position: relative; overflow: hidden;
}
.btn::before {
content: ''; position: absolute; top: 0; left: -100%;
width: 100%; height: 100%;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
transition: left 0.7s;
}
.btn:hover::before { left: 100%; }
.btn:hover { transform: translateY(-2px); box-shadow: var(--box-shadow-lg); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--gradient-primary); color: white; }
.btn-secondary { background: var(--bg-tertiary); }
.btn-action { background: var(--gradient-secondary); color: white; }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; padding: 0; border-radius: 50%; min-width: unset; }
.slider-container { display: flex; align-items: center; gap: 0.5rem; }
.slider-label { font-size: 0.9rem; color: var(--text-secondary); min-width: 100px; }
input[type="range"] {
-webkit-appearance: none; appearance: none;
width: 150px; height: 8px; background: var(--bg-secondary);
border-radius: 5px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none; appearance: none;
width: 20px; height: 20px; border-radius: 50%;
background: var(--accent-primary); cursor: pointer;
transition: var(--transition-fast);
}
input[type="range"]::-webkit-slider-thumb:hover {
transform: scale(1.1); background: var(--accent-secondary);
}
/* ========================
PROGRESS BAR
======================== */
.progress-container { width: 100%; height: 6px; background: var(--bg-secondary); border-radius: 3px; overflow: hidden; margin: 1.5rem 0; }
.progress-bar {
height: 100%; background: var(--gradient-primary); width: 0;
transition: width 0.5s ease; border-radius: 3px; position: relative;
}
.progress-bar::after {
content: ''; position: absolute; top: 0; right: 0; bottom: 0;
width: 100px; background: linear-gradient(to right, transparent, rgba(255,255,255,0.3));
transform: translateX(100%); animation: shimmer 2s infinite;
}
@keyframes shimmer { 100% { transform: translateX(-100%); } }
/* ========================
STATS PANEL
======================== */
.stats-panel {
display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem; margin-bottom: 2rem;
}
.stat-card {
background: var(--bg-secondary); padding: 1.5rem; border-radius: var(--border-radius);
text-align: center; box-shadow: var(--box-shadow); transition: var(--transition);
border-top: 4px solid var(--accent-primary);
}
.stat-card:nth-child(2) { border-top-color: var(--accent-secondary); }
.stat-card:nth-child(3) { border-top-color: var(--accent-tertiary); }
.stat-card:hover { transform: translateY(-5px); box-shadow: var(--box-shadow-lg); }
.stat-value {
font-size: 2rem; font-weight: 700; margin: 0.5rem 0;
font-family: 'JetBrains Mono', monospace;
background: var(--gradient-primary); -webkit-background-clip: text;
background-clip: text; color: transparent;
}
.stat-label {
font-size: 0.9rem; color: var(--text-secondary);
font-weight: 500; text-transform: uppercase; letter-spacing: 1px;
}
.stat-icon {
background: var(--bg-tertiary); width: 40px; height: 40px;
border-radius: 50%; display: flex; align-items: center; justify-content: center;
margin: 0 auto 0.5rem;
}
/* ========================
GAME BOARD
======================== */
.game-board {
background: rgba(var(--bg-secondary-rgb), 0.8);
border-radius: var(--border-radius-lg); padding: 2rem;
margin-bottom: 3rem; box-shadow: var(--box-shadow-lg); position: relative;
overflow: hidden; min-height: 600px; backdrop-filter: blur(10px);
border: 1px solid rgba(255,255,255,0.1); transition: var(--transition);
}
.game-board::before {
content: ''; position: absolute; top: 0; left: 0;
width: 100%; height: 100%;
background: linear-gradient(45deg, rgba(99,102,241,0.05), rgba(236,72,153,0.05));
z-index: -1;
}
.game-tabs {
display: flex; border-bottom: 2px solid var(--bg-tertiary);
margin-bottom: 2rem; overflow-x: auto; padding-bottom: 0.5rem;
}
.game-tab {
padding: 0.8rem 1.5rem; background: none; border: none;
color: var(--text-secondary); font-weight: 500; cursor: pointer;
transition: var(--transition-fast); position: relative; white-space: nowrap;
}
.game-tab:hover { color: var(--text-primary); }
.game-tab.active { color: var(--accent-primary); }
.game-tab.active::after {
content: ''; position: absolute; bottom: -0.5rem; left: 0;
width: 100%; height: 3px; background: var(--gradient-primary);
border-radius: 3px 3px 0 0;
}
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.5s ease forwards; }
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
/* Step Explanation */
.step-explanation {
background: var(--bg-tertiary); padding: 1.5rem;
border-radius: var(--border-radius); margin: 1.5rem 0;
position: relative; border-left: 4px solid var(--accent-primary);
transition: var(--transition);
}
.step-explanation.highlight { transform: scale(1.02); box-shadow: var(--box-shadow); }
.step-title {
font-weight: 600; margin-bottom: 0.8rem;
display: flex; align-items: center; gap: 0.5rem;
}
.step-title-icon {
background: var(--accent-primary); width: 24px; height: 24px;
border-radius: 50%; display: flex; align-items: center; justify-content: center;
font-size: 0.8rem; color: white;
}
/* Visualization Area */
.visualization-area {
width: 100%; min-height: 400px; position: relative;
margin-top: 2rem; padding: 1rem; background: var(--bg-secondary);
border-radius: var(--border-radius); overflow: hidden; transition: var(--transition);
}
/* Array visualization */
.array-container {
display: flex; justify-content: center; gap: 6px; margin: 2rem 0;
height: 230px; align-items: flex-end; padding: 1rem; position: relative;
}
.array-element {
background: var(--gradient-primary); border-radius: 6px 6px 0 0;
transition: transform 0.5s ease, height 0.5s ease, background 0.3s ease;
position: relative; min-width: 35px; display: flex; justify-content: center;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.array-element.comparing {
background: var(--gradient-secondary); animation: pulse 0.8s infinite alternate;
z-index: 1;
}
.array-element.sorted { background: linear-gradient(to top, var(--success), #4ade80); }
.array-element.pivot { background: var(--gradient-secondary); border: 2px solid white; z-index: 2; }
.array-element.swapping { animation: bounce 0.5s ease; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-20px); } }
.element-value { position: absolute; bottom: -25px; font-weight: 600; font-size: 0.9rem; color: var(--text-secondary); font-family: 'JetBrains Mono', monospace; }
/* Buckets */
.buckets-container {
display: flex; flex-wrap: wrap; justify-content: center; gap: 1.5rem; margin-top: 3rem;
}
.bucket {
background: var(--bg-secondary); border-radius: var(--border-radius);
padding: 1.5rem; min-width: 180px; min-height: 150px; position: relative;
border: 1px dashed rgba(255,255,255,0.2); box-shadow: var(--box-shadow);
transition: var(--transition);
}
.bucket:hover { transform: translateY(-5px); box-shadow: var(--box-shadow-lg); }
.bucket-label {
position: absolute; top: -12px; left: 50%;
transform: translateX(-50%); background: var(--bg-tertiary);
padding: 0.4rem 0.8rem; border-radius: 20px; font-size: 0.8rem;
white-space: nowrap; box-shadow: var(--box-shadow); font-weight: 500;
}
.bucket-elements {
display: flex; flex-wrap: wrap; gap: 8px; margin-top: 1rem; justify-content: center;
}
.bucket-element {
width: 36px; height: 36px; background: var(--gradient-primary);
border-radius: 50%; display: flex; align-items: center; justify-content: center;
font-size: 0.8rem; font-weight: 600; color: white;
box-shadow: 0 2px 4px rgba(0,0,0,0.1); transition: var(--transition-fast);
}
.bucket-element:hover { transform: scale(1.1); box-shadow: 0 4px 8px rgba(0,0,0,0.2); }
/* Min Heap Visualization */
.heap-visualization { margin-top: 3rem; }
.heap-tree {
width: 100%; max-width: 500px; height: 250px; margin: 0 auto; position: relative;
}
.heap-node {
position: absolute; width: 40px; height: 40px; background: var(--gradient-primary);
border-radius: 50%; display: flex; align-items: center; justify-content: center;
color: white; font-weight: 600; box-shadow: var(--box-shadow); transition: var(--transition);
}
.heap-node.extracting { animation: extractMin 1s forwards; }
@keyframes extractMin { 0% { transform: scale(1); } 50% { transform: scale(1.2); box-shadow: 0 0 20px rgba(99,102,241,0.5); } 100% { transform: translateY(100px) scale(0.8); opacity: 0; } }
.heap-edge {
position: absolute; background: var(--text-secondary); height: 2px;
transform-origin: left center;
}
.merged-array {
display: flex; justify-content: center; gap: 8px; margin-top: 2rem; flex-wrap: wrap;
}
.merged-element {
width: 40px; height: 40px; background: linear-gradient(to top, var(--success), #4ade80);
border-radius: 6px; display: flex; align-items: center; justify-content: center;
font-weight: 600; color: white; box-shadow: var(--box-shadow);
animation: fadeIn 0.5s ease forwards;
}
/* Animations */
@keyframes pulse {
from { transform: scale(1); box-shadow: 0 0 0 rgba(245,158,11,0); }
to { transform: scale(1.05); box-shadow: 0 0 20px rgba(245,158,11,0.5); }
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
/* ========================
CHALLENGE SECTION
======================== */
.challenge-section { margin: 3rem 0; }
.challenge-card {
background: rgba(var(--bg-secondary-rgb), 0.8);
border-radius: var(--border-radius); padding: 2rem; margin-bottom: 2rem;
box-shadow: var(--box-shadow); border: 1px solid rgba(255,255,255,0.1);
position: relative; overflow: hidden; transition: var(--transition);
}
.challenge-card:hover { transform: translateY(-5px); box-shadow: var(--box-shadow-lg); }
.challenge-card::before {
content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%;
background: var(--gradient-primary);
}
.challenge-card h3 {
color: var(--text-primary); margin-bottom: 1rem;
display: flex; align-items: center; gap: 0.5rem;
}
.challenge-badge {
background: var(--gradient-primary); color: white;
width: 28px; height: 28px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
font-size: 0.9rem; font-weight: 600;
}
/* Mini-game */
.mini-game { margin: 2rem 0; text-align: center; }
.mini-game-elements { display: flex; justify-content: center; gap: 1rem; margin: 1.5rem 0; flex-wrap: wrap; }
.mini-game-element {
width: 50px; height: 50px; background: var(--bg-tertiary);
border-radius: 50%; display: flex; align-items: center; justify-content: center;
font-weight: 600; cursor: pointer; transition: var(--transition);
border: 2px solid transparent; color: var(--text-primary);
}
.mini-game-element:hover {
transform: scale(1.1); border-color: var(--accent-primary);
box-shadow: 0 0 15px rgba(99,102,241,0.3);
}
.mini-game-element.selected {
background: var(--gradient-primary); color: white;
transform: scale(1.1); box-shadow: var(--box-shadow);
}
/* ========================
ACCORDION
======================== */
.accordion { margin: 2rem 0; }
.accordion-item {
margin-bottom: 1rem; border-radius: var(--border-radius);
overflow: hidden; box-shadow: var(--box-shadow);
}
.accordion-header {
background: var(--bg-secondary); padding: 1rem 1.5rem;
cursor: pointer; display: flex; align-items: center;
justify-content: space-between; user-select: none;
transition: var(--transition-fast);
}
.accordion-header:hover { background: var(--bg-tertiary); }
.accordion-body {
background: var(--bg-tertiary); padding: 0;
max-height: 0; overflow: hidden;
transition: max-height 0.3s ease, padding 0.3s ease;
}
.accordion-body.active { padding: 1.5rem; max-height: 500px; }
.accordion-icon { transition: transform 0.3s ease; }
.accordion-header.active .accordion-icon { transform: rotate(180deg); }
/* ========================
ACHIEVEMENTS SECTION
======================== */
.achievements-section { margin: 3rem 0; }
.achievements-grid {
display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 1.5rem; margin-top: 2rem;
}
.achievement-card {
background: var(--bg-secondary); border-radius: var(--border-radius);
padding: 1.5rem; text-align: center; box-shadow: var(--box-shadow);
transition: var(--transition); position: relative; overflow: hidden;
}
.achievement-card::after {
content: ''; position: absolute; top: 0; left: 0;
width: 100%; height: 5px; background: var(--gradient-primary);
}
.achievement-card:hover { transform: translateY(-5px); box-shadow: var(--box-shadow-lg); }
.achievement-card.locked { opacity: 0.7; }
.achievement-icon {
width: 60px; height: 60px; background: var(--bg-tertiary);
border-radius: 50%; display: flex; align-items: center; justify-content: center;
margin: 0 auto 1rem; font-size: 1.5rem;
}
.achievement-card.unlocked .achievement-icon {
background: var(--gradient-primary); color: white;
animation: unlockAchievement 1s ease;
}
@keyframes unlockAchievement {
0% { transform: scale(0.8); }
50% { transform: scale(1.2); box-shadow: 0 0 30px rgba(99,102,241,0.5); }
100% { transform: scale(1); }
}
.achievement-title { font-weight: 600; margin-bottom: 0.5rem; }
.achievement-description { font-size: 0.9rem; color: var(--text-secondary); }
/* Level indicator */
.level-indicator {
position: absolute; top: 1rem; right: 1rem;
background: var(--bg-tertiary); padding: 0.4rem 0.8rem;
border-radius: 20px; font-size: 0.9rem; font-weight: 600;
display: flex; align-items: center; gap: 0.5rem; box-shadow: var(--box-shadow);
}
.level-badge {
background: var(--gradient-primary); color: white;
width: 24px; height: 24px; border-radius: 50%;
display: flex; align-items: center; justify-content: center; font-size: 0.8rem;
}
/* ========================
TOOLTIP
======================== */
.tooltip { position: relative; display: inline-block; }
.tooltip .tooltip-text {
visibility: hidden; width: 200px; background-color: var(--bg-tertiary);
color: var(--text-primary); text-align: center; border-radius: 6px;
padding: 0.5rem; position: absolute; z-index: 1;
bottom: 125%; left: 50%; transform: translateX(-50%);
opacity: 0; transition: opacity 0.3s; box-shadow: var(--box-shadow);
font-size: 0.8rem;
}
.tooltip .tooltip-text::after {
content: ""; position: absolute; top: 100%; left: 50%;
margin-left: -5px; border-width: 5px; border-style: solid;
border-color: var(--bg-tertiary) transparent transparent transparent;
}
.tooltip:hover .tooltip-text { visibility: visible; opacity: 1; }
/* ========================
MODAL
======================== */
.modal {
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
display: flex; align-items: center; justify-content: center;
background: rgba(0,0,0,0.7); z-index: 1000;
opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.modal.show { opacity: 1; pointer-events: auto; }
.modal-content {
background: var(--bg-secondary); border-radius: var(--border-radius);
width: 90%; max-width: 600px; max-height: 90vh; overflow-y: auto;
padding: 2rem; position: relative; transform: scale(0.9);
transition: transform 0.3s ease; box-shadow: var(--box-shadow-lg);
}
.modal.show .modal-content { transform: scale(1); }
.modal-close {
position: absolute; top: 1rem; right: 1rem;
background: none; border: none; color: var(--text-secondary);
font-size: 1.5rem; cursor: pointer; transition: var(--transition-fast);
}
.modal-close:hover { color: var(--text-primary); transform: rotate(90deg); }
.modal-title {
margin-bottom: 1.5rem; font-size: 1.8rem; font-weight: 700;
background: var(--gradient-primary); -webkit-background-clip: text;
background-clip: text; color: transparent;
}
/* ========================
NOTIFICATIONS
======================== */
.notification-container {
position: fixed; bottom: 20px; right: 20px; z-index: 1000;
}
.notification {
background: var(--bg-secondary); color: var(--text-primary);
padding: 1rem 1.5rem; border-radius: var(--border-radius);
margin-bottom: 10px; box-shadow: var(--box-shadow-lg);
display: flex; align-items: center; gap: 0.8rem;
transform: translateX(120%); transition: transform 0.3s ease;
max-width: 350px;
}
.notification.show { transform: translateX(0); }
.notification-icon {
width: 30px; height: 30px; border-radius: 50%;
display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.notification-success .notification-icon { background: var(--success); color: white; }
.notification-warning .notification-icon { background: var(--warning); color: white; }
.notification-error .notification-icon { background: var(--danger); color: white; }
.notification-close {
margin-left: auto; background: none; border: none;
color: var(--text-secondary); cursor: pointer; transition: var(--transition-fast);
}
.notification-close:hover { color: var(--text-primary); }
/* ========================
FOOTER
======================== */
footer {
text-align: center; padding: 3rem 0 2rem;
color: var(--text-secondary); font-size: 0.9rem; position: relative;
}
.footer-links {
display: flex; justify-content: center; gap: 1.5rem; margin-bottom: 1.5rem;
}
.footer-link { color: var(--text-secondary); text-decoration: none; transition: var(--transition-fast); }
.footer-link:hover { color: var(--accent-primary); }
.back-to-top {
position: absolute; top: -20px; left: 50%;
transform: translateX(-50%); background: var(--bg-secondary);
width: 40px; height: 40px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
color: var(--text-primary); text-decoration: none;
box-shadow: var(--box-shadow); transition: var(--transition);
}
.back-to-top:hover { transform: translateX(-50%) translateY(-5px); box-shadow: var(--box-shadow-lg); }
/* ========================
RESPONSIVE STYLES
======================== */
@media (max-width: 1024px) {
.container { padding: 1.5rem 1rem; }
.game-board { padding: 1.5rem; }
.achievements-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
@media (max-width: 768px) {
.title { font-size: 2.2rem; }
.game-controls { flex-direction: column; align-items: stretch; }
.btn { width: 100%; }
.slider-container { flex-direction: column; align-items: stretch; }
input[type="range"] { width: 100%; }
.stats-panel { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.array-element { min-width: 28px; }
.step-explanation { padding: 1rem; }
.achievements-grid { grid-template-columns: 1fr; }
}
@media (max-width: 576px) {
.array-element { min-width: 20px; }
.element-value { font-size: 0.7rem; }
.bucket { min-width: 100%; }
.game-tabs { flex-wrap: wrap; }
.notification { max-width: 300px; }
}
/* ========================
PRINT STYLES
======================== */
@media print {
.game-controls, .btn, .game-tabs, .modal, .notification-container { display: none !important; }
.container { padding: 0; max-width: 100%; }
body { background: white; color: black; }
.game-board, .step-explanation, .bucket, .array-element, .achievement-card {
box-shadow: none; border: 1px solid #ddd;
}
}
/* ========================
ACCESSIBILITY
======================== */
.sr-only {
position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}
@media (prefers-reduced-motion: reduce) {
*, ::before, ::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
/* ========================
CODE BLOCK STYLING
======================== */
.code-section { margin-top: 20px; border-radius: var(--border-radius); overflow: hidden; }
.code-block {
background-color: #1e1e1e; color: #d4d4d4;
padding: 1.5rem; border-radius: var(--border-radius);
font-family: 'JetBrains Mono', monospace; font-size: 0.9rem;
line-height: 1.5; overflow-x: auto; white-space: pre; box-shadow: var(--box-shadow);
}
.code-keyword { color: #569cd6; }
.code-type { color: #4ec9b0; }
.code-function { color: #dcdcaa; }
.code-string { color: #ce9178; }
.code-comment { color: #6a9955; }
.code-number { color: #b5cea8; }
/* ========================
MATH EQUATION STYLES
======================== */
.math-equation {
font-family: 'JetBrains Mono', monospace; font-style: italic;
padding: 0.2rem 0.4rem; background: var(--bg-tertiary);
border-radius: var(--border-radius-sm); display: inline-block;
margin: 0 0.2rem; font-weight: 500;
}
/* ========================
FEATURE CARD STYLES
======================== */
.feature-card {
background: var(--bg-secondary); border-radius: var(--border-radius);
padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: var(--box-shadow);
border-left: 4px solid var(--accent-primary); transition: var(--transition);
}
.feature-card:hover { transform: translateY(-5px); box-shadow: var(--box-shadow-lg); }
.feature-card h4 {
font-weight: 600; margin-bottom: 0.8rem; color: var(--text-primary);
display: flex; align-items: center; gap: 0.5rem;
}
.feature-icon {
width: 30px; height: 30px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
background: var(--gradient-primary); color: white;
}
/* ========================
HELP MODAL STYLING
======================== */
.help-content { margin: 1.5rem 0; }
.help-section { margin-bottom: 2rem; }
.help-title {
font-weight: 600; margin-bottom: 1rem; color: var(--accent-primary);
display: flex; align-items: center; gap: 0.5rem;
}
.help-icon {
width: 24px; height: 24px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
background: var(--gradient-primary); color: white; font-size: 0.8rem;
}
.step-detail { margin-left: 2rem; margin-bottom: 1rem; padding-left: 1rem; border-left: 2px solid var(--accent-primary); }
.algorithm-step {
background: var(--bg-secondary); padding: 1.5rem;
border-radius: var(--border-radius); margin-bottom: 1.5rem;
box-shadow: var(--box-shadow); position: relative; overflow: hidden;
transition: var(--transition);
}
.algorithm-step:hover { transform: translateY(-3px); box-shadow: var(--box-shadow-lg); }
.algorithm-step::before {
content: ''; position: absolute; top: 0; left: 0;
width: 3px; height: 100%; background: var(--gradient-primary);
}
.step-header {
font-weight: 600; margin-bottom: 1rem; display: flex;
align-items: center; gap: 0.5rem;
}
.step-icon {
width: 28px; height: 28px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
background: var(--gradient-primary); color: white; font-weight: 500;
flex-shrink: 0;
}
.step-content { margin-left: 2.5rem; }
.step-content p { margin-bottom: 0.8rem; }
.step-content ul { list-style-type: disc; margin-left: 1.5rem; margin-bottom: 0.8rem; }
.step-content li { margin-bottom: 0.4rem; }
/* ========================
ENHANCED TOOLTIPS
======================== */
.enhanced-tooltip {
position: relative; display: inline-block;
border-bottom: 1px dotted var(--text-secondary); cursor: help;
}
.enhanced-tooltip .tooltip-content {
visibility: hidden; width: 250px; background: var(--bg-secondary);
color: var(--text-primary); border-radius: var(--border-radius);
padding: 1rem; position: absolute; z-index: 10;
bottom: 125%; left: 50%; transform: translateX(-50%);
opacity: 0; transition: opacity 0.3s; box-shadow: var(--box-shadow-lg);
font-weight: normal; font-size: 0.9rem; text-align: left; pointer-events: none;
}
.enhanced-tooltip:hover .tooltip-content { visibility: visible; opacity: 1; }
.enhanced-tooltip .tooltip-content::after {
content: ''; position: absolute; top: 100%; left: 50%;
transform: translateX(-50%); border-width: 10px; border-style: solid;
border-color: var(--bg-secondary) transparent transparent transparent;
}
/* ========================
ENHANCED HELP MODAL SCROLL
======================== */
.help-modal-content {
max-width: 700px; max-height: 80vh; overflow-y: auto; padding-right: 1rem;
}
.help-modal-content::-webkit-scrollbar { width: 8px; }
.help-modal-content::-webkit-scrollbar-track { background: var(--bg-tertiary); border-radius: 4px; }
.help-modal-content::-webkit-scrollbar-thumb { background: var(--accent-primary); border-radius: 4px; }
.help-modal-content::-webkit-scrollbar-thumb:hover { background: var(--accent-secondary); }
</style>
</head>
<body>
<a href="#main-content" class="skip-link">Skip to content</a>
<div class="container">
<header>
<button class="theme-toggle" id="theme-toggle" aria-label="Toggle dark/light mode">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16" id="theme-icon">
<path d="M8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm0 1a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z"/>
</svg>
</button>
<h1 class="title">Alpay's Fractal Sort</h1>
<p class="subtitle">Master the innovative sorting algorithm through an interactive game experience</p>
<div class="main-nav">
<button class="nav-tab active" data-tab="game">Algorithm Game</button>
<button class="nav-tab" data-tab="learn">Learn</button>
<button class="nav-tab" data-tab="challenges">Challenges</button>
<button class="nav-tab" data-tab="achievements">Achievements</button>
</div>
</header>
<main id="main-content">
<!-- GAME TAB CONTENT -->
<div class="tab-content active" id="game-tab">
<div class="stats-panel">
<div class="stat-card">
<div class="stat-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 11a1 1 0 1 1 0-2 1 1 0 0 1 0 2zm6-1a1 1 0 1 0 2 0 1 1 0 0 0-2 0zM1.5 11a.5.5 0 0 0 0 1h13a.5.5 0 0 0 0-1h-13zM1.5 4a.5.5 0 0 0 0 1h13a.5.5 0 0 0 0-1h-13zM4 5a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm6-1a1 1 0 1 1 2 0 1 1 0 0 1-2 0z"/>
</svg>
</div>
<div class="stat-value" id="comparison-count">0</div>
<div class="stat-label">Comparisons</div>
</div>
<div class="stat-card">
<div class="stat-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"/>
</svg>
</div>
<div class="stat-value" id="sort-score">0</div>
<div class="stat-label">Score</div>
</div>
<div class="stat-card">
<div class="stat-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 3.5a.5.5 0 0 0-1 0V9a.5.5 0 0 0 .252.434l3.5 2a.5.5 0 0 0 .496-.868L8 8.71V3.5z"/>
<path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zm7-8A7 7 0 1 1 1 8a7 7 0 0 1 14 0z"/>
</svg>
</div>
<div class="stat-value" id="time-taken">0s</div>
<div class="stat-label">Time</div>
</div>
</div>
<div class="game-controls">
<button class="btn btn-primary" id="generate-array" aria-label="Generate new array">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"/>
</svg>
New Array
</button>
<button class="btn btn-action" id="start-sort" aria-label="Start sorting">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="m11.596 8.697-6.363 3.692c-.54.313-1.233-.066-1.233-.697V4.308c0-.63.692-1.01 1.233-.696l6.363 3.692a.802.802 0 0 1 0 1.393z"/>
</svg>
Start Sorting
</button>
<button class="btn btn-secondary" id="step-button" aria-label="Step through algorithm">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 3.5a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5H4a.5.5 0 0 1 0-1h3.5V4a.5.5 0 0 1 .5-.5z"/>
<path fill-rule="evenodd" d="M7.5 8a.5.5 0 0 1 .5-.5h4a.5.5 0 0 1 0 1H8.5V12a.5.5 0 0 1-1 0V8z"/>
</svg>
Step-by-Step
</button>
<div class="slider-container">
<label for="speed-slider" class="slider-label">Speed:</label>
<input type="range" id="speed-slider" min="1" max="10" value="5" aria-label="Animation speed">
</div>
<button class="btn btn-secondary" id="help-button" aria-label="Help">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
<path d="M5.255 5.786a.237.237 0 0 0 .241.247h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286zm1.557 5.763c0 .533.425.927 1.01.927.609 0 1.028-.394 1.028-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94z"/>
</svg>
Help
</button>
</div>
<div class="progress-container">
<div class="progress-bar" id="sort-progress"></div>
</div>
<div class="game-board">
<div class="level-indicator">
<span class="level-badge" id="current-level">1</span>
<span>Level</span>
</div>
<div class="game-tabs">
<button class="game-tab active" data-game-tab="visualization">Visualization</button>
<button class="game-tab" data-game-tab="algorithm">Algorithm Steps</button>
<button class="game-tab" data-game-tab="code">Code View</button>
</div>
<!-- Visualization Tab -->
<div class="tab-content active" id="visualization-tab">
<div class="step-explanation">
<h3 class="step-title">
<span class="step-title-icon">1</span>
Welcome to Alpay's Fractal Sort Game
</h3>
<p>This interactive visualization will help you understand how this innovative sorting algorithm works through gameplay. Generate a new array to begin!</p>
</div>
<div class="array-container" id="array-container">
<!-- Array elements will be generated here -->
</div>
<div class="visualization-area" id="visualization-area">
<!-- Buckets will appear here during partitioning -->
<div class="buckets-container" id="buckets-container" style="display: none;">
<!-- Buckets will be generated here -->
</div>
<!-- Min-heap visualization for k-way merge -->
<div class="heap-visualization" id="heap-visualization" style="display: none;">
<h3>Min-Heap K-Way Merge</h3>
<div class="heap-tree" id="heap-tree">
<!-- Heap nodes will be generated here -->
</div>
<div class="merged-array" id="merged-array">
<!-- Merged elements will appear here -->
</div>
</div>
</div>
</div>
<!-- Algorithm Steps Tab -->
<div class="tab-content" id="algorithm-tab">
<div class="accordion" id="algorithm-accordion">
<div class="accordion-item">
<div class="accordion-header" data-accordion="initialize">
<span>1. Check Array Size</span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-body">
<p>If the array size is less than or equal to ALPAY_SMALL_THRESH (12), use the bidirectional triple fix method for efficient sorting of small arrays.</p>
<p>For larger arrays, proceed with the fractal partitioning approach.</p>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" data-accordion="selectPivots">
<span>2. Select Pivots</span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-body">
<p>Calculate sqrt(n) as the number of pivots needed, where n is the array size.</p>
<p>Sample approximately 2 × sqrt(n) elements randomly from the array.</p>
<p>Sort the samples and remove outliers (about 15% from each end).</p>
<p>Select evenly spaced elements from the remaining samples as pivots.</p>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" data-accordion="partition">
<span>3. Partition Array</span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-body">
<p>Create k+1 buckets (where k is the number of pivots).</p>
<p>For each element in the array:</p>
<ul style="list-style-type: disc; margin-left: 20px;">
<li>Find the smallest pivot that is greater than the element</li>
<li>Place the element in the corresponding bucket</li>
<li>If no pivot is greater, place in the last bucket</li>
</ul>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" data-accordion="recursiveSort">
<span>4. Recursive Sort</span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-body">
<p>For each bucket with more than one element:</p>
<ul style="list-style-type: disc; margin-left: 20px;">
<li>If bucket size ≤ 12, use bidirectional triple fix</li>
<li>Otherwise, recursively apply the entire fractal sort algorithm</li>
</ul>
<p>This recursive approach creates a fractal-like pattern of partitioning, reducing the problem size rapidly.</p>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" data-accordion="merge">
<span>5. K-Way Merge</span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-body">
<p>Create a min-heap with the first element from each bucket.</p>
<p>Repeatedly:</p>
<ul style="list-style-type: disc; margin-left: 20px;">
<li>Extract the minimum element from the heap</li>
<li>Add it to the result array</li>
<li>Insert the next element from the same bucket into the heap</li>
<li>Continue until all elements are processed</li>
</ul>
<p>This approach ensures an efficient O(n log k) merge complexity.</p>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" data-accordion="complete">
<span>6. Sorting Complete</span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-body">
<p>The array is now fully sorted! The algorithm has used fractal partitioning to efficiently divide the problem into manageable chunks and then merged them back together.</p>
<p>The theoretical time complexity approaches O(n log log n) for well-distributed data, making this algorithm potentially faster than traditional O(n log n) sorting algorithms in many cases.</p>
</div>
</div>
</div>
</div>
<!-- Code View Tab -->
<div class="tab-content" id="code-tab">
<div class="code-section">
<pre class="code-block"><span class="code-comment">// Updated C++ code for Alpay's Advanced Fractal Sort</span>
<span class="code-comment">// with bidirectional triple fix, fractal partitioning, and min-heap k-way merge</span>
<span class="code-keyword">#include</span> <span class="code-string"><iostream></span>
<span class="code-keyword">#include</span> <span class="code-string"><vector></span>
<span class="code-keyword">#include</span> <span class="code-string"><cstdlib></span> <span class="code-comment">// rand, srand</span>
<span class="code-keyword">#include</span> <span class="code-string"><ctime></span> <span class="code-comment">// time</span>
<span class="code-keyword">#include</span> <span class="code-string"><utility></span> <span class="code-comment">// std::swap</span>
<span class="code-keyword">#include</span> <span class="code-string"><cmath></span> <span class="code-comment">// std::sqrt</span>
<span class="code-keyword">#include</span> <span class="code-string"><queue></span> <span class="code-comment">// std::priority_queue</span>
<span class="code-comment">// Threshold for fallback (small array size)</span>
<span class="code-keyword">static const int</span> <span class="code-function">ALPAY_SMALL_THRESH</span> = 12;
<span class="code-comment">// Sample factor for pivot selection</span>
<span class="code-keyword">static const double</span> <span class="code-function">PIVOT_SAMPLE_FACTOR</span> = 2.0;
<span class="code-comment">// Fraction of sample outliers to discard</span>
<span class="code-keyword">static const double</span> <span class="code-function">PIVOT_OUTLIER_FRAC</span> = 0.15;
/*****************************************************************************
* 1) Bidirectional Triple Pass
*****************************************************************************/
<span class="code-keyword">void</span> <span class="code-function">alpayTripleFixBidirectional</span>(<span class="code-type">std::vector</span><<span class="code-type">int</span>> &arr, <span class="code-type">int</span> start, <span class="code-type">int</span> end) {
<span class="code-keyword">if</span> (start >= end) <span class="code-keyword">return</span>; <span class="code-comment">// Array of size 0 or 1 is sorted</span>
<span class="code-keyword">if</span> (end - start == 1) { <span class="code-comment">// Array of size 2</span>
<span class="code-keyword">if</span> (arr[start] > arr[start + 1]) {
<span class="code-function">std::swap</span>(arr[start], arr[start + 1]);
}
<span class="code-keyword">return</span>;
}
<span class="code-type">bool</span> changed = <span class="code-keyword">true</span>;
<span class="code-keyword">while</span> (changed) {
changed = <span class="code-keyword">false</span>;
<span class="code-comment">// Forward pass</span>
<span class="code-keyword">for</span> (<span class="code-type">int</span> i = start; i < end; i++) {
<span class="code-keyword">if</span> (arr[i] > arr[i + 1]) { <span class="code-function">std::swap</span>(arr[i], arr[i + 1]); changed = <span class="code-keyword">true</span>; }
}
<span class="code-comment">// Backward pass</span>
<span class="code-keyword">for</span> (<span class="code-type">int</span> i = end - 1; i >= start; i--) {
<span class="code-keyword">if</span> (arr[i] < arr[i - 1]) { <span class="code-function">std::swap</span>(arr[i], arr[i - 1]); changed = <span class="code-keyword">true</span>; }
}
}
}
/*****************************************************************************
* 2) Pivot Array Sort (using triple pass)
*****************************************************************************/
<span class="code-keyword">void</span> <span class="code-function">alpayTripleSortPivotArray</span>(<span class="code-type">std::vector</span><<span class="code-type">int</span>> &pivots) {
<span class="code-function">alpayTripleFixBidirectional</span>(pivots, 0, (<span class="code-type">int</span>)pivots.size() - 1);
}
/*****************************************************************************
* 3) Min-Heap-based K-Way Merge
*****************************************************************************/
<span class="code-comment">// Structure for min-heap items</span>
<span class="code-keyword">struct</span> <span class="code-function">HeapItem</span> {
<span class="code-type">int</span> value;
<span class="code-type">int</span> bIndex; <span class="code-comment">// Bucket index</span>
<span class="code-type">int</span> iIndex; <span class="code-comment">// Index within bucket</span>
<span class="code-keyword">bool</span> <span class="code-function">operator></span>(<span class="code-keyword">const</span> <span class="code-function">HeapItem</span>&o) <span class="code-keyword">const</span> {
<span class="code-keyword">return</span> value > o.value;
}
};
<span class="code-keyword">void</span> <span class="code-function">alpayMultiBucketMerge</span>(<span class="code-keyword">const</span> <span class="code-type">std::vector</span><<span class="code-type">std::vector</span><<span class="code-type">int</span>>> &buckets,