0% found this document useful (0 votes)
88 views

Time Complexity

This document summarizes common sorting algorithms and data structures, including their time and space complexities. It shows that sorting algorithms like quicksort, mergesort, and heapsort have average time complexities of O(n log n), while algorithms like bubblesort and selectionsort have worse average time complexities of O(n^2). Common data structures include arrays, linked lists, binary search trees, heaps and hash tables, with each having different complexities for operations like insertion, deletion, searching and more.

Uploaded by

Mohamaad Sihatth
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views

Time Complexity

This document summarizes common sorting algorithms and data structures, including their time and space complexities. It shows that sorting algorithms like quicksort, mergesort, and heapsort have average time complexities of O(n log n), while algorithms like bubblesort and selectionsort have worse average time complexities of O(n^2). Common data structures include arrays, linked lists, binary search trees, heaps and hash tables, with each having different complexities for operations like insertion, deletion, searching and more.

Uploaded by

Mohamaad Sihatth
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Sorting algorithms

Space
Data Time complexity: Time complexity:
Algorithm Time complexity: Best complexity:
structure Average Worst
Worst

Quick sort Array O(n log(n)) O(n log(n)) O(n2) O(n)

Merge sort Array O(n log(n)) O(n log(n)) O(n log(n)) O(n)
O(n// when all
Heap sort Array O(n log(n)) O(n log(n)) O(1)
elements are same)
Smooth
Array O(n) O(n log(n)) O(n log(n)) O(1)
sort
Bubble
Array O(n) O(n2) O(n2) O(1)
sort
Insertion
Array O(n) O(n2) O(n2) O(1)
sort
Selection
Array O(n2) O(n2) O(n2) O(1)
sort

Data structures

Get at Find Find Space


Data Structure Insert Delete Balance Search
index minimum maximum usage

O(1) O(1)
Unsorted array (see note) (see note) N/A O(1) O(n) O(n) O(n) O(n)

Sorted array O(n) O(n) N/A O(1) O(log n) O(1) O(1) O(n)
Stack
Queue
Unsorted linked list O(1) O(1)[1] N/A O(n) O(n) O(n) O(n) O(n)
Sorted linked list O(n) O(1)[1] N/A O(n) O(n) O(1) O(1) O(n)
Skip list
Self-balancing binary
O(log n) O(log n) O(log n) N/A O(log n) O(log n) O(log n) O(n)
search tree
O(1) for a min- O(1) for a max-
heap heap
Heap O(log n) O(log n) O(log n) N/A O(n) O(n)
O(n) for a max- O(n) for a min-
heap[2] heap[2]
Hash table O(1) O(1) O(n) N/A O(1) O(n) O(n) O(n)

You might also like