Skip to content
IRC-Coding IRC-Coding
Algorithms Structograms Flowcharts Programming Fundamentals

Algorithms Fundamentals: Properties and Structograms

Introduction to algorithms: fundamental properties, structograms (flowcharts), and basic algorithmic concepts for beginners.

S

schutzgeist

1 min read

Algorithms Fundamentals: Properties and Structograms

This article is a concept explanation about algorithms and their fundamental properties.

In a Nutshell

An algorithm is a finite sequence of well-defined instructions to solve a specific problem or perform a computation.

Algorithm Properties

Essential Characteristics

  1. Finiteness: Algorithm must terminate after a finite number of steps
  2. Definiteness: Each step must be precisely defined and unambiguous
  3. Input: Algorithm has zero or more well-defined inputs
  4. Output: Algorithm produces one or more well-defined outputs
  5. Effectiveness: Each step must be basic enough to be carried out

Algorithm Quality Criteria

  • Correctness: Produces correct output for all valid inputs
  • Efficiency: Uses minimal time and memory resources
  • Readability: Easy to understand and maintain
  • Robustness: Handles invalid inputs gracefully
  • Scalability: Performs well with increasing input size

Structograms (Flowcharts)

Structograms are graphical representations of algorithms using standardized symbols.

Basic Flowchart Symbols

┌─────────────┐  Start/End
│   OVAL      │
└─────────────┘

┌─────────────┐  Process/Operation
│ RECTANGLE   │
└─────────────┘

┌─────────────┐  Decision/Condition
│   DIAMOND   │
└─────────────┘

┌─────────────┐  Input/Output
│ PARALLELOGRAM│
└─────────────┘

┌─────────────┐  Connector
│    CIRCLE    │
└─────────────┘

Example: Finding Maximum Number

        ┌─────────┐
        │  START  │
        └─────────┘


        ┌─────────────┐
        │  Input n[]  │
        │  Set max=n[0]│
        └─────────────┘


        ┌─────────────┐
        │  i = 1      │
        └─────────────┘


        ┌─────────────┐
        │ i < n.length │
        └─────────────┘
         YES │   NO
              ▼   ▼
        ┌─────────────┐
        │ max > n[i]? │
        └─────────────┘
         YES │   NO
              ▼   ▼
        ┌─────────────┐
        │ max = n[i]  │
        └─────────────┘


        ┌─────────────┐
        │   i = i + 1 │
        └─────────────┘


        ┌─────────────┐
        │ Output max  │
        └─────────────┘


        ┌─────────┐
        │  END    │
        └─────────┘

Algorithm Examples

def linear_search(arr, target):
    for i in range(len(arr)):
        if arr[i] == target:
            return i  # Found at index i
    return -1  # Not found
def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    
    while left <= right:
        mid = (left + right) // 2
        
        if arr[mid] == target:
            return mid  # Found at index mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    
    return -1  # Not found

Bubble Sort

def bubble_sort(arr):
    n = len(arr)
    
    for i in range(n):
        swapped = False
        
        for j in range(0, n - i - 1):
            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
                swapped = True
        
        if not swapped:
            break  # Array is sorted
    
    return arr

Algorithm Analysis

Time Complexity

Time complexity measures how runtime grows with input size.

ComplexityDescriptionExample
O(1)Constant timeArray access
O(log n)LogarithmicBinary search
O(n)LinearLinear search
O(n log n)LinearithmicMerge sort
O(n²)QuadraticBubble sort
O(2ⁿ)ExponentialBrute force

Space Complexity

Space complexity measures memory usage relative to input size.

  • O(1): Constant space - uses fixed amount of memory
  • O(n): Linear space - memory grows proportionally to input
  • O(n²): Quadratic space - memory grows quadratically

Algorithm Design Techniques

1. Divide and Conquer

  • Break problem into smaller subproblems
  • Solve subproblems recursively
  • Combine solutions

Example: Merge Sort, Quick Sort

2. Greedy Algorithms

  • Make locally optimal choice at each step
  • Hope to find global optimum

Example: Dijkstra’s Algorithm, Huffman Coding

3. Dynamic Programming

  • Break problem into overlapping subproblems
  • Store results of subproblems

Example: Fibonacci Sequence, Knapsack Problem

4. Backtracking

  • Try all possible solutions
  • Abandon partial solutions that don’t work

Example: N-Queens Problem, Sudoku Solver

Best Practices

  1. Clear problem definition: Understand requirements completely
  2. Choose appropriate data structures: Select structures that optimize your algorithm
  3. Handle edge cases: Consider empty inputs, single elements, etc.
  4. Test thoroughly: Verify with various input scenarios
  5. Document your algorithm: Explain logic and complexity

Common Mistakes to Avoid

  1. Off-by-one errors: Incorrect loop boundaries
  2. Infinite loops: Missing termination conditions
  3. Memory leaks: Not releasing allocated memory
  4. Incorrect assumptions: Assuming sorted input when not guaranteed
  5. Poor variable naming: Using unclear variable names

Learning Resources

  • Books: Introduction to Algorithms by Cormen et al.
  • Online: Khan Academy, Coursera algorithms courses
  • Practice: LeetCode, HackerRank, Codeforces
  • Visualization: Algorithm visualizers online

Next Steps

After mastering fundamentals:

  1. Study advanced algorithms
  2. Learn data structures in depth
  3. Practice competitive programming
  4. Implement algorithms from scratch
  5. Analyze real-world algorithm applications
Back to Blog
Share:

Related Posts