Map of Computer

###Components

Latency Numbers Every Programmer Should Know

###Example

####Binary search vs. Linear search

#####Binary search:

if a[i] < key:
    go left
else:
    go right

The if statement is likely to fail

Runtime:

is the cost of incorrect prediction

#####Linear search

for i = 1 : n
    if a[i] = key:
        return i;

The if statement will only fail 1 time when it actually find the element. (Assumption: if branch prediction act like we want)

Runtime:


Chart showing Binary vs Linear search Picture source

Your Comments

comments powered by Disqus