Algo Visualizer

The best way to understand complex data structures is to see them in action. This project is developed in an
interactive animations for a variety of data structures and algorithms.

Selection sort

Delay Time :

10

Array Size :

10

Defination :
Selection sort is an in-place comparison sort. It has O(n2) complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort. Selection sort is noted for its simplicity, and also has performance advantages over more complicated algorithms in certain situations. The algorithm finds the minimum value, swaps it with the value in the first position, and repeats these steps for the remainder of the list. It does no more than n swaps, and thus is useful where swapping is very expensive.

Performance
Best-case Time complexity: O(n²)
Average-case Time complexity: O(n²)
worst-case Time complexity: O(n²)

Space complexity
worst-case Space complexity: O(1)


            async function selectionSort(arr){
                var minIdx;
                for(var i = 0; i < len; i++){
                    minIdx = i;
                    for(var  j = i+1; j < len; j++) {
                        if(arr[j] < arr[minIdx]){
                            minIdx = j;
                        }
                    }
                    await swapIndex(arr,i,minIdx);
                    await drawArr(arr);
                    await sleep(time)
                }
                return arr;
            }
    
            

Designed and built with by The ThunderBolt