Latest

6/recent/ticker-posts

TIME COMPLEXITY OF DIFFERENT ALGORITHMS

 1. Linear search: O(n)

2. Binary search: O(log n)

3. Bubble sort : Worst and average time complexity:  O(n^2)

                           Best time complexity: O(n)

4. Insertion sort:  Worst and average case time complexity: O(n^2)

                            Best case time complexity: O(n)

5. Selection sort: O(n^2) [all cases]

6. Heap sort : O(nlogn) [all cases]

7. Merge sort: O(n log n) [Best case]

                        O(n^2)  [worst case]

8. Quick sort : O(nlogn) [All cases]

    In worst case O(n^2)

9. Inserting an element in heap : O(log n) [ Worst case] 

                       O(1) : best case

10. Deleting an element from heap: O(log n)


11. Creating a heap : O(n log n)

12. Heapify : O( n )

13. Heap sort : O(n log n)

14. 

     



ARRAY

LINKED LIST

Accessing from beginning

O(1)

O(n)

Insert from beginning/end

O(n)

O(1)

Insert/remove from end

O(1)

O(n)

Insert/remove from middle

O(n)

O(n)


Post a Comment

0 Comments