Before You Solve the Problem
Understand the Environment
Every algorithm begins with three questions:
- What output must I return? Answer Space
- What information am I given? Problem Space
- What rules and movement are allowed as each Candidate is evaluated for admission into the Answer Space? Decision Space
Case File #001 teaches you how to identify these three spaces before writing code.
numbers is a Candidate
until the evidence either confirms it as the target or eliminates it.Read the Problem Statement for Context Clues
Before choosing an answer, identify the words that describe what the solution must return. In this case, return-language helps define the Answer Space.
Type: Linear Scanner
Watch the Scanner evaluate one Candidate at a time. The first candidate that satisfies the Invariant completes the investigation.Problem Statement
Given an unsorted array of integers called numbers and an integer called target, return the index of the first occurrence of target.
Search the array from left to right.
If target does not appear in the array, return -1.