Sorting
Class 12 · Computer Science
4 ideas in Class 12 Computer Science, explained in plain words, with games and quizzes to practise.
Why Sort and What It Costs
Part of: Sorting ideas and bubble sort
Sorting arranges items in an order, such as numbers from small to big or words from A to Z. Ordered lists are far easier to search, which is why dictionaries keep words alphabetically. Every method costs time: a straight loop grows with the list size, while a loop inside a loop grows with the square of the size.
Why it matters. Sorting makes searching fast, and cost rules help pick the right method for big data. A learner who reads loop shapes can predict which program will crawl on a huge list and which will stay quick.
Key words
- Sorting
- : Arranging a collection of items in a chosen order.
- Ascending Order
- : Arrangement from the smallest item to the largest.
- Time Complexity
- : How the work of an algorithm grows as data grows.
- Quadratic Time
- : Cost that grows with the square of the data size.
- Overhead
- : Extra sorting time that pays off in faster searching.
Try it in two minutes
- Hide a word in ten shuffled cards and time the search.
- Sort the cards and find the same word again.
- Ask why the second search felt faster.
Try at home. Ask your child to sort ten books two ways and say which order helps finding one faster.
Bubble Sort
Part of: Sorting ideas and bubble sort
Bubble sort repeatedly compares neighbours and swaps them when they are out of order. After each pass the largest unsorted value reaches its final place at the end, so later passes ignore it. A list of n items needs at most n minus one passes, and a pass with zero swaps means the list is already sorted.
Why it matters. Bubble sort is the simplest sorting idea and teaches passes, swaps and early stopping. Tracing it by hand builds the care needed for every harder sorting method.
Key words
- Bubble Sort
- : Sorting by swapping unordered neighbours pass after pass.
- Pass
- : One full walk through the items being sorted.
- Swap
- : Exchanging the positions of two items.
- Adjacent
- : Standing right next to each other in the list.
Try it in two minutes
- Line up five number cards and compare the first two neighbours.
- Swap them if out of order and walk to the end of the line.
- Ask which value reached the end after this pass.
Try at home. Ask your child to bubble sort five cards and record the line after each pass.
Selection Sort
Part of: Selection and insertion sorts
Selection sort splits the list into a sorted left part and an unsorted right part. Each pass scans the unsorted part for its smallest value and swaps it with the leftmost unsorted spot. That spot joins the sorted part, which grows by one every pass until the whole list is ordered.
Why it matters. Selection sort teaches scanning for extremes and growing an answer one place at a time. Its swap-once-per-pass style contrasts nicely with the many swaps of bubble sort.
Key words
- Selection Sort
- : Sorting by selecting the smallest leftover value each pass.
- Sorted Part
- : The left section already fixed in final order.
- Unsorted Part
- : The right section still waiting to be ordered.
- Leftmost Spot
- : The first open position of the unsorted part.
Try it in two minutes
- Line up five number cards and find the smallest by scanning.
- Swap it with the leftmost card.
- Ask which part is now sorted and repeat.
Try at home. Ask your child to selection sort five cards and mark the sorted part after each pass.
Insertion Sort
Part of: Selection and insertion sorts
Insertion sort grows a sorted hand one card at a time, like arranging playing cards. It lifts the first unsorted card, shifts larger sorted cards one step right to open a gap, and slips the card into its right place. After pass two, three cards stand sorted, and the rest follow the same way.
Why it matters. Insertion mirrors how people naturally order things and shines on nearly sorted lists. Learning its shift-then-place move prepares learners for smarter methods later.
Key words
- Insertion Sort
- : Sorting by slipping each card into its place among sorted cards.
- Shifting
- : Moving sorted cards one step right to open a gap.
- Sorted Hand
- : The cards already arranged in final order.
- Gap
- : The open spot where the lifted card belongs.
Try it in two minutes
- Hold one card as the sorted hand and lift the next card.
- Shift bigger cards right until the gap is found.
- Slip the card in and count the sorted hand.
Try at home. Ask your child to insertion sort five cards and count the shifts in each pass.
What your child will practise
- Bubble Sort: Desert Quick Fire (Quick Fire)
- Insertion Sort: Candy Puzzle (Clue Puzzle)
- Insertion Sort: Space Quick Fire (Quick Fire)
- Selection Sort: Ocean Quick Fire (Quick Fire)
- Why Sort and What It Costs: Space Puzzle (Clue Puzzle)
- Quiz: Bubble Sort (8 questions)
- Quiz: Insertion Sort (8 questions)
- Quiz: Selection Sort (8 questions)
- Quiz: Why Sort and What It Costs (8 questions)