0% found this document useful (0 votes)
33 views5 pages

DS Complexities

The document summarizes the time and space complexities of various sorting algorithms, data structures, graph algorithms, search algorithms, tree traversals, and strongly connected components algorithms. It provides the best, average, and worst case time complexities as well as the space complexity for each algorithm and data structure.
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
33 views5 pages

DS Complexities

The document summarizes the time and space complexities of various sorting algorithms, data structures, graph algorithms, search algorithms, tree traversals, and strongly connected components algorithms. It provides the best, average, and worst case time complexities as well as the space complexity for each algorithm and data structure.
Copyright
© © All Rights Reserved
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
You are on page 1/ 5

Sorting Algorithms:

1. Bubble Sort:

 Time Complexity: Best - O(n), Average - O(n^2), Worst - O(n^2)

 Space Complexity: O(1)

2. Selection Sort:

 Time Complexity: Best - O(n^2), Average - O(n^2), Worst - O(n^2)

 Space Complexity: O(1)

3. Insertion Sort:

 Time Complexity: Best - O(n), Average - O(n^2), Worst - O(n^2)

 Space Complexity: O(1)

4. Comb Sort:

 Time Complexity: Best - O(n log n), Average - O(n^2), Worst - O(n^2)

 Space Complexity: O(1)

5. Quick Sort:

 Time Complexity: Best - O(n log n), Average - O(n log n), Worst - O(n^2)

 Space Complexity: Best - O(log n), Worst - O(n)

6. Merge Sort:

 Time Complexity: Best - O(n log n), Average - O(n log n), Worst - O(n log n)

 Space Complexity: O(n)

7. Radix Sort:

 Time Complexity: Best - O(nk), Average - O(nk), Worst - O(nk)

 Space Complexity: O(n + k)

8. Heap Sort:

 Time Complexity: Best - O(n log n), Average - O(n log n), Worst - O(n log n)

 Space Complexity: O(1)

9. Radix Sort:

 Time Complexity: Best - O(nk), Average - O(nk), Worst - O(nk)

 Space Complexity: O(n + k)


10. Comb Sort:

 Time Complexity: Best - O(n log n), Average - O(n^2), Worst - O(n^2)

 Space Complexity: O(1)

Data Structures:
1. Hash Table:

 Time Complexity (average): O(1)

 Space Complexity: O(n)

2. Heaps:

 Time Complexity (heapify): O(n)

 Space Complexity: O(n)

3. Hashing:

 Time Complexity (average): O(1)

 Space Complexity: O(n)

4. Hashmaps:

 Time Complexity (average): O(1)

 Space Complexity: O(n)

5. Binary Search Tree (BST):

 Time Complexity (average): Best - O(log n), Average - O(log n), Worst - O(n)

 Space Complexity: O(n)

6. AVL Tree:

 Time Complexity (search, insert, delete): Best - O(log n), Average - O(log n), Worst -
O(log n)

 Space Complexity: O(n)

7. Linked List:

 Time Complexity (search): Best - O(1), Average - O(n), Worst - O(n)

 Space Complexity: O(n)

8. Doubly Linked List:

 Time Complexity (search): Best - O(1), Average - O(n), Worst - O(n)

 Space Complexity: O(n)


9. Circular Linked List:

 Time Complexity (search): Best - O(1), Average - O(n), Worst - O(n)

 Space Complexity: O(n)

10. Stacks:

 Time Complexity (push, pop): Best - O(1), Average - O(1), Worst - O(1)

 Space Complexity: O(n)

11. Queue:

 Time Complexity (enqueue, dequeue): Best - O(1), Average - O(1), Worst - O(1)

 Space Complexity: O(n)

12. Priority Queue:

 Time Complexity (enqueue, dequeue): Best - O(1), Average - O(log n), Worst - O(log n)

 Space Complexity: O(n)

Graph Algorithms:
1. Prim's Algorithm:

 Time Complexity: Best - O(E + V log V), Average - O(E + V log V), Worst - O(E + V log V)

 Space Complexity: O(V)

2. Kruskal's Algorithm:

 Time Complexity: Best - O(E log V), Average - O(E log V), Worst - O(E log V)

 Space Complexity: O(V + E)

3. Dijkstra's Algorithm:

 Time Complexity: Best - O((V + E) log V), Average - O((V + E) log V), Worst - O((V + E) log
V)

 Space Complexity: O(V + E)

4. Breadth-First Search (BFS):

 Time Complexity: Best - O(|V| + |E|), Average - O(|V| + |E|), Worst - O(|V| + |E|)

 Space Complexity: O(|V|) for the queue

5. Depth-First Search (DFS):

 Time Complexity: Best - O(|V| + |E|), Average - O(|V| + |E|), Worst - O(|V| + |E|)

 Space Complexity: O(|V|) for the recursive call stack


6. Bellman-Ford Algorithm:

 Time Complexity: Best - O(|V| * |E|), Average - O(|V| * |E|), Worst - O(|V| * |E|)

 Space Complexity: O(|V|)

7. Topological Sort:

 Time Complexity: Best - O(|V| + |E|), Average - O(|V| + |E|), Worst - O(|V| + |E|)

 Space Complexity: O(|V| + |E|)

Search Algorithms:
1. Binary Search:

 Time Complexity: Best - O(1), Average - O(log n), Worst - O(log n)

 Space Complexity: O(1)

2. Linear Search:

 Time Complexity: Best - O(1), Average - O(n), Worst - O(n)

 Space Complexity: O(1)

3. Interpolation Search:

 Time Complexity: Best - O(1), Average - O(log log n), Worst - O(n)

 Space Complexity: O(1)

4. Rabin-Karp Algorithm:

 Time Complexity: Best - O(n + m), Average - O(n + m), Worst - O(nm)

 Space Complexity: O(1)


Tree Traversals:
1. Inorder Traversal:

 Time Complexity: Best - O(1), Average - O(n), Worst - O(n)

 Space Complexity: O(h), where h is the height of the tree (recursive call stack space)

2. Preorder Traversal:

 Time Complexity: Best - O(1), Average - O(n), Worst - O(n)

 Space Complexity: O(h), where h is the height of the tree (recursive call stack space)

3. Postorder Traversal:

 Time Complexity: Best - O(1), Average - O(n), Worst - O(n)

 Space Complexity: O(h), where h is the height of the tree (recursive call stack space)

Strongly Connected Components Algorithms:


1. Kosaraju's Algorithm:

 Time Complexity: Best - O(V + E), Average - O(V + E), Worst - O(V + E)

 Space Complexity: O(V)

2. Tarjan's Algorithm:

 Time Complexity: Best - O(V + E), Average - O(V + E), Worst - O(V + E)

 Space Complexity: O(V)

You might also like