## Procedural Programming Concepts
Procedural programming is a paradigm based on the concept of the **procedure call**. Programs are
structured as a sequence of statements that modify a global or local state, broken down into functions or
subroutines.
### Key Constructs
All procedural programs are built using three basic control structures:
* **Sequence:** Executing instructions one after the other in the order they are written.
* **Selection:** Using conditions to determine which path of execution to follow (e.g., `if/else`
statements or `switch/case`).
* **Iteration:** Repeating a block of code a set number of times (**count-controlled** like `for` loops)
or until a condition is met (**condition-controlled** like `while` or `repeat/until` loops).
## Functions, Procedures, and Scope
Subroutines (or subprograms) are blocks of code designed to perform a specific task. They make code
modular, reusable, and easier to debug.
* **Procedures:** Perform a task but **do not return a value** to the main program.
* **Functions:** Perform a task and **must return a value** back to the calling statement.
### Parameter Passing
When passing data into subroutines, it can be done in two ways:
1. **Passing by Value (ByVal):** A copy of the data is passed into the subroutine. Any changes made to
the parameter inside the subroutine *do not* affect the original variable outside it.
2. **Passing by Reference (ByRef):** The actual memory address of the variable is passed. Any changes
made inside the subroutine *will* permanently change the original variable outside it.
### Variable Scope
* **Local Variables:** Declared inside a specific subroutine. They only exist while that subroutine is
running and cannot be accessed by other parts of the program. This frees up memory and prevents
accidental overwrites.
* **Global Variables:** Declared at the top level of the program. They are accessible by any subroutine
throughout the entire lifecycle of the program. Overusing them is considered poor practice as they make
debugging difficult.
## Object-Oriented Programming (OOP)
OOP is a paradigm that organizes software design around **data**, or **objects**, rather than
functions and logic. An object can be defined as a data field that has unique attributes and behavior.
### Core OOP Concepts
* **Class:** A blueprint or template used to create objects. It defines the attributes (data) and methods
(behaviors) that the objects will have.
* **Object:** An instance of a class. For example, if `Car` is a class, `myAudi` is an object.
* **Instantiation:** The process of creating an actual object from a class blueprint using a constructor
method.
### The Four Pillars of OOP
| Pillar | Definition | Example Scenario |
| **Encapsulation** | Hiding the internal state of an object and requiring all interaction to occur
through public methods (Getters and Setters). Attributes are usually set to `private`. | Preventing direct
access to a `bankBalance` variable; it can only be changed via a `deposit()` method. |
| **Inheritance** | Allowing a new class (subclass/child) to adopt the attributes and methods of an
existing class (superclass/parent), promoting code reusability. | A `Dog` class and a `Cat` class both
inheriting attributes like `age` and `breed` from an `Animal` class. |
| **Polymorphism** | The ability of different classes to process objects differently depending on their
data type. It allows a single method name to behave differently in subclasses (**Method Overriding**).
| Calling `.makeSound()` on an `Animal` object results in “Woof” if it’s a `Dog` or “Meow” if it’s a `Cat`. |
| **Abstraction** | Hiding complex implementation details and only showing the essential features of
an object to reduce complexity. | A user knows how to call a `.drive()` method on a car object without
needing to know how the internal engine code calculates fuel consumption. |
## Integrated Development Environment (IDE) Tools
An IDE is a software application that provides comprehensive facilities to programmers for software
development. Core tools include:
* **Source Code Editor:** Features like syntax highlighting, auto-completion, and automatic indentation
to make code readable.
* **Error Diagnostics:** Real-time flagging of syntax errors before compilation or interpretation.
* **Debugging Tools:** * *Breakpoints:* Pausing code execution at a specific line to inspect the current
state.
* *Watch Window:* Monitoring the value of specific variables in real-time as the code steps through.
* *Stepping (Step Over/Into):* Executing the program line-by-line to find logic errors.
## Standard Algorithms: Searching & Sorting
You are required to understand the logic, efficiency, and implementation of core algorithms.
### Searching Algorithms
* **Linear Search:** Examines every element in a list sequentially from start to finish until the item is
found. Works on **unsorted** lists. Time complexity is $O(n)$.
* **Binary Search:** Continually divides a list in half by comparing the target item to the middle
element. It requires the list to be **sorted**. Time complexity is $O(\log n)$.
### Sorting Algorithms
* **Bubble Sort:** Repeatedly steps through the list, compares adjacent elements, and swaps them if
they are in the wrong order. Passes through the list until no swaps are needed. $O(n^2)$.
* **Insertion Sort:** Builds a final sorted array one item at a time by taking elements from an unsorted
portion and inserting them into their correct position. $O(n^2)$.
* **Merge Sort:** A divide-and-conquer algorithm that splits the list into individual sub-lists, then
merges them back together in perfect sorted order. $O(n \log n)$.
Would you like to look at code implementations (such as Python or pseudocode) for one of these sorting
algorithms, or dive into Object-Oriented syntax specifics?