What is a Big O notation?
The Big O notation helps identify algorithm efficiency. It can measure computation and memory growth with respect to input.
Real-world code example
O(n) — Linear Time
func containsValue(array: [Int], value: Int) -> Bool {
for element in array {
if element == value {
return true
}
}
return false
}
O(1) — Constant Time
func findFirstElement(array: [Int]) -> Int? {
return array.first
}
Thank you for reading!