Learn C Programming

Lesson 3 of 9 · Arrays

Module 9 · Arrays

Searching and Frequency Counting

Free with an accountReading

The class votes on the end-of-year trip, and each ballot carries the voter's student number. David hunts for double votes by comparing each ballot with every earlier one. Amara ticks one box per student number instead, and a box already ticked is a double vote.

Sign in to read

This lesson is free, with an account

An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.

What is inside Searching and Frequency Counting

  1. Linear search, and why not found is -1
  2. A count array: the value is the index
  3. The first double vote, in one pass
  4. Every pair against one pass, measured
  5. The sieve of Eratosthenes
  6. Prefix sums: running totals in one pass