---
# System prepended metadata

title: 'More example of big O notation: Chapter 1'
tags: [Kiditech]

---

###### tags: `Kiditech`

# More example of big O notation: Chapter 1 

O(1) means that, no matter how much data, it will execute in constant time. 

```
# Example 1
x = 2 * 10   o(1) constant time for this caculation
print(x)     o(1) constant time to print
```

```
# Example 2
def max(n1 , n2)  
    if n1>n2:     o(1) constant time compare n1 and n2
        return n1
    elseL
        return n2  
```
**In the Example 1 , both of the 2*10 and print(x) take 
constant time , so the big o is n(1)**

**Example 2 is a max function that returns the item with the highest value , the time for computer to compare two number is constant , we we say the big o for this function is o(1)**


O(n) means that it is proportional to the amount of data

```
# Example 3
for x in range(0,100):  O(n) time for this for loop  
    print(x)            o(1) constant time to print   
```

```
# Example 4 Linear Search for target 'z'
list = ['t','u','t','o','r','i','a','z']
target ='z'
def LinearSearch(list , target)
    for index in rabge(0,8):       O(n) time for this search 
        if x == target:
            return index
```

**Example 3 is a agrorithms with O(n) complexity , remember that even though  "printx(x)" takes only o(1) time but we alwasys focue on the  dominant term in big o notation, so the complexity is o(n) not o(1)**


**Example 4 is a Linear Search to search the target's index in a list :
A linear search looks down a list, one item at a time, without jumping. In complexity terms this is an O(n) search - the time taken to search the list gets bigger at the same rate as the list does.**
