The Collection Is Unsorted
You cannot assume smaller values appear before larger values. The collection provides no ordering that would allow you to eliminate possible matches based on value.
CORRECT CODE INVESTIGATION / CASE FILE #001
Before investigating a solution, establish what the problem requires and what must be understood to solve it.
THE CASE
Imagine receiving a collection of numbers and being asked to find a particular number within it.
You are not given a guarantee that the numbers are sorted, and you cannot assume that the target exists. Your task is to determine whether the target appears and, if it does, identify the position of its first occurrence.
This is a fundamental searching problem in computer science. Although the objective sounds simple, its requirements determine what constitutes a correct solution.
Finding information within a collection is one of the most common operations performed in software.
This problem introduces foundational Data Structures and Algorithms concepts:
THE OBSTACLES
Finding a number sounds simple. However, the requirements introduce constraints that influence how a valid solution must be constructed.
You cannot assume smaller values appear before larger values. The collection provides no ordering that would allow you to eliminate possible matches based on value.
Your solution must account for the possibility that no matching element is found. A valid solution must define what happens when the target is absent.
If the target appears multiple times, returning any matching position is insufficient. The required answer is the earliest matching position.
Finding the target's value does not satisfy the requirement. The solution must identify its position within the collection.
To establish that a match is the first occurrence, earlier positions must already have been accounted for. A matching value alone does not establish that the answer is correct.
Several foundational concepts will become important during the investigation:
CONVENTIONAL INSTRUCTION
Traditionally, students are introduced to a collection, a target value, and a familiar sequence of programming instructions for examining the collection.
The instruction commonly begins by showing how to examine elements one at a time, compare each value with the target, and determine whether a match exists.
The solution is then expressed in a programming language, followed by a discussion of time and space complexity.
This teaching approach can help students learn how a familiar searching procedure works. However, it can also encourage learning based on recognizing a familiar problem and recalling a familiar sequence of instructions.
Students may learn to associate an unsorted collection with a particular searching procedure without fully understanding:
THE CCF METHODOLOGY
The Correct Code Framework approaches a problem by establishing the reasoning required to construct a valid solution before selecting an implementation.
Rather than beginning with a familiar algorithm, CCF organizes the problem into distinct reasoning spaces. Each space addresses a different part of establishing a valid solution.
What information is available, and what conditions govern the problem?
What result must a valid solution produce?
What decisions must be made to connect the available information to the required answer?
Understanding the problem is not the same as establishing its solution. CCF develops the reasoning needed to justify each successive part of that solution.
INVESTIGATION AUTHORIZED
You have been introduced to the problem, its requirements, its constraints, and the reasoning methodology that will guide the investigation.
The investigation begins with the Base Component: establishing the identity of the solution before determining how that solution will be constructed.
The Base Component provides the starting point for organizing the reasoning that follows. The investigation will establish how the problem's information, required answer, and necessary decisions contribute to a valid solution.