Computational Thinking, Programming, and Algorithms Notes

Searching Algorithms

  • Searching algorithms find specific items within a dataset.

  • Linear search inspects items sequentially from first to last until the target value is found or all items are checked.

Boolean and Logical Operators

  • Precedence order: 1. NOT, 2. AND, 3. OR (brackets override default precedence).

  • Relational operators: greater than (>), less than (<), greater than or equal (>=), less than or equal (<=), equal (==), and not equal (!=).

  • Python Boolean operators are written in lowercase: and, or, and not.

Conditional Statements

  • if statements execute code blocks defined by indentation only when a condition is True.

  • else statements execute when the if condition evaluates to False.

  • elif statements test multiple sequential conditions when preceding conditions evaluate to False.

Data Types, Constants, and Flags

  • Standard data types: integer, real, character, string, and Boolean.

  • bool() converts data to Boolean: 00 and empty strings "" evaluate to False, while non-zero numbers and non-empty strings evaluate to True.

  • Constants store fixed values using uppercase identifiers in Python (e.g., TEN, COST).

  • Flags are Boolean variables used to indicate whether a specific event has occurred.

Sub-routines and Libraries

  • Functions are sub-routines that return a value to the main program using return.

  • Procedures execute instructions without returning a value.

  • Parameters are input values passed to sub-routines in parentheses.

  • Key Python library tools:

    • math.ceil(): rounds decimals up to the next integer.

    • math.pi: returns the constant \n\n\pi.

    • random.randint(smallest, largest): generates a random whole number within an inclusive range.

Software Development and Testing

  • Decomposition breaks down a complex problem into smaller sub-problems.

  • Iterative development builds programs incrementally through repeating cycles of coding, testing, and modifying.

  • Test data types:

    • Normal: standard expected inputs within valid bounds.

    • Invalid: inputs outside allowable limits to verify error handling.

    • Boundary: inputs located on the exact edges of acceptable ranges.