Basics of Programming and Algorithm Design
Fundamentals of Computer Programming
- Computer Program: A sequential set of instructions, known as codes, written or "programmed" in a computer language to let the computer perform a specific computation task.
- Execution Principle: Instructions in a computer program must be performed sequentially unless explicitly directed otherwise. Each instruction expresses a unit of work that a computer language can support.
- Software Examples:
- System software
- Web browsers
- Utility software
- Multimedia software
- Spreadsheet software
- Computer / Programming Language: A set of grammatical rules that commands a computer or a device to behave in a specific way.
- Programming: The art and science of instructing computers to perform tasks using a specific programming language. It creates codes that tell a computer how to solve problems and accomplish various operations.
- Applications of Programming:
- Developing computer programs and software applications
- Designing websites
- Analyzing data
- Automating processes
- Career Opportunities: Software development, web development, data science, and artificial intelligence.
- Cognitive Benefits: Enhances critical thinking, logical reasoning, and problem-solving abilities, enabling programmers to break down complex tasks into manageable steps and develop efficient algorithms.
Evolution and History of Programming
- Initial Stage: Programming originally involved writing machine code consisting of binary instructions (0 and 1) directly communicating with the computer's hardware.
- Development of High-Level Languages: As technology progressed, high-level programming languages were developed to simplify the coding process by utilizing human-readable syntax.
- Modern Ecosystem: A broad ecosystem of programming languages and tools exists to cater to different programming paradigms and application domains.
Programming Paradigms
- Definition: Conceptual frameworks and approaches to structuring and organizing code to solve problems and design software (synonymous with "pattern").
- Procedural Programming (Imperative Programming):
- Focuses on organizing code into reusable procedures or functions.
- Emphasizes the sequence of steps required to execute a program.
- Examples: BASIC, C, C++, Pascal, Java.
- Object-Oriented Programming (OOP):
- Revolves around objects that encapsulate data and behavior.
- Promotes modularity, code reusability, and scalability.
- Examples: Python, VB.NET, C#.
- Functional Programming:
- Treats computation as evaluating mathematical functions.
- Emphasizes consistency and avoids side effects.
- Selection Criteria: Choosing a paradigm depends on project nature, requirements, and desired programming style.
Classification of Programming Languages
- Low-Level Languages:
- Close to machine code and hardware in syntax.
- Provides direct control over hardware and resources, enabling fine-detailed coding.
- Used for tasks requiring precise control and efficient execution.
- Assembly Language: Uses specific instructions to control computer hardware.
- Machine Language: All instructions are written strictly as binary numbers (0 and 1).
- High-Level Languages:
- Designed to be easy for humans to read, write, and understand.
- Enables programming without specific knowledge of the processor or hardware on which the program runs.
- Examples: C++, Pascal, PHP, Python, Java.
- Selection Criteria: Language choice depends on project requirements, performance needs, community support, and available libraries or frameworks.
Core Programming Terminologies
- Syntax: A set of rules defining combinations and arrangements of symbols or characters to create a valid statement in a language.
- Command: A unique instruction given to a computer application to perform a specific task or function (e.g., "print" to display text on screen).
- Integrated Development Environment (IDE): A software application for formatting code, checking syntax, and running and testing code. IDEs can support single or multiple programming languages.
- Library: A pre-built or installed collection of useful resources (such as objects and functions) within an IDE that can be used individually and configured to work together.
- Interpreter: A program that directly executes instructions written in a high-level language without converting them into machine language.
- Assembler: A program that converts instructions written in low-level assembly code into relocatable machine language.
- Compiler: A program that converts high-level languages into machine-readable code that a computer can execute.
Algorithms
- Definition: A set of steps that generates a finite sequence of simple computational operations leading to the solution of a given problem. It must be expressed in a natural language (e.g., English) that anyone can follow.
- Steps in the Programming Problem-Solving Process:
- Problem Analysis: Evaluating and outlining the problem and its solution requirements.
- Algorithm Design: Designing an algorithm to solve the problem.
- Coding: Implementing the algorithm in a programming language.
- Execution: Verifying whether the algorithm works or not.
- Algorithmic Example (Rectangle Volume):
- Problem: Find and display the volume of a rectangle given its length, width, and height.
- Required Formula: volume=length×width×height
- Step-by-step Algorithm:
- Get the length of the rectangle
- Get the width of the rectangle
- Get the height of the rectangle
- Find the volume using the formula: volume=length×width×height
- Display the computed volume
- Algorithm Representation Tools: Pseudocode and Flowchart.
Pseudocode
- Definition: A technique used to describe distinct steps of an algorithm in a format that is simple to understand for anyone with basic programming knowledge.
- Standard Symbols & Operations:
- Arithmetic operations: +, −, ∗, /
- Assignment: =
- Comparison: ==, =, <; >
- Relational bounds: ≤, ≥
- Logical operations: AND, OR
- Command Keywords: PRINT, WRITE, READ, SET, GO TO
- Formatting: Indentation is used to indicate branches and loops of instructions.
- Pseudocode Example (Rectangle Volume):
- READ length
- READ width
- READ height
- SET volume to 0
- COMPUTE volume as length * width * height
- PRINT volume
Flowcharts
- Definition: A diagrammatic or pictorial representation of the steps of an algorithm, serving as an easily understood substitute for textual descriptions.
- Categories of Flowcharts:
- Program Flowcharts: Illustrate logical steps in a software program or programming task to understand a process, workflow, or algorithm. They contain steps to solve a problem unit for a specific result.
- System Flowcharts: Show how parts of a system work together by displaying data flow and how decisions affect surrounding events.
- Standard Program Flowchart Symbols:
- Terminal: Shows the start and end of a set of computer-related processes.
- Input/Output: Shows any input or output operation.
- Computer Processing: Shows any processing performed by a computer system.
- Predefined Processing: Indicates any process not specially defined in the flowchart.
- Comment: Used for writing any explanatory statement required to clarify something.
- Flow line: Used for connecting symbols to indicate direction of flow.
- Document Input/Output: Used when input comes from a document and output goes to a document.
- Decision: Shows any point in the process wherein a decision must be made to determine further action.
- On-page Connector: Connects parts of a flowchart continued on the same page.
- Off-page Connector: Connects parts of a flowchart continued to separate pages.
- Five (5) Rules for Creating Program Flowcharts:
- Only standard symbols should be used in program flowcharts.
- Program logic should only show flow from top to bottom and/or left to right.
- Each symbol should contain only one entry point and one exit point, except the decision symbol (known as the single rule).
- Operations shown within a symbol should be expressed independently of any programming language.
- All decision branches should be well-labeled.
Academic References
- Chaudhuri, A. (2020). Flowchart and algorithm basics: The art of programming. Mercury Learning and Information.
- DG Junior (2023). Basics of programming: A comprehensive guide for beginners. DG Junior.