Java data-structure and algorithm programs preserve a representation invariant or a recurrence while making their input assumptions explicit.
Count the whole operation
Binary search needs ordered input. Sorting an unsorted batch first is part of the cost. Recursion depth is not the same quantity as total work across all branches.
Common Mistakes
Test empty input, repeated values, boundary values, and an absent result. A correct output for one small fixture does not establish correctness for every valid input.
Working through this section
The curriculum below groups the canonical pages for this section. Open a lesson to see its release label, operation contract and connected topics. Examples can also be linked from another section without creating a second copy of the same page.
Compile the stated program with a compatible JDK and compare its result with the displayed output. Read the rejected-input and ownership clauses before changing the input. Local self-checks and downloaded programs do not imply a server-side code judge or a production service.
