0% found this document useful (0 votes)
6 views2 pages

COMPLEXITIES

This document presents a detailed overview of the time and space complexities associated with various data structures and their operations, including arrays, linked lists, stacks, queues, binary search trees, heaps, and graphs. It also outlines the complexities of several sorting algorithms such as bubble sort, insertion sort, and merge sort. The information is organized in a comprehensive table format for easy reference.
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)
6 views2 pages

COMPLEXITIES

This document presents a detailed overview of the time and space complexities associated with various data structures and their operations, including arrays, linked lists, stacks, queues, binary search trees, heaps, and graphs. It also outlines the complexities of several sorting algorithms such as bubble sort, insertion sort, and merge sort. The information is organized in a comprehensive table format for easy reference.
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/ 2

Time and Space Complexities of Data Structures and Their

Operations

1 Introduction
This document provides a comprehensive table that includes the time complexities and space complexities
of common data structures and their operations.

2 Complexities of Data Structures


2.1 Arrays

Operation Best Case Worst Case Space Complexity


Access O(1) O(1) O(n)
Search (Linear) O(1) O(n) O(n)
Search (Binary) O(1) O(log n) O(n)
Insertion (end) O(1) O(1) O(n)
Insertion (middle) O(1) O(n) O(n)
Deletion (end) O(1) O(1) O(n)
Deletion (middle) O(1) O(n) O(n)

2.2 Linked Lists

Operation Best Case Worst Case Space Complexity


Access O(1) O(n) O(n)
Search O(1) O(n) O(n)
Insertion (head) O(1) O(1) O(n)
Insertion (tail) O(1) O(n) O(n)
Deletion (head) O(1) O(1) O(n)
Deletion (tail) O(1) O(n) O(n)

2.3 Stack

Operation Best Case Worst Case Space Complexity


Push O(1) O(1) O(n)
Pop O(1) O(1) O(n)
Peek O(1) O(1) O(n)

1
2.4 Queue

Operation Best Case Worst Case Space Complexity


Enqueue O(1) O(1) O(n)
Dequeue O(1) O(1) O(n)
Access (Front/Rear) O(1) O(1) O(n)

2.5 Binary Search Tree (BST)

Operation Best Case Worst Case Space Complexity


Search O(log n) O(n) O(n)
Insertion O(log n) O(n) O(n)
Deletion O(log n) O(n) O(n)

2.6 Heap

Operation Best Case Worst Case Space Complexity


Insert O(1) O(log n) O(n)
Delete O(1) O(log n) O(n)
Heapify O(1) O(log n) O(n)
Build Heap O(n) O(n) O(n)

2.7 Graph

Operation Adjacency List Adjacency Matrix


Add Vertex O(1) O(n2 )
Add Edge O(1) O(1)
Remove Edge O(1) O(1)
Remove Vertex O(V + E) O(V 2 )
Search Edge O(V ) O(1)

3 Sorting Algorithm Complexities

Algorithm Best Case Worst Case Space Complexity


2
Bubble Sort O(n) O(n ) O(1)
Insertion Sort O(n) O(n2 ) O(1)
Selection Sort O(n2 ) O(n2 ) O(1)
Merge Sort O(n log n) O(n log n) O(n)
Quick Sort O(n log n) O(n2 ) O(log n)
Heap Sort O(n log n) O(n log n) O(1)

You might also like