Programming Fundamentals - Language Concepts and Problem Solving (Vocabulary)
1.0 Introduction to Programming Language
Definition: A programming language is a formal language comprising a set of instructions that can be used to produce various kinds of output. It is the means by which humans communicate tasks to a computer.
Purpose: To command and instruct machines to perform tasks and compute results (e.g., add two numbers) and to obtain the correct answers.
Real-world relevance: The programming language is the fundamental unit in today’s tech world for building software, applications, and systems.
1.1 Describe the programming language
Learning outcomes (as listed):
1.1 Describe the programming language.
1.2 Describe fundamentals of programming languages.
1.3 Identify problem solving concepts.
1.4 Describe the different types and patterns in algorithms to solve problems.
2.0 History and Approaches to Programming Languages
Overview: History of programming languages and approaches to programming.
Key topics to cover:
Types of programming languages
Generations of programming languages
How languages evolved from low-level to high-level abstractions
2.1 History of programming language and approaches
Claim: Programming language is the fundamental unit of today’s tech world; languages command machines to perform tasks by following instructions.
Early example concepts: Binary instructions directly understood by computers (machine language).
2.2 Types of programming languages
Three broad categories historically discussed:
Machine language (low-level)
Assembly language (low-to-mid level)
High-level language (high-level)
General idea: Higher-level languages are closer to human language and require translation to machine code.
2.3 Generations of programming languages
Generations overview (overview from pages on generations):
1st generation: Machine language (low-level)
2nd generation: Assembly language (low-level, human-readable mnemonics)
3rd generation: High-level languages (procedural, English-like statements)
4th generation: Non-procedural, database-oriented, human-friendly; examples include SQL, Perl, Python, MATLAB, etc.
5th generation: Based on AI concepts; problem-solving by constraints rather than explicit algorithms (e.g., Prolog, Mercury, OPS5).
3.0 First to Fifth Generations — Details, Examples, and Trade-offs
1st generation (Machine Language)
Characteristics: Direct binary instructions; machine understands 0/1; no translator required; fastest execution but hard to write and debug.
Advantages: Fast and efficient; no translator required.
Disadvantages: Difficult to learn; hard to read and locate errors.
Example: A sequence of binary numbers such as
10100001 ext{ }10111100 ext{ }10010011 ext{ }00000100
00001000 ext{ }00000011 ext{ }00000101 ext{ }11000000
10010011 ext{ }00000100 ext{ }00001000 ext{ }10100011
11000000 ext{ }10010100 ext{ }00000100 ext{ }00001000
2nd generation (Assembly Language)
Characteristics: Developed after machine language; uses mnemonic codes (letters, digits, symbols) to represent instructions; requires an assembler to translate to machine language.
Advantages: More readable than machine language.
Disadvantages: Requires assembler; still machine-dependent.
Example: Simple assembly code snippet (illustrative):
section .text
global _start
_start:
mov edx, len
MOV ecx, msg
etc.
3rd generation (High Level Language, Procedural)
Characteristics: Use English-like statements to write computer instructions; easy to understand; requires translation to machine language via a compiler or interpreter.
Advantages: Easier to understand; fewer lines of code; code can be ported to other machines with appropriate compilers.
Disadvantages: Initially still required assemblers in some contexts; different compilers may be needed for different machines.
Examples: C, C++, Java, Visual Basic, JavaScript.
Example (C/C++ style):
#include<iostream> using namespace std; int main() { cout << "Hello World!" << endl; return 0; }4th generation (Non-procedural, Non-imperative, closer to human language)
Characteristics: Focuses on data handling; database access; more human-friendly; higher abstraction level.
Advantages: Easier to write and read; more database-centric capabilities.
Disadvantages: Higher memory consumption; less hardware control; less flexible.
Examples: Perl, Python, Ruby, SQL, MATLAB.
Example: SQL snippet
ext{SELECT CustomerName, City FROM Customers;}
5th generation (AI-based)
Characteristics: Based on artificial intelligence; solves problems by constraining solutions rather than prescribing exact steps; computers can learn to solve problems.
Advantages: Machines can make decisions; programmer effort reduced.
Disadvantages: Complex and long code; resource-intensive and expensive.
Examples: Mercury, OPS5, Prolog.
Prolog example:
findmax(X, Y, X) :- X >= Y, !. findmax(X, Y, Y) :- X < Y. findmin(X, Y, X) :- X =< Y, !. findmin(X, Y, Y) :- X > Y.
4.0 Algorithms and Problem-Solving Patterns
What is an algorithm?
A step-by-step set of instructions or procedure used to solve a problem or perform a task in programming.
It is a logical sequence that tells the computer what to do and how to do it.
Problem-solving patterns in algorithms:
Sequential (Sequence): Execute steps one after another; each step depends on the previous.
Conditional (Selection): Make decisions; choose between actions based on conditions.
Iterative (Repetition): Repeat a set of steps until a condition is met or a repetition count is reached.
Practical note: There are multiple patterns; the transcript emphasizes three core patterns and includes references to different representations (e.g., flowcharts).
5.0 Algorithms Patterns — Details
Sequential structure example: step1 → step2 → … → step_n
Conditional structure example: If condition then codeblocktrue else codeblockfalse End if
Iterative structure example: Repeat steps until condition is met (or while condition holds)
Different pattern names: Sequential, Conditional, Iterational; sometimes called Sequence, Selection, and Repetition in various texts.
5.1 Example Algorithms (illustrative)
Morning routine algorithm example:
Get up from bed
Shower
Get dressed
Have breakfast
Go to school
Average of three numbers example:
Set Total = 0, Average = 0
Input number1, number2, number3
Total = number1 + number2 + number3
Average = Total / 3
Display Average
Formula representations: ext{Total} = ext{number1} + ext{number2} + ext{number3}
ext{Average} = rac{ ext{Total}}{3}
Salary calculation example (hourly basis):
Salary = hourswork × payrate
Formula representation: ext{Salary} = ext{hours extunderscore work} imes ext{pay extunderscore rate}
5.2 Flowcharts — Visual representation of algorithms
What is a flowchart?
Graphic representation of an algorithm; shows flow from start to end using symbols connected by arrows.
Helps visualize input, processing, decisions, and outputs.
Standard symbols (common set):
Terminal: beginning and end of a process
Process: processing steps or computations
Data / Input-Output: data input or results output
Decision: a point where a decision is made (branching)
Connector: lines to connect parts of the chart
On-page connector: connects parts on the same page
Off-page connector: connects parts across pages
Example flow: START → INPUT → PROCESS → OUTPUT → END
Flowchart example tasks:
Average of 3 numbers (generate algorithm → flowchart)
Smallest of two numbers (decision exercise)
Display numbers 1 to 10 (repetition exercise)
5.3 Example: Flowchart and Algorithm for average of 3 numbers
Algorithm (same as earlier):
Set Total = 0, Average = 0
Input number1, number2, number3
Total = number1 + number2 + number3
Average = Total / 3
Display Average
Flowchart steps mirror the algorithm: Start → Input → Compute → Compute → Output → End
5.4 Flowchart and Algorithm for smallest of two numbers
Algorithm:
Input num1 and num2
If num1 < num2, print "Smallest is Number 1"; else print "Smallest is Number 2"
Flowchart would include a decision symbol to compare num1 and num2 and branching to two outputs.
5.5 Flowchart and Algorithm for displaying numbers 1 through 10
Algorithm: initialize x = 0; increment x by 1; print x; if x < 10, repeat
Flowchart includes a loop/decision to continue until 10 is reached.
6.0 Problem-Solving Tools: Flowcharts, Pseudocode, and Pseudo-Algorithms
Tools to illustrate algorithms: Flowcharts, Pseudocodes (pseudo code)
Pseudocode characteristics:
Semi-formal representation mixing programming-like steps with natural language
Not directly executable by a computer; used for planning and communication
Purpose of pseudocode:
Helps focus on problem-solving steps rather than syntax
Useful as a bridge between an algorithm and actual code
Pseudo code guidelines and best practices:
Statements should be short, clear, and readable
Each statement should have a single meaning
Outline with clear Begin and End
Use INPUT/READ, OUTPUT/PRINT to denote I/O operations
Indentation should reflect program structure to show hierarchy
Keep it simple; avoid overly complex terms
Write in logical order; review and refine
6.1 Pseudo code — Example and purpose
Example pseudo code fragment (illustrative):
START
INPUT hourswork, payrate
CALCULATE Salary = hourswork * payrate
DISPLAY Salary
ENDPseudocode is a teaching and planning tool, not a language syntax; it cannot be compiled or interpreted by a computer.
7.0 Practical Problem-Solving Exercises and References
Exercise 1 (Algorithm): Write an algorithm to prompt the user to enter two numbers, calculate the sum and average, and display the output.
Exercise 2 (IPO and Pseudocode): Write problem analysis (Input-Process-Output), algorithm, pseudo code, and flowchart for the scenario: You bought shoes costing RM250 with a 10% discount. Compute the net price.
These exercises reinforce identifying inputs, operations, and outputs, and translating problem statements into step-by-step procedures, pseudocode, and flowcharts.
8.0 Additional Course Details and Closing Notes
The content is organized into sections for: Introduction, Fundamentals, Problem Solving, Algorithms, Flowcharts, Pseudocode, and Exercises.
The course emphasizes connecting theoretical concepts to practical representations (code, diagrams, and human language).
Contact and next class information:
Politeknik Mukah, rozaidahalil@pmu.edu.my
Next class topic: TOPIC 2
9.0 Summary of Key Formulas and Concepts
Algorithm definition: A step-by-step procedure to solve a problem.
Sequential pattern: Steps executed in order; each step depends on the previous one.
Conditional pattern: Decision-based branching; different paths based on conditions.
Iterative pattern: Repetition until a condition is satisfied.
Flowchart elements: Start/End, Input/Output, Process, Decision, Connectors, On-page/Off-page connectors.
Fundamental data flow: Input → Process → Output (IPO) model is used to analyze problems.
Optional but common formulas used in examples:
ext{Total} = ext{number1} + ext{number2} + ext{number3}
ext{Average} = rac{ ext{Total}}{3}
ext{Area of circle} = ext{PI} imes r^2, ext{ with } ext{PI} ext{ taken as } 3.142
ext{Salary} = ext{hours extunderscore worked} imes ext{pay extunderscore rate}
(Titles presented as top-level headings in the notes above are intended to align with the presentation structure. Each section contains concise bullet points of the major and minor ideas, definitions, examples, and practical implications from the transcript.)