+ Bubble Sort is an iterative sorting algorithm that imitates the movement of bubbles in sparkling
+ water.
+ The bubbles represents the elements of the data structure.
+
+
+ The bigger bubbles reach the top faster than smaller bubbles, and this algorithm works in the same
+ way. It
+ iterates through the data structure and for each cycle compares the current element with the next
+ one,
+ swapping them if they are in the wrong order.
+
+
+ It's a simple algorithm to implement, but not much efficient: on average, quadratic sorting
+ algorithms with the
+ same time complexity such as Selection Sort or Insertion
+ Sort perform better.
+ It has several variants to improve its performances, such as Shaker Sort Odd Even Sort and Comb
+ Sort.
+
+
+
+
+
COMPLEXITY
+
+
+
+
+ Average Complexity
+
+
+
+ O(n2)
+
+
+
+
+
+ Best Case
+
+
+
+ O(n)
+
+
+
+
+
+ Worst Case
+
+
+
+ O(n2)
+
+
+
+
+
+ Space Complexity
+
+
+
+ O(1)
+
+
+
+
+
+
+
+
+
+
IMPLEMENTATIONS (C++)
+
+
+
+ void swap(int *xp, int *yp)
+ {
+ int temp = *xp;
+ *xp = *yp;
+ *yp = temp;
+ }
+
+
+ void bubbleSort(int arr[], int n)
+ {
+ int i, j;
+ for (i = 0; i < n-1; i++)
+ for (j=0; j < n-i-1; j++)
+ if (arr[j]> arr[j+1])
+ swap(&arr[j], &arr[j+1]);
+ }
+
+ Insertion sort is a simple sorting algorithm that builds the final sorted array one item at a time.
+ It's less performant than advanced sorting algorithms, but it can still have some advantages: it's
+ really easy
+ to implement and it's efficient on small data structures almost sorted.
+
+
+ The algorithm divides the data structure in two sublists: a sorted one, and one still to sort.
+ Initially, the
+ sorted sublist is made up of just one element and it gets progressively filled.
+ For every iteration, the algorithm picks an element on the unsorted sublist and inserts it at the
+ right place in
+ the sorted sublist.
+ It's available in several variants such as Gnome Sort.
+
+ Heap Sort is an in-place iterative sorting algorithm based on auxiliary data structures called heap.
+ It's less efficient than algorithm with the same time complexity and it's not suitable for data
+ structures with
+ few elements.
+
+
+ The heap is a data structure representable as a binary tree, where each node has a value bigger or
+ equal to its
+ children. Consequently, the root will hold the maximum value.
+
+
+ The data structure gets ordered to form the heap initially, and then it gets progressively reordered
+ with an
+ algorithm similar to Selection Sort, starting from the bigger
+ elements.
+
+
+
+
+
COMPLEXITY
+
+
+
+
+ Average Complexity
+
+
+
+ O(n × log n)
+
+
+
+
+
+ Best Case
+
+
+
+ O(n × log n)
+
+
+
+
+
+ Worst Case
+
+
+
+ O(n × log n)
+
+
+
+
+
+ Space Complexity
+
+
+
+ O(1)
+
+
+
+
+
+
+
+
+
+
IMPLEMENTATIONS (c++)
+
+
+
+ void heapify(int arr[], int n, int i) {
+ int largest = i;
+ int left = 2 * i + 1;
+ int right = 2 * i + 2;
+
+ if (left < n && arr[left]> arr[largest])
+ largest = left;
+
+ if (right < n && arr[right]> arr[largest])
+ largest = right;
+
+ if (largest != i) {
+ swap(arr[i], arr[largest]);
+ heapify(arr, n, largest);
+ }
+ }
+
+ void heapSort(int arr[], int n) {
+ for (int i = n / 2 - 1; i >= 0; i--)
+ heapify(arr, n, i);
+
+ for (int i = n - 1; i >= 0; i--) {
+ swap(arr[0], arr[i]);
+ heapify(arr, i, 0);
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/images/Github_icon.png b/images/Github_icon.png
new file mode 100644
index 0000000..628da97
Binary files /dev/null and b/images/Github_icon.png differ
diff --git a/images/g.png b/images/g.png
new file mode 100644
index 0000000..d3942c8
Binary files /dev/null and b/images/g.png differ
diff --git a/images/i.png b/images/i.png
new file mode 100644
index 0000000..b7a5e01
Binary files /dev/null and b/images/i.png differ
diff --git a/images/mainbg.jpg b/images/mainbg.jpg
new file mode 100644
index 0000000..fb8ee05
Binary files /dev/null and b/images/mainbg.jpg differ
diff --git a/images/n.png b/images/n.png
new file mode 100644
index 0000000..a296f3b
Binary files /dev/null and b/images/n.png differ
diff --git a/images/o.png b/images/o.png
new file mode 100644
index 0000000..84c9e25
Binary files /dev/null and b/images/o.png differ
diff --git a/images/pause.png b/images/pause.png
new file mode 100644
index 0000000..2c664ea
Binary files /dev/null and b/images/pause.png differ
diff --git a/images/play.png b/images/play.png
new file mode 100644
index 0000000..5359184
Binary files /dev/null and b/images/play.png differ
diff --git a/images/r.png b/images/r.png
new file mode 100644
index 0000000..f825b72
Binary files /dev/null and b/images/r.png differ
diff --git a/images/s.png b/images/s.png
new file mode 100644
index 0000000..4aadb1d
Binary files /dev/null and b/images/s.png differ
diff --git a/images/sortbg.jpg b/images/sortbg.jpg
new file mode 100644
index 0000000..b9a318d
Binary files /dev/null and b/images/sortbg.jpg differ
diff --git a/images/t.png b/images/t.png
new file mode 100644
index 0000000..a21f5ac
Binary files /dev/null and b/images/t.png differ
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..a74fbb2
--- /dev/null
+++ b/index.html
@@ -0,0 +1,324 @@
+
+
+
+
+
+
+
+ Sorting Visualizer
+
+
+
+
+
+
+
+
+
+
+ Sorting algorithms are used to sort a data structure according to a specific order relationship,
+ such as numerical order or lexicographical order.
+
+
+ This operation is one of the most important and widespread in computer science. For a long time,
+ new methods have been developed to make this procedure faster and faster.
+
+
+ There are currently hundreds of different sorting algorithms, each with its own specific
+ characteristics. They are classified according to two metrics: space complexity and time
+ complexity.
+
+
+ Those two kinds of complexity are represented with asymptotic notations, mainly with the symbols
+ O, Θ, Ω, representing respectively the upper bound, the tight bound, and the lower bound of the
+ algorithm's complexity, specifying in brackets an expression in terms of n, the number of the
+ elements of the data structure.
+
+
+ Most of Sorting Algorithms fall into two categories:
+
+
+
+
Logarithmic
+ The complexity is proportional to the binary logarithm (i.e to the base 2) of n.
+
+ An example of a logarithmic sorting algorithm is Quick sort, with space and time
+ complexity O(n × log n).
+
+
+ Quadratic
+ The complexity is proportional to the square of n.
+ An example of a quadratic sorting algorithm is Bubble sort, with a time complexity
+ of O(n2).
+
+
+
+
+ Space and time complexity can also be further subdivided into 3 different cases: best case,
+ average case and worst case.
+
+
+ Sorting algorithms can be difficult to understand and it's easy to get confused. We believe
+ visualizing sorting algorithms can be a great way to better understand their functioning while
+ having fun!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/insertion.html b/insertion.html
new file mode 100644
index 0000000..8f2cba0
--- /dev/null
+++ b/insertion.html
@@ -0,0 +1,209 @@
+
+
+
+
+
+
+
+ Document
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Insertion sort is a simple sorting algorithm that builds the final sorted array one item at a time.
+ It's less performant than advanced sorting algorithms, but it can still have some advantages: it's
+ really easy
+ to implement and it's efficient on small data structures almost sorted.
+
+
+ The algorithm divides the data structure in two sublists: a sorted one, and one still to sort.
+ Initially, the
+ sorted sublist is made up of just one element and it gets progressively filled.
+ For every iteration, the algorithm picks an element on the unsorted sublist and inserts it at the
+ right place in
+ the sorted sublist.
+ It's available in several variants such as Gnome Sort.
+
+
+
+
+
COMPLEXITY
+
+
+
+
+ Average Complexity
+
+
+
+ O(n2)
+
+
+
+
+
+ Best Case
+
+
+
+ O(n)
+
+
+
+
+
+ Worst Case
+
+
+
+ O(n2)
+
+
+
+
+
+ Space Complexity
+
+
+
+ O(1)
+
+
+
+
+
+
+
+
+
+
IMPLEMENTATIONS (C++)
+
+
+
+ void insertionSort(int arr[], int n)
+ {
+ int i, key, j;
+ for (i = 1; i < n; i++)
+ {
+ key=arr[i];
+ j=i - 1;
+ while (j>= 0 && arr[j] > key)
+ {
+ arr[j + 1] = arr[j];
+ j = j - 1;
+ }
+ arr[j + 1] = key;
+ }
+ }
+
+ Merge Sort is a sorting algorithm based on the Divide et Impera technique, like Quick
+ Sort.
+ It can be implemented iteratively or recursively, using the Top-Down and Bottom-Up algorithms
+ respectively.
+ We represented the first one.
+
+
+ The algorithm divides the data structure recursively until the subsequences contain only one
+ element.
+ At this point, the subsequences get merged and ordered sequentially.
+ To do so, the algorithm progressively builds the sorted sublist by adding each time the minimum
+ element of the
+ next two unsorted subsequences until there is only one sublist remaining.
+ This will be the sorted data structure.
+
+ Quick Sort is a sorting algorithm based on splitting the data structure in smaller partitions and
+ sort them
+ recursively until the data structure is sorted.
+
+
+ This division in partitions is done based on an element, called pivot:
+ all the elements bigger than the pivot get placed on the right side of the structure, the smaller
+ ones to the
+ left, creating two partitions.
+ Next, this procedure gets applied recursively to the two partitions and so on.
+
+
+ This partition technique based on the pivot is called Divide and
+ conquer.
+ It's a performant strategy also used by other sorting algorithms, such as Merge
+ Sort.
+
+
+
+
+
COMPLEXITY
+
+
+
+
+ Average Complexity
+
+
+
+ O(n × log n)
+
+
+
+
+
+ Best Case
+
+
+
+ O(n × log n)
+
+
+
+
+
+ Worst Case
+
+
+
+ O(n2)
+
+
+
+
+
+ Space Complexity
+
+
+
+ O(n)
+
+
+
+
+
+
+
+
+
+
IMPLEMENTATIONS (C++)
+
+
+
+ void swap(int* a, int* b)
+ {
+ int t = *a;
+ *a = *b;
+ *b = t;
+ }
+
+ int partition (int arr[], int low, int high)
+ {
+ int pivot = arr[high];
+ int i = (low - 1);
+
+ for (int j = low; j <= high- 1; j++) {
+ if (arr[j] <=pivot) {
+ i++;
+ swap(&arr[i], &arr[j]);
+ }
+ }
+ swap(&arr[i + 1],&arr[high]);
+ return (i + 1);
+ }
+
+ void quickSort(int arr[], int low, int high) {
+ if (low < high) {
+ int pivot=partition(arr, low, high);
+ quickSort(arr, low, pivot - 1);
+ quickSort(arr, pivot + 1, high);
+ }
+ }
+
+ Selection Sort is an iterative and in-place sorting algorithm that divides the data structure in two
+ sublists: the ordered one, and the unordered one.
+ The algorithm loops for all the elements of the data structure and for every cycle picks the
+ smallest
+ element of the unordered sublist and adds it to the sorted sublist, progressively filling it.
+
+
+ It's a really simple and intuitive algorithm that does not require additional memory, but it's not
+ really efficient on big data structures due to its quadratic time complexity.
+
+
+ This algorithm has been upgraded and enhanced in several variants such as Heap
+ Sort.
+
+
+
+
+
COMPLEXITY
+
+
+
+
+ Average Complexity
+
+
+
+ O(n2)
+
+
+
+
+
+ Best Case
+
+
+
+ O(n2)
+
+
+
+
+
+ Worst Case
+
+
+
+ O(n2)
+
+
+
+
+
+ Space Complexity
+
+
+
+ O(1)
+
+
+
+
+
+
+
+
+
+
IMPLEMENTATIONS (c++)
+
+
+
+ void swap(int *xp, int *yp) {
+ int temp = *xp;
+ *xp = *yp;
+ *yp = temp;
+ }
+
+ void selectionSort(int arr[], int n) {
+ int i, j, min_idx;
+ for (i = 0; i < n-1; i++) {
+ min_idx=i;
+ for (j=i+1; j < n; j++)
+ if (arr[j] < arr[min_idx])
+ min_idx=j;
+ swap(&arr[min_idx],&arr[i]);
+ }
+ }
+