Skip to content
Home ยป Probabilistic Analysis

Probabilistic Analysis


๐Ÿ“˜ Probabilistic Analysis (Introduction)

Probabilistic Analysis is a method of analyzing algorithms in which the input is assumed to be random, and the performance of the algorithm is calculated as the expected value.

๐Ÿ‘‰ It gives Expected Time Complexity instead of Worst-Case Complexity.


๐Ÿ“Œ Why Probabilistic Analysis?

Many algorithms:

  • Perform poorly only for rare or specific inputs
  • But perform well for most inputs

Worst-case time complexity may not represent typical behavior.

Examples:

  • Quick Sort worst-case โ†’ O(nยฒ)
  • But average case (expected) โ†’ O(n log n)
    Because probabilistic analysis assumes inputs are random.

๐Ÿ“˜ Deterministic vs Probabilistic Analysis

Deterministic AnalysisProbabilistic Analysis
Assumes worst or best case inputAssumes input follows a probability distribution
Gives worst-case or best-caseGives expected (average) running time
Used for guaranteed performanceUsed for realistic performance
Example: Worst-case of Quick SortExpected case of Quick Sort

๐Ÿ“˜ Where is Probabilistic Analysis Used?

  1. Average-case analysis of algorithms
  2. Hashing / Hash Tables
  3. Randomized algorithms
  4. Quick Sort & Quick Select
  5. Skip Lists
  6. Probabilistic Counting Algorithms
  7. Load Balancing Algorithms
  8. Random Input Models

๐Ÿ“˜ Example: Quick Sort (Classic Example)

For Quick Sort:

Worst Case: O(nยฒ)
Expected / Probabilistic Case: O(n log n)

Why?

Because:

  • Probability of selecting a bad pivot = very low
  • Probability of partition creating balanced subproblems = high

Thus, using probability theory:

  • Expected height of recursion tree = log n
  • Expected work per level = n

๐Ÿ‘‰ Expected Time = n ร— log n


๐Ÿ“˜ Example: Hashing

In a hash table:

  • Worst-case search time = O(n)
  • Expected search time = O(1) if each key has equal probability of being hashed to any slot.

Probability theory tells us:

  • Expected number of collisions is small
  • Expected chain length = load factor ฮฑ = n/m

Thus operations (search, insert, delete) are expected O(1).


๐Ÿ“˜ Example: Randomized Algorithm Analysis

Some algorithms use randomness inside them.

Examples:

  • Randomized Quick Sort
  • Randomized Binary Search
  • Randomized Selection Algorithms
  • Monte Carlo and Las Vegas algorithms

We compute expected running time using probability of each random event.


๐Ÿ“˜ Formal Definition of Probabilistic Analysis

In probabilistic analysis:

  • Define the probability distribution of all possible inputs
  • Compute expected running time:

[
E[T(n)] = \sum_{i=1}^{k} P(input=i) \times Time(input=i)
]

Where:

  • ( P(input=i) ) is the probability of the i-th input
  • ( Time(input=i) ) is time taken for that input

๐Ÿ“˜ Types of Probabilistic Analysis

There are two types:


1. Distribution-based Probabilistic Analysis

Assumes inputs follow a known probability distribution.

Example:

  • Every permutation of n elements is equally likely

Used in:

  • Quick Sort
  • Randomized Select

2. Randomized Algorithm Analysis

Algorithm itself makes random choices.

Example:

  • Randomized pivot selection in Quick Sort
  • Randomized skip lists
  • Randomized hashing

๐Ÿ“˜ Example: Average Case of Linear Search

Problem:

Element is equally likely to be at any position in an array of size n.

Probability = 1/n for each index.

Expected time:

[
E[T] = \frac{1}{n}(1 + 2 + 3 + \dots + n)
= \frac{(n+1)}{2}
]

๐Ÿ‘‰ Linear search average time = O(n)


๐Ÿ“˜ Key Points (For Exams)

  • Probabilistic Analysis studies the expected behavior of algorithms.
  • It uses probability theory to analyze average-case performance.
  • Helps evaluate algorithms realistically for random inputs.
  • Important in hashing, quicksort, randomized algorithms, load balancing, etc.
  • Expected time often gives more practical understanding than worst-case.

๐ŸŽฏ Summary (Short Notes)

  • Probabilistic Analysis = Expected running time analysis
  • Uses probability of inputs or random choices
  • Realistic: most important for algorithms like Quick Sort & Hashing
  • Expected time often better than worst-case