logoNEURAL COOK
SearchAll PostsTagsNotesAuthor
instagramtwitterfacebookyoutubelinkedinmailgithubrss
Copyright © 2026 All rights reserved.
•
VIKI
Built with Vikramaditya Singh
Built with
VIKI - A posts created with Next.js and Tailwind.css
About
arrays
Arrays
Boyer-Moore Majority Vote Algorithm
Kadane’s Algorithm
Triple Reverse algorithm aka Reversal Algorithm
graph
Cycle detection
Graph
Topological Sort
Tree Traversal
heap
Binary Heap
Binomial Heap
Heap
linked-list
Cycle Detection
Linked List
Sorting
miscellaneous
Finding the majority element
Rotate array by K steps
numerical-algorithms
Finding If Number is Prime
GCD of two numbers
Performing Exponentiation
Prime Numbers
Randomising Data
partitioning
3. Max Consecutive Ones
Hoare'S Partition Scheme
Lomuto Partition Scheme
queue
Deques
Priority Queue
Queue
search
The Binary Search Master Guide
The Rotated Sorted Array Master Guide
sort
Bubble Sort
Counting Sort
Sorting
Insertion Sort
Merge Sort
Pigeon Hole Sort
Quick Sort
Selection Sort
stack
Monotonic Stack
Monotonic Stack
Stack
Reversing an Array
Stack
Tower of Hanoi
tree
Binary Tree Traversal
Centre of gravity
Diameter of Tree
Shortest Path
Algorithmic Pattern›linked list

Sorting

# 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 ListNextFinding the majority element
CONTENTS
Sorting with Insertion Sort <a href="#head-3-35" id="head-3-35"></a>Sorting with Selection Sort