This document provides a summary of time and space complexities for various algorithms and data structures. It includes tables summarizing the complexities of operations like searching, sorting, adding/removing nodes/edges for different algorithms and data structures like heaps, graphs, trees and lists. For example, it notes that binary search has a time complexity of O(log(n)) for average and worst cases.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
1K views
Algorithms CheatSheet
This document provides a summary of time and space complexities for various algorithms and data structures. It includes tables summarizing the complexities of operations like searching, sorting, adding/removing nodes/edges for different algorithms and data structures like heaps, graphs, trees and lists. For example, it notes that binary search has a time complexity of O(log(n)) for average and worst cases.
Searching Algorithm Data Structure Time Complexity Space Complexity
Average Worst Worst
Depth First Search (DFS) Graph of |V| vertices and |E| edges - O(|E| + |V|) O(|V|)
Breadth First Search (BFS) Graph of |V| vertices and |E| edges - O(|E| + |V|) O(|V|)
Binary search Sorted array of n elements O(log(n)) O(log(n)) O(1)
Linear (Brute Force) Array O(n) O(n) O(1)
Shortest path by Dijkstra, using a Min-heap as priority queue Graph with |V| vertices and |E| edges O((|V| + |E|) log |V|) O((|V| + |E|) log |V|) O(|V|)
Shortest path by Dijkstra, using an unsorted array as priority queue Graph with |V| vertices and |E| edges O(|V|^2) O(|V|^2) O(|V|)
Shortest path by Bellman-Ford Graph with |V| vertices and |E| edges O(|V||E|) O(|V||E|) O(|V|)
Compiled By : JITENDRA KUMAR PATEL. Ref : http://bigocheatsheet.com/