Explain time and space complexity.
Skip to solutionKEEP THE
easyDSA
What is Big-O notation?
892 views
01
Understand the problem
complexitybig-o
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Nudge consolestandby
Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.
03
Study the solution
Big-O describes how an algorithm's running time or space grows relative to input size n in the worst case, ignoring constants — e.g. O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n), O(n²) quadratic. It lets you compare algorithms independent of hardware.
Solution ready — 2 min read
Classified // press E to declassify
04
Read the code
Constant vs linear vs quadratic
Run Playgrounddef constant(nums): # O(1) - one access, size-independent
return nums[0] if nums else None
def linear(nums, target): # O(n) - touches each element once
for x in nums:
if x == target:
return True
return False
def quadratic(nums): # O(n^2) - every pair
pairs = []
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
pairs.append((nums[i], nums[j]))
return pairs
# --- demo ---
print(constant([10, 20, 30])) # 10
print(linear([10, 20, 30], 20)) # True
print(quadratic([1, 2, 3])) # [(1, 2), (1, 3), (2, 3)]05
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.
Transmission complete // awaiting log
KEEP THE
STREAK ALIVE.
Dossier 6 of 127 decoded in the Data Structures & Algorithms track. One more won't hurt.