logoNEURAL COOK
SearchAll PostsTagsNotesAuthor
logoNEURAL COOK

A posts created with Next.js and Tailwind.css

Explore

  • All posts
  • Notes
  • Snippets
  • Tags
  • RSS feed

Connect

instagramtwitterfacebookyoutubelinkedinmailgithub

© 2026 VIKI. All rights reserved.

Built with
Contents
ArraysBoyer-Moore Majority Vote AlgorithmKadane’s AlgorithmTriple Reverse algorithm aka Reversal Algorithm
Cycle detectionDijkstraDisjoint Set UnionGraphTopological SortTraversal algorithmsTree Traversal
Binary HeapBinomial HeapHeap
Cycle DetectionLinked ListSorting
Finding the majority elementRotate array by K steps
Finding If Number is PrimeGCD of two numbersPerforming ExponentiationPrime NumbersRandomising Data
3. Max Consecutive OnesHoare'S Partition SchemeLomuto Partition Scheme
DequesPriority QueueQueue
The Binary Search Master GuideThe Rotated Sorted Array Master Guide
Bubble SortCounting SortInsertion SortMerge SortPigeon Hole SortQuick SortSelection Sort
Monotonic StackMonotonic StackStackReversing an ArrayStackTower of Hanoi
Binary Tree TraversalCentre of gravityDiameter of TreeShortest Path
Algorithmic Pattern/linked list

Sorting

1 min read
On this pageSorting with Insertion Sort <a href="#head-3-35" id="head-3-35"></a>
Sorting with Insertion Sort <a href="#head-3-35" id="head-3-35"></a>Sorting with Selection Sort

# Sorting with Insertion Sort

Basic idea behind insertionsort is to take an item from the input list and insert it into the proper position in a sorted output list (which initially starts empty).

The algorithm

  • starts by building an empty list to hold the sorted output.
  • Then loops through the unsorted list of input nodes.
  • For each input nodes, looks through the growing sorted list and finds the node after which the new value belongs.
  • It then inserts the node there.

Since we end up comparing with all in worst case the time complexity is O(n2)O(n^2)O(n2)

# Sorting with Selection Sort

Basic idea behind the selectionsort algorithm is to search the input list for the largest item it contains and then add it to the front of a growing sorted list.

For an input list contains nnn items, finding the largest item in the list takes nnn steps but adding the largest item to the sorted list takes only a few steps.

The input lenght also shrinks but still the time complexity is O(n2)O(n^2)O(n2)


\

←PreviousLinked ListNext→Finding the majority element

On this page

Sorting with Insertion Sort <a href="#head-3-35" id="head-3-35"></a>Sorting with Selection Sort