0% found this document useful (0 votes)
23 views3 pages

Java Data Structures Complexities and APIs

The document outlines various Java data structures, detailing their time and space complexities along with common API methods. It covers structures such as Array, ArrayList, LinkedList, Stack, Queue, HashSet, TreeSet, HashMap, TreeMap, PriorityQueue, and Graph (Adjacency List). Each structure is summarized with its access, search, insert/delete complexities, and key methods for usage.

Uploaded by

Apeksha Jadeja
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)
23 views3 pages

Java Data Structures Complexities and APIs

The document outlines various Java data structures, detailing their time and space complexities along with common API methods. It covers structures such as Array, ArrayList, LinkedList, Stack, Queue, HashSet, TreeSet, HashMap, TreeMap, PriorityQueue, and Graph (Adjacency List). Each structure is summarized with its access, search, insert/delete complexities, and key methods for usage.

Uploaded by

Apeksha Jadeja
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

Java Data Structures – Time & Space Complexity +

API Methods

Array
Time & Space Complexity:
1 Access: O(1)
2 Search: O(n)
3 Insert/Delete: O(n)
4 Space: O(n)
Common Methods:
length

ArrayList
Time & Space Complexity:
1 Access: O(1)
2 Search: O(n)
3 Insert/Delete (end): O(1) amortized
4 Insert/Delete (middle): O(n)
5 Space: O(n)
Common Methods:
add(), add(index, e), get(), set(), remove(), size(), contains(), clear()

LinkedList
Time & Space Complexity:
1 Access: O(n)
2 Insert/Delete: O(1)
3 Search: O(n)
4 Space: O(n)
Common Methods:
add(), addFirst(), addLast(), remove(), get(), getFirst(), getLast()

Stack
Time & Space Complexity:
1 Push: O(1)
2 Pop: O(1)
3 Peek: O(1)
4 Space: O(n)
Common Methods:
push(), pop(), peek(), isEmpty()

Queue / Deque
Time & Space Complexity:
1 Enqueue: O(1)
2 Dequeue: O(1)
3 Peek: O(1)
4 Space: O(n)
Common Methods:
offer(), poll(), peek(), add(), remove()

HashSet
Time & Space Complexity:
1 Add: O(1)
2 Remove: O(1)
3 Search: O(1)
4 Space: O(n)
Common Methods:
add(), remove(), contains(), size(), clear()

TreeSet
Time & Space Complexity:
1 Add: O(log n)
2 Remove: O(log n)
3 Search: O(log n)
4 Space: O(n)
Common Methods:
add(), remove(), first(), last(), higher(), lower()

HashMap
Time & Space Complexity:
1 Put/Get: O(1)
2 Remove: O(1)
3 Space: O(n)
Common Methods:
put(), get(), remove(), containsKey(), keySet(), values(), entrySet()

TreeMap
Time & Space Complexity:
1 Put/Get: O(log n)
2 Remove: O(log n)
3 Space: O(n)
Common Methods:
put(), get(), firstKey(), lastKey(), higherKey(), lowerKey()

PriorityQueue
Time & Space Complexity:
1 Insert: O(log n)
2 Remove: O(log n)
3 Peek: O(1)
4 Space: O(n)
Common Methods:
offer(), poll(), peek(), add()
Graph (Adjacency List)
Time & Space Complexity:
1 Add Vertex: O(1)
2 Add Edge: O(1)
3 Traversal (BFS/DFS): O(V+E)
4 Space: O(V+E)
Common Methods:
addVertex(), addEdge(), dfs(), bfs()

You might also like