Programming Fundamentals Cheat Sheet
Programming Fundamentals Cheat Sheet: Core Concepts, Logic & Examples
Programming is the process of writing instructions that a computer can execute to perform tasks, solve problems, process information, and automate activities.
Whether you plan to learn Python, Java, C++, JavaScript, or another language, understanding programming fundamentals will help you learn new technologies more effectively.
This cheat sheet explains essential programming concepts with simple definitions, examples, and practical comparisons.
1. What Is Programming?
Programming involves designing instructions that tell a computer what to do and how to do it.
Examples include:
Calculating employee salaries.
Processing online payments.
Displaying website content.
Analyzing customer data.
Automating repetitive tasks.
Building mobile applications.
A program is a set of instructions written in a programming language.
Basic Programming Workflow
Understand the problem.
Identify the expected input and output.
Design a solution.
Write the code.
Run the program.
Test the results.
Debug errors.
Improve and maintain the solution.
2. Algorithms
An algorithm is a finite sequence of well-defined steps used to solve a problem or complete a task.
For example, an algorithm to calculate the total price of a purchase could be:
Read the item price.
Read the quantity.
Multiply the price by the quantity.
Display the total.
Python implementation:
price = 100
quantity = 3
total = price * quantity
print(total)Output:
300Characteristics of a Good Algorithm
Input: Accepts the information needed to solve the problem.
Output: Produces the required result.
Definiteness: Steps are clear and unambiguous.
Finiteness: Terminates after a finite number of steps.
Effectiveness: Steps can be carried out.
3. Pseudocode and Flowcharts
Before writing code, programmers often describe the solution using pseudocode or a flowchart.
Pseudocode Example
Problem: Check whether a number is even or odd.
START
INPUT number
IF number is divisible by 2
DISPLAY "Even"
ELSE
DISPLAY "Odd"
ENDPseudocode expresses logic in a readable form without requiring exact programming-language syntax.
Common Flowchart Symbols
Symbol | Meaning |
|---|---|
Oval | Start or end |
Rectangle | Process or instruction |
Diamond | Decision |
Parallelogram | Input or output |
Arrow | Direction of control flow |
Flowcharts help visualize how a program moves between steps and decisions.
4. Variables and Constants
A variable is a named reference used to access a value.
age = 25
name = "Alex"
salary = 50000A constant represents a value intended not to change during program execution.
Python does not enforce ordinary constant declarations, but uppercase names communicate the convention:
TAX_RATE = 0.18Variable vs. Constant
Variable | Constant |
|---|---|
Intended to hold a value that may change | Intended to represent a fixed value |
Often written in lowercase with underscores in Python | Often written in uppercase with underscores in Python |
Example: | Example: |
Naming conventions and enforcement depend on the programming language.
5. Data Types
A data type describes the kind of value a variable or expression represents.
Type | Purpose | Example |
|---|---|---|
Integer | Whole numbers |
|
Float | Decimal numbers |
|
String | Text |
|
Boolean | True or false |
|
Character | A single character in languages that define this type |
|
Array | Indexed collection of elements |
|
Object or record | Groups related information | A customer record |
Null-like value | Represents absence of a value |
|
Exact type names and behavior differ between languages. For example, Python has strings rather than a separate built-in character type.
Why Data Types Matter
Data types affect:
Which operations are allowed.
How values are stored and represented.
How comparisons behave.
How data is converted.
How memory and performance are managed.
Example:
age = 25
name = "Alex"
print(age + 5)
print(name + " Kumar")6. Operators
Operators perform operations on values.
Arithmetic Operators
Operator | Operation | Example |
|---|---|---|
| Addition |
|
| Subtraction |
|
| Multiplication |
|
| Division |
|
| Remainder in common languages |
|
| Exponentiation in Python |
|
Operator syntax and integer-division behavior vary across languages.
Comparison Operators
x = 10
y = 5
print(x == y)
print(x != y)
print(x > y)
print(x < y)
print(x >= y)
print(x <= y)These comparisons return Boolean results in Python.
Logical Operators
AND: True when both conditions are true.OR: True when at least one condition is true.NOT: Reverses a Boolean condition.
Python uses and, or, and not. Other languages may use symbols such as &&, ||, and !.
7. Conditional Statements
Conditional statements allow programs to make decisions based on conditions.
If Statement
age = 20
if age >= 18:
print("Eligible")If-Else Statement
number = 7
if number % 2 == 0:
print("Even")
else:
print("Odd")Multiple Conditions
marks = 82
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
else:
print("Grade C")Conditional logic is used in authentication, eligibility checks, pricing rules, validation, and business workflows.
8. Loops
Loops repeat instructions.
For Loop
for number in range(1, 6):
print(number)This prints numbers from 1 to 5.
While Loop
count = 1
while count <= 5:
print(count)
count += 1Loop Control
break: Exits a loop.continue: Skips the rest of the current iteration.return: Exits a function and may return a value.
Loop syntax differs between languages, but the underlying concept of repetition is widely shared.
Common Loop Mistake
An incorrect termination condition can create an infinite loop.
Always check that a loop has a valid stopping condition or another reliable exit mechanism.
9. Functions
A function is a reusable block of code designed to perform a particular task.
def calculate_total(price, quantity):
return price * quantity
total = calculate_total(100, 3)
print(total)Output:
300Key Function Concepts
Function name: Identifies the function.
Parameter: A named input in the function definition.
Argument: A value supplied when calling the function.
Return value: The result sent back to the caller.
Scope: Determines where a name can be accessed.
Benefits of Functions
Reduce duplicated code.
Improve readability.
Simplify testing.
Support modular design.
Make maintenance easier.
Functions should generally have clear responsibilities and meaningful names.
10. Data Structures
Data structures organize information so programs can access and manipulate it efficiently.
Data structure | Description | Common use |
|---|---|---|
Array or list | Ordered collection | Storing multiple values |
Linked list | Elements connected through references | Certain insertion and deletion patterns |
Stack | Last in, first out (LIFO) | Undo operations |
Queue | First in, first out (FIFO) | Task processing |
Hash table or map | Key-value lookup | Finding information by key |
Set | Collection of unique values | Removing duplicates |
Tree | Hierarchical structure | File systems and search structures |
Graph | Nodes connected by edges | Maps and social networks |
Stack Example
A stack follows LIFO: the last item added is the first item removed.
Think of a stack of plates. The top plate is removed first.
Common operations:
push: Add an item.pop: Remove the top item.peekortop: Inspect the top item.
Queue Example
A queue follows FIFO: the first item added is the first item removed.
Think of a line at a service counter.
Common operations:
enqueue: Add an item.dequeue: Remove the next item.front: Inspect the next item.
11. Strings and Collections
Programs frequently work with text and groups of values.
String Example
message = "Hello Programming"
print(message.upper())
print(len(message))List Example
numbers = [10, 20, 30]
numbers.append(40)
print(numbers)Dictionary Example
employee = {
"name": "Alex",
"department": "Marketing"
}
print(employee["name"])Choose a data structure based on the operations you need to perform, such as searching, inserting, deleting, or maintaining order.
12. Recursion
Recursion occurs when a function calls itself to solve a smaller version of a problem.
Example: calculating a factorial.
def factorial(n):
if n < 0:
raise ValueError("n must be non-negative")
if n <= 1:
return 1
return n * factorial(n - 1)
print(factorial(5))Output:
120The function has two important parts:
Base case: Stops the recursion.
Recursive case: Calls the function with a smaller problem.
Without an appropriate base case, recursion can continue until the program fails or reaches a recursion limit.
An iterative solution may be simpler or more memory-efficient for some problems.
13. Object-Oriented Programming
Object-oriented programming (OOP) organizes code around objects that combine data and behavior.
Class and Object Example
class Employee:
def __init__(self, name, salary):
self.name = name
self.salary = salary
def display_details(self):
print(self.name, self.salary)
employee = Employee("Alex", 50000)
employee.display_details()Four Common OOP Concepts
1. Encapsulation
Organizes data and related methods together and controls how internal state is accessed.
2. Abstraction
Exposes the essential operations while hiding unnecessary implementation details.
3. Inheritance
Allows one class to reuse or extend behavior from another class.
4. Polymorphism
Allows different objects to respond to the same operation in different ways.
OOP is useful for many applications, but not every problem requires an object-oriented design.
14. Error Types and Debugging
Errors can occur when writing or running a program.
Error type | Meaning | Example |
|---|---|---|
Syntax error | Code violates language syntax | Missing closing bracket |
Runtime error | Failure during execution | Division by zero |
Logical error | Program runs but produces the wrong result | Incorrect calculation formula |
Type error | An operation receives an incompatible type | Adding a number to an unsupported value |
Debugging Process
Reproduce the problem.
Read the error message.
Identify the relevant code.
Inspect variables and inputs.
Trace the program's execution.
Make a focused correction.
Run the test again.
Example of a Logical Error
price = 100
quantity = 3
total = price + quantityThe program runs, but the result is incorrect because it adds instead of multiplying.
Correct version:
total = price * quantityDebugging requires checking the intended behavior, not merely removing error messages.
15. Time and Space Complexity
Algorithm complexity describes how resource requirements grow as input size increases.
Big O Notation
Big O is commonly used to express an upper-bound growth rate.
Complexity | Name | Example |
|---|---|---|
| Constant | Accessing an array element by index |
| Logarithmic | Binary search on sorted data |
| Linear | Scanning a list |
| Linearithmic | Typical efficient comparison sorting |
| Quadratic | Comparing every pair in a simple nested loop |
| Exponential | Some brute-force recursive algorithms |
Actual performance depends on the algorithm, implementation, input, and environment.
Time Complexity
Describes how the number of operations tends to grow as input size increases.
Space Complexity
Describes how memory requirements grow with input size.
Example: Searching an unsorted list may require examining every element, resulting in (O(n)) time in the worst case.
Understanding complexity helps developers choose algorithms that scale appropriately.
16. Programming Paradigms
A programming paradigm is an approach to structuring programs.
Paradigm | Main idea | Examples |
|---|---|---|
Procedural | Organizes code into procedures or functions | C |
Object-oriented | Organizes code around objects | Java, C++ |
Functional | Emphasizes functions and transformations | Haskell; functional features in Python and JavaScript |
Declarative | Describes the desired result | SQL |
Event-driven | Responds to events | Browser-based JavaScript applications |
These paradigms are not mutually exclusive. Many modern languages support multiple approaches.
17. Compiled vs. Interpreted Languages
Programs need to be translated or executed by software that the computer can run.
Compiled approach: A compiler translates source code into another form, often machine code or bytecode, before execution.
Interpreted approach: An interpreter executes or processes program instructions at runtime.
In practice, many languages use a combination of compilation and interpretation.
For example, Python implementations commonly compile source code into bytecode that a virtual machine executes. Therefore, describing Python simply as “interpreted” is a useful beginner simplification rather than the full technical picture.
18. Essential Programming Vocabulary
Term | Meaning |
|---|---|
Source code | Human-readable program instructions |
Syntax | Rules governing valid code |
Variable | A named reference to a value |
Data type | Classification of a value |
Expression | Code that produces a value |
Statement | An instruction executed by a program |
Function | Reusable block of code |
Parameter | Named input in a function definition |
Argument | Value supplied to a function |
Loop | Structure that repeats instructions |
Condition | Expression used to make a decision |
Algorithm | Steps for solving a problem |
API | Interface through which software components communicate |
Library | Reusable code available to a program |
Framework | Structure that provides conventions and reusable components |
Debugging | Finding and fixing problems |
Testing | Checking whether software behaves as expected |
Version control | Tracking changes to files and code |
Repository | A location containing project files and version history |
Runtime | Environment in which a program executes |
Exception | An event that interrupts normal program flow |
19. Essential Problem-Solving Techniques
Break Problems Into Smaller Steps
Instead of solving an entire application at once, divide it into manageable tasks.
For example, an expense tracker could contain separate functions for:
Accepting an expense.
Validating the amount.
Saving the record.
Calculating totals.
Displaying a report.
Identify Inputs and Outputs
Before coding, write down what information enters the program and what result it must produce.
Test Edge Cases
Consider:
Empty input.
Zero values.
Negative values.
Very large inputs.
Duplicate records.
Missing data.
Invalid formats.
Avoid Premature Complexity
Start with the simplest correct solution. Improve performance and structure when there is a clear reason to do so.
20. Programming Fundamentals Practice Checklist
Core concepts
Explain what an algorithm is.
Understand variables, constants, and data types.
Use arithmetic and comparison operators.
Write conditional statements.
Create loops and control their execution.
Reusable code
Define and call functions.
Understand parameters and return values.
Work with lists, maps, sets, stacks, and queues.
Explain classes and objects.
Understand recursion.
Quality and performance
Identify syntax, runtime, and logical errors.
Debug a small program.
Explain time and space complexity.
Test normal and edge-case inputs.
Use clear names and modular code.
Conclusion
Programming fundamentals form the foundation for learning any programming language. Variables, data types, operators, control flow, functions, data structures, algorithms, debugging, and complexity analysis are useful across many technical disciplines.
Learn these concepts by writing small programs and gradually increasing their complexity. Once you understand the underlying logic, moving between languages such as Python, Java, C++, and JavaScript becomes easier.



