codegurukool.com · Free coding tutorials & online compiler

Home › C Tutorial › C Big O (DSA)

C Big O (DSA)

How cost grows with input.

Big O describes growth: O(1) constant, O(log n) binary search, O(n) one loop, O(n log n) good sorting, O(n squared) nested loops.

Example code

#include <stdio.h>
int main() {
  int n = 5, ops = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) ops++;
  printf("n=%d ops=%d\n", n, ops);
  return 0;
}

Run this code in the online editor

← C linked lists (DSA)Live project: Student report card →