Skip to main content

Data Structure Big(o) basics

 Performance graph Big(o) notation 



Best is O(1)- constant & worst is O(n square)

Link to check Big(o) for different data structures - https://www.bigocheatsheet.com/

Big ONameDescription
1Constantstatement, one line of code
log(n)LogarithmicDivide and conquer (binary search)
nLinearLoop
n*log(n)LinearithmicEffective sorting algorithms
n^2QuadraticDouble loop
n^3CubicTriple loop
2^nExponentialComplex full search


Worst Case→AccessSearchInsertionDeletionSpace Complexity
ArrayO(1)O(n)O(n)O(n)O(n)
StackO(n)O(n)O(1)O(1)O(n)
QueueO(n)O(n)O(1)O(1)O(n)
Singly-Linked ListO(n)O(n)O(1)O(1)O(n)
Doubly-Linked ListO(n)O(n)O(1)O(1)O(n)
Hash TableN/AO(n)O(n)O(n)O(n)


HashTable- implementation in C#/Python - [Dictionary<TKey, TValue>I), Java through HashMap

Hash functions converts Key to index/HashCode
Hash Collision: when Hash Function generates same function for to different Keys.

Queue -
  • Enqueue - insert
  • Dequeue - remove 
  • peek - shows the item
Stack -
  • push - insert item on top of stack
  • Pop - removes top item in the stack
  • Peek - just shows top item in stack , does not remove it

















Sorting AlgorithmsSpace complexityTime complexityTime complexity
Worst caseBest caseWorst case
Insertion SortO(1)O(n)O(n^2)
Selection SortO(1)O(n^2)O(n^2)
Bubble SortO(1)O(n)O(n^2)
MergesortO(n)O(n log n)O(n log n)
QuicksortO(log n)O(n log n)O(n^2)
HeapsortO(1)O(n log n)O(n log n)

Comments

Popular posts from this blog

API Basics

 

Algorithm solving Common Patterns & Techniques

  These are targeted data manipulation strategies used to handle arrays, strings, and linked lists efficiently. Two Pointers : Uses two reference pointers to iterate through a data structure simultaneously, typically from opposite ends or at different speeds (Fast & Slow pointers). Sliding Window : Maintains a subset of data (a "window") over a sequential structure to track running statistics without recalculating the whole set. Prefix Sum : Pre-computes and stores cumulative sums of an array to allow for \(O(1)\) constant-time range sum queries. Dynamic Programming (DP ): Dynamic programming is an optimization technique used to solve problems by breaking them down into simpler subproblems and storing the results of these subproblems to avoid redundant computations. It is particularly effective for problems exhibiting overlapping subproblems and optimal substructure. Greedy Algorithm Breadth-First Search (BFS) / Depth-First Search (DFS) : Systematic graph and tree travers...