Ch 5 covers three fundamental sorting algorithms — bubble sort, selection sort, and insertion sort. Learn how each works, implement them in Python, and analyse their efficiency.
Bubble Sort: repeatedly compare adjacent elements and swap if out of order. After each pass, the largest unsorted element "bubbles" to its correct position. Passes: n-1 maximum. Optimisation: if no swaps in a pass, array is sorted — stop early. Selection Sort: find the minimum element in unsorted portion, swap with first unsorted position. Repeat. Always does n-1 swaps (in-place, minimal writes). Insertion Sort: build sorted array one element at a time. Take next element, insert into correct position in already-sorted left portion. Like sorting cards in hand.
Time complexity (Big-O): how running time grows with input size n. Bubble Sort: O(n²) average and worst case, O(n) best case (already sorted, with optimisation). Selection Sort: O(n²) always — same comparisons regardless of input order. Insertion Sort: O(n) best (already sorted), O(n²) average and worst. Space: all three are O(1) — in-place sorting. For small arrays (< 50 elements), all perform similarly. For large arrays: use Python's built-in sort() — TimSort, O(n log n). NCERT focuses on understanding, not just speed.
Download: https://ncert.nic.in/textbook/pdf/lecs105.pdf | Complete Book: https://ncert.nic.in/textbook/pdf/lecs1ps.zip
For CBSE exams: know all three thoroughly. For real programming: use Python's built-in sorted() or list.sort() — both use TimSort (hybrid of merge sort and insertion sort), O(n log n) average and worst case, optimised for real-world data. Among the three NCERT algorithms: insertion sort is generally best for small or nearly-sorted data (O(n) best case). Selection sort is best when writes are expensive (only n-1 swaps). Bubble sort is mainly educational — rarely used in practice.
Book a Trial + Diagnostic session. Get a personalized Learning Path with clear milestones, tutor match, and a plan recommendation — all within 24 hours.
Book Trial + Diagnostic →