![]() |
|
Programming Fundamentals — Logic, Structure, Algorithms & Problem-Solving - Printable Version +- The Lumin Archive (https://theluminarchive.co.uk) +-- Forum: The Lumin Archive — Core Forums (https://theluminarchive.co.uk/forumdisplay.php?fid=3) +--- Forum: Computer Science (https://theluminarchive.co.uk/forumdisplay.php?fid=8) +---- Forum: Programming & Algorithms (https://theluminarchive.co.uk/forumdisplay.php?fid=26) +---- Thread: Programming Fundamentals — Logic, Structure, Algorithms & Problem-Solving (/showthread.php?tid=99) |
Programming Fundamentals — Logic, Structure, Algorithms & Problem-Solving - Leejohnston - 11-13-2025 Programming Fundamentals — Logic, Structure, Algorithms & Problem-Solving Programming is the art of turning ideas into instructions a computer can follow. This thread introduces the essential concepts needed to understand code, algorithms, and computational thinking. ----------------------------------------------------------------------- 1. What Is Programming? Programming is the process of writing instructions that computers execute. Languages include: • Python • JavaScript • C / C++ • Java • Rust • Go • Swift All languages share the same core ideas: • variables • data types • logic • loops • functions • algorithms ----------------------------------------------------------------------- 2. Variables & Data Types Variables store information. Common data types: • integers (whole numbers) • floats (decimals) • strings (text) • booleans (True/False) • lists/arrays • dictionaries/maps Example in Python: Code: age = 21----------------------------------------------------------------------- 3. Control Flow — Making Decisions Programs make decisions using conditions. Example: Code: if temperature > 30:Comparison operators: • > • < • >= • == • != ----------------------------------------------------------------------- 4. Loops — Repeating Instructions Loops repeat code until a condition is met. For loop: Code: for i in range(5):While loop: Code: while x < 10:Loops are vital for: • simulations • processing lists • iterating over data • automation ----------------------------------------------------------------------- 5. Functions — Reusable Blocks of Code Functions organise code into reusable pieces. Example: Code: def add(a, b):Benefits: • avoids repetition • clearer structure • easier debugging ----------------------------------------------------------------------- 6. What Is an Algorithm? An algorithm is a step-by-step method for solving a problem. Example: “Find the largest number in a list” 1. assume first number is largest 2. check each number 3. if a number is bigger → update largest 4. output result Programming = implementing algorithms in code. ----------------------------------------------------------------------- 7. Common Algorithms Sorting: • bubble sort • merge sort • quicksort Searching: • linear search • binary search Graph algorithms: • Dijkstra’s shortest path • A* search Data structure basics: • stacks • queues • linked lists • trees • hash maps These form the basis of computer science. ----------------------------------------------------------------------- 8. Big O Notation (Time Complexity) Big O describes how fast an algorithm grows as input size increases. Examples: • O(1) → constant • O(n) → linear • O(n²) → quadratic • O(log n) → logarithmic Why it matters: • performance • scalability • optimisation ----------------------------------------------------------------------- 9. Good Programming Practices ✔ write clean, readable code ✔ comment important sections ✔ use descriptive variable names ✔ test your code ✔ break problems into smaller parts ✔ avoid duplication (DRY principle) ✔ version control (Git) ----------------------------------------------------------------------- 10. Common Mistakes ❌ Forgetting indentation (Python) ✔ indentation defines structure ❌ Infinite loops ✔ ensure loop conditions eventually become False ❌ Using = instead of == in conditions ✔ = assigns, == compares ❌ Not testing small pieces first ✔ build and test in steps ❌ Hardcoding everything ✔ use variables and functions ----------------------------------------------------------------------- 11. Beginner Practice Questions 1. Write pseudocode for deciding if a number is even or odd. 2. What is the difference between a list and a dictionary? 3. Explain how binary search works. 4. What does O(n) mean in time complexity? 5. Write a function that returns the square of a number. ----------------------------------------------------------------------- Summary This thread covered: • variables • decision making • loops • functions • algorithms • Big O notation • good practices • common mistakes • practice questions Programming is problem-solving — and this forum is your space to learn, experiment, and build. |