easyDSA

What is the time complexity of common operations on arrays, hash maps, and balanced trees?

753 views
01

Understand the problem

Explain operation complexities.

complexity
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Read the code

Picking the right structure
Run Playground
import bisect

# Array / list: O(1) index, O(n) search
arr = [10, 20, 30]
print(arr[1])              # 20    O(1)
print(20 in arr)           # True  O(n)

# dict (hash map): O(1) average lookup, unordered
seen = {"a": 1, "b": 2}
print(seen["a"])           # 1     O(1) avg

# Ordered / range queries: Python has no built-in BST; a sorted list
# + bisect gives O(log n) search. (3rd-party: sortedcontainers.SortedDict)
keys = [1, 3, 5]
print(keys[bisect.bisect_left(keys, 3)])   # 3   search/successor, O(log n)
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.