Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between accessing and searching? (when determining time complexity of an array)

According to this website: http://bigocheatsheet.com/ Accessing an array is constant time but searching it is O(n). What's the difference between accessing an array and searching it?

like image 265
SilentDev Avatar asked Jan 18 '26 04:01

SilentDev


2 Answers

Accesing means looking up an item value by index, while searching means looking up an index by item value. Obviously an array lookup is constant, while linear searching is, well.. linear.

like image 177
Blindy Avatar answered Jan 20 '26 19:01

Blindy


Accessing means using the value a[i]. Searching means finding the i you want.

For example, where in this answer is the last letter E? You have to look at every letter in my answer, because I might have written EEEEEEE

like image 45
Davislor Avatar answered Jan 20 '26 21:01

Davislor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!