| Term | Definition |
|---|---|
| Programming language | A formal language consisting of a set of symbols, keywords, syntax rules and semantic rules used to communicate instructions to a computer; the means through which programmers express algorithms that can be translated into machine-executable instructions. |
| Syntax | The grammatical rules governing how program statements are written · it specifies the legal structure of programs. |
| Semantics | The meaning associated with syntactically correct statements. Syntax determines structure; semantics determines meaning. |
| Language specification | A formal document describing all aspects of a programming language · syntax, semantics, data types, operators, control structures, libraries and runtime behaviour. It is the authoritative reference for implementation and usage. |
| Grammar / BNF | A formal description of how valid program constructs can be formed. The most common notation is Backus–Naur Form, e.g. <assignment> ::= <identifier> = <expression>. |
| Data type | A classification specifying the kind of values that can be stored, the operations permitted on them, the memory required, and the interpretation of the stored data. It defines a set of values and a set of permissible operations. |
| Type system | A set of rules governing how data types are defined, checked and used in a language, determining what values variables may contain, what operations are permitted and how errors are detected. |
| Static typing | Type checking performed during compilation. |
| Dynamic typing | Type checking performed during program execution. |
| Type safety | The extent to which a language prevents invalid operations. |
| Data abstraction | The process of hiding implementation details while exposing only essential features, so programmers focus on what something does rather than how it is implemented. |
| Data structure | A method of organizing and storing data in a computer so that it can be accessed and modified efficiently. |
| Abstract Data Type | A logical description of a data structure specifying the data it stores and the operations that can be performed, without specifying implementation details · what the structure does, not how it is implemented. |
| Parse tree | A tree that represents the grammatical structure of a program according to the language grammar; generated during syntax analysis. |
| Abstract Syntax Tree | A simplified version of a parse tree that removes unnecessary grammar details while preserving program meaning. |
| Control structures | The mechanisms that determine the order in which operations are executed; they govern flow of execution, decision-making, repetition and how functions interact. |
| Control flow | The order in which statements, instructions or function calls are executed in a program. |
| Recursion | A control mechanism in which a function calls itself to solve a problem, consisting of a base case that terminates it and a recursive case that calls itself with a smaller problem. |
| Scope | Where a variable can be accessed within a program · it controls variable visibility and lifetime. |
| Variable lifetime | The period during which a variable exists in memory. It depends on scope, storage allocation method and program execution state. |
| Data flow | How information moves through a program · between variables, functions, modules and program components. |
| Structured programming | A paradigm emphasizing sequence, selection and iteration while avoiding uncontrolled jumps such as excessive use of GOTO. |
| Gen | Type | Example | Characteristics |
|---|---|---|---|
| 1GL | Machine language | 10110000 01100001 | Machine dependent · difficult to understand · fast execution |
| 2GL | Assembly language | MOV AX, 5ADD AX, 2 | Symbolic instructions · requires an assembler · hardware dependent |
| 3GL | High-level | C++, Java, Python, JavaScript | High-level abstraction · portable · easier development |
| 4GL | Logic / AI-oriented | Prolog | Logic-based · knowledge representation · AI applications |
SYNTAX · is it legally written? Correct: x = 10 Incorrect: = x 10 ← violates the rules SEMANTICS · what does it mean? x = 10 + 20 Syntax says: correctly written. Semantics says: add 10 and 20, store in x.
| Goal | Definition | Achieved through |
|---|---|---|
| Readability | The ease with which programs can be understood, including code written by others | Simplicity · consistency · clear syntax · meaningful keywords |
| Writability | The ease with which programmers can create programs | Powerful constructs that reduce development effort |
| Reliability | The ability of a program to perform according to its specification under various conditions | Strong type checking · exception handling · restricted operations |
| Maintainability | The ease with which software can be modified, corrected or extended | Modular design · clear documentation · consistent coding standards |
| Efficiency | The effective utilization of system resources | CPU time · memory · storage · why C++ suits performance-critical work |
Meaning: an assignment statement consists of an identifier, an assignment operator and an expression. The statement x = y + z satisfies this rule.
PYTHON
age = 20
if age >= 18:
print("Adult")JAVASCRIPT
let age = 20;
if (age >= 18) {
console.log("Adult");
}C++
#include <iostream>
using namespace std;
int main() {
int age = 20;
if (age >= 18) {
cout << "Adult";
}
return 0;
}The observation to write: all three implement the same logic, but differ in syntax, type systems, block structures and execution models · and those differences reflect distinct language design philosophies.
| Principle | Python | JavaScript | C++ |
|---|---|---|---|
| Block structure | Indentation | Braces | Braces |
| Typing style | Dynamic | Dynamic | Static |
| Compilation model | Interpreted | JIT / interpreted | Compiled |
| Complexity | Low | Medium | High |
| Memory control | Automatic | Automatic | Manual / automatic |
| Readability | Very high | High | Moderate |
| Runtime speed | Moderate | Moderate | High |
Formally, a data type defines a set of values and a set of permissible operations.
| Category | Definition | Examples |
|---|---|---|
| Primitive | The basic building blocks provided directly by the language; they cannot be decomposed into simpler types | Integer · floating-point · character · boolean · string |
| Composite | Combine multiple primitive values into a single structure | Arrays · lists · tuples · dictionaries · structures · objects |
| User-defined | Types created by the programmer | Structures · classes · enumerations · records |
USER-DEFINED TYPES IN THREE LANGUAGES
C++ struct Student {
string name;
int age;
};
Python class Student:
def __init__(self, name, age):
self.name = name
self.age = age
JavaScript class Student {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
| Basis | Static typing | Dynamic typing |
|---|---|---|
| When checked | During compilation | During execution |
| Languages | C++ | Python, JavaScript |
| Advantages | Early error detection · improved reliability · better performance · compiler optimization | Greater flexibility · faster development · less code |
| Disadvantages | Reduced flexibility · more verbose code | Runtime errors · reduced type safety |
C++ int x = 10;
x = "CMS710"; ← COMPILATION ERROR
Python x = 10
x = "CMS710" ← perfectly legal
| Basis | Strong typing | Weak typing |
|---|---|---|
| Rule | Prevents inappropriate type conversions | Allows implicit type conversions |
| Example | Python: age + "years" → error | JavaScript: "5" + 2 → "52", the number is converted to a string |
Definition: hiding implementation details while exposing only essential features, so programmers focus on what an object does rather than how it is implemented.
The car analogy from the notes: a driver uses the steering wheel, accelerator and brake without needing to understand the internal engine mechanisms. Similarly, programmers interact with data structures through well-defined interfaces.
Four benefits: simplicity (reduces complexity) · reusability (abstract components can be reused) · maintainability (changes to implementation do not affect users) · security (internal details remain hidden).
| Feature | Python | JavaScript | C++ |
|---|---|---|---|
| Typing style | Dynamic | Dynamic | Static |
| Type safety | Strong | Weak / moderate | Strong |
| Compilation | Interpreted | JIT / interpreted | Compiled |
| Memory control | Automatic | Automatic | Manual / automatic |
| Flexibility | Very high | High | Moderate |
| Runtime speed | Moderate | Moderate | High |
An ADT specifies the data it stores and the operations that can be performed, without specifying implementation. The Stack ADT declares Push(), Pop(), Peek() and IsEmpty() · and does not specify whether the stack is built from arrays, linked lists or dynamic memory.
Four advantages of ADTs: abstraction (reduces complexity) · reusability (can be implemented in multiple ways) · maintainability (implementation can change without affecting users) · modularity (encourages separation of concerns).
| Structure | Definition and rule | Real-life uses |
|---|---|---|
| Array | Elements in contiguous memory, accessed by index. Fixed size, indexed access, efficient retrieval, homogeneous data | Student records |
| List | An ordered collection that, unlike an array, can grow and shrink dynamically | Any changing collection |
| Stack | LIFO · the last element inserted is the first removed. Push, Pop, Peek, IsEmpty | Browser history · undo · function calls · expression evaluation |
| Queue | FIFO · the first element inserted is the first removed. Enqueue, Dequeue, Front, IsEmpty | Bank customers · print queues · OS scheduling · network packets |
Arrays: fast access and simple implementation, but fixed size and costly insertion/deletion. Lists: dynamic and flexible, but extra memory overhead and slower than arrays for some operations.
ARRAY / LIST
Python scores = [70, 80, 90, 85, 95]
JavaScript let scores = [70, 80, 90, 85, 95];
C++ int scores[5] = {70, 80, 90, 85, 95};
vector<string> students; // dynamic
STACK
Python stack = []
stack.append(10); stack.pop()
JavaScript let stack = [];
stack.push(10); stack.pop();
C++ #include <stack>
stack<int> s;
s.push(10); s.pop();
QUEUE
Python from collections import deque
queue = deque()
queue.append(10); queue.popleft()
JavaScript let queue = [];
queue.push(10); queue.shift();
C++ #include <queue>
queue<int> q;
q.push(10); q.pop();
BINARY TREE NODE
Python class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
root = Node(50)
C++ class Node {
public:
int value;
Node* left;
Node* right;
Node(int v) { value = v;
left = nullptr;
right = nullptr; }
};
Node* root = new Node(50);
A tree is a hierarchical structure of nodes connected by edges · root, parent, child, leaf. A binary tree has at most two children per node. Applications: searching, sorting, expression evaluation, database indexing.
PARSE TREE for the expression a + b * c
+
/ \
a *
/ \
b c
The parse tree shows that MULTIPLICATION
is evaluated BEFORE addition.
ABSTRACT SYNTAX TREE
Assignment
├── Variable(a)
└── Addition
├── b
└── c
A parse tree represents the grammatical structure of a program according to the language grammar and is generated during syntax analysis. An AST is a simplified parse tree that removes unnecessary grammar details while preserving meaning. ASTs are used in compilers, interpreters, static analysis tools, code optimization systems and modern AI code assistants.
| Phase | Produces |
|---|---|
| Lexical analysis | Tokens |
| Parsing (syntax analysis) | Parse trees |
| Semantic analysis | Abstract syntax trees |
| Code generation | Executable instructions, from the AST |
The conclusion the module draws: trees are central to compiler and interpreter design. If a question asks why trees matter in a programming languages course rather than a data structures one, this table is the answer.
| Feature | Python | JavaScript | C++ |
|---|---|---|---|
| Built-in list support | Excellent | Excellent | Vector library |
| Dynamic resizing | Yes | Yes | Yes |
| Memory management | Automatic | Automatic | Manual / automatic |
| Tree implementation complexity | Low | Moderate | High |
| Runtime performance | Moderate | Moderate | High |
| Ease of use | Very high | High | Moderate |
Control flow refers to the order in which statements, instructions or function calls are executed in a program. It determines:
It is commonly represented using flowcharts, control-flow graphs or execution traces. Control structures are the mechanisms that govern it, and their design significantly influences program readability, software reliability, maintainability and execution efficiency.
| Kind | What it does |
|---|---|
| Sequential | The simplest form · statements executed one after another in the order they appear. Simple, predictable, easy to understand, but cannot support decision-making or repetition |
| Selection | Choose among alternative execution paths based on conditions · this enables decision making |
| Iteration | Execute a set of instructions repeatedly until a condition is satisfied · commonly called looping |
| Recursion | A function calls itself to solve a problem |
Selection has three types: single (execute a statement if a condition is true) · double (choose between two alternatives) · multiple (choose among several · the switch).
Advantages of selection: supports decision making · improves flexibility · enhances program intelligence.
Advantages of iteration: reduces code duplication · improves efficiency · simplifies repetitive tasks.
| Basis | Sequence | Iteration |
|---|---|---|
| Definition | Statements executed once each, in written order | A block executed repeatedly until a condition is satisfied |
| Repetition | None | Yes · that is its purpose |
| Condition | No condition involved | Controlled by a condition |
| Order | Strictly top to bottom | Returns to the start of the block |
| Constructs | Ordinary statements | for · while · do-while |
| Purpose | Perform steps in order | Avoid rewriting the same code |
SEQUENCE ITERATION
x = 10 for i in range(5):
y = 20 print(i)
z = x + y
print(z) prints 0 1 2 3 4
· one statement, five executions
Executes 4 statements,
each exactly once.
| Loop | Used when |
|---|---|
for | The number of repetitions is known |
while | Repetitions depend on a condition |
do-while | Executes at least once before testing the condition |
Python for i in range(5):
print(i)
JavaScript for (let i = 0; i < 5; i++) {
console.log(i);
}
C++ for (int i = 0; i < 5; i++) {
cout << i;
}
Python count = 1
while count <= 5:
print(count)
count += 1
Recursion is a control mechanism in which a function calls itself to solve a problem. A recursive solution consists of a base case, which terminates the recursion, and a recursive case, which calls itself with a smaller problem.
Python def factorial(n):
if n == 1:
return 1
return n * factorial(n - 1)
JavaScript function factorial(n) {
if (n === 1) { return 1; }
return n * factorial(n - 1);
}
C++ int factorial(int n) {
if (n == 1) return 1;
return n * factorial(n - 1);
}
| Advantages | Disadvantages |
|---|---|
| Elegant solutions | Higher memory consumption |
| Natural representation of hierarchical structures | Risk of stack overflow |
| Useful for trees and graphs | Often slower than iteration |
Scope determines where a variable can be accessed within a program. It is fundamental because it controls variable visibility and lifetime.
| Type of scope | Accessible | Example |
|---|---|---|
| Global scope | Throughout the program | Python: x = 10 at module level |
| Local scope | Only within a function or block | Python: y = 20 inside def test(): |
| Block scope | Only inside a specific block | JavaScript: let age = 20; inside if (true) { } · reading age outside produces an error |
Importance of scope · four points: prevents naming conflicts · enhances security · improves maintainability · supports modular design.
Variable lifetime refers to the period during which a variable exists in memory. A variable's lifetime depends on scope, storage allocation method and program execution state.
| Mechanism | How it works |
|---|---|
| Pass-by-value | A copy of the argument is passed. Changes inside the function do not affect the original variable |
| Pass-by-reference | The function receives a reference to the original variable. Changes affect the original |
| Pass-by-object-reference | Python's approach · objects are passed by reference to object values, so appending to a list inside a function modifies the original list |
C++ pass-by-value C++ pass-by-reference
void increment(int x) { void increment(int &x) {
x++; x++;
} }
original unchanged original modified
Python pass-by-object-reference
def modify(lst):
lst.append(100) ← the original list IS modified
Data flow refers to how information moves through a program · between variables, functions, modules and program components. Most programs follow the Input → Processing → Output model:
number = int(input())
square = number * number
print(square)
User Input
↓
Variable
↓
Processing
↓
Output
| Basis | Imperative | Functional |
|---|---|---|
| Focus | How tasks should be performed | What should be computed |
| Example | total = 0for n in numbers: total += n | total = sum(numbers) |
| Detail | Every step is written out | Implementation details are hidden |
| Languages | C++, JavaScript, Python | Python and JavaScript support functional style |
Advantages of the functional approach: simpler code · improved abstraction · reduced side effects.
| Feature | Python | JavaScript | C++ |
|---|---|---|---|
| Readability | Very high | High | Moderate |
| Block structure | Indentation | Braces | Braces |
| Recursion support | Excellent | Excellent | Excellent |
| Functional features | Moderate | High | Moderate |
| Performance | Moderate | Moderate | High |
| Parameter passing complexity | Low | Moderate | High |
Structured programming, in this module's words, emphasizes sequence, selection and iteration while avoiding uncontrolled jumps such as excessive use of GOTO. Its benefits: improved readability (programs easier to understand) · improved reliability (errors easier to identify) · easier maintenance (modifications simpler).