Link to home
Create AccountLog in
Avatar of zizi21
zizi21

asked on

Help on big oh analysis

Hi,

I am trying to understand big oh notations. Please correct me.

Say there is a program that accesses a file on disk randomly and say the size of the file n.
So, the big oh notation for this program is O(n) this is because it may access the file randomly at n positions. However, there is a possibility that the program assess the data for the file from the cache but lets ignore this for now.

If the program accesses the file sequantially (one after the other), the big oh notation is O(1).

Is this right ?

Thank you very much.
Avatar of ozo
ozo
Flag of United States of America image

O(1) time for a single access.
O(n) time to access all of the file.
Avatar of zizi21
zizi21

ASKER

Doesn't making random accesses to disk does not make a difference to the big oh notation ?
Avatar of zizi21

ASKER

Thanks ozo. I thought random accesses influeces big oh notations ?
It can.  
What disk operations does the program require?
Avatar of zizi21

ASKER

Thanks ozo.

The program accesses the data on file on random positions...But, how do I write that in big oh notation?
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of zizi21

ASKER

Thank you very much for the reply.

Does this mean that if seeking gets slower in large files, it is always sqrt(n)? But, why sqrt(n)  and not only other number ? Seeking would get slower in larger files because the files would not be cached in RAM. But, if the file is small, it is cached in RAM and accessing it is fast.

For example, if the size of the file is larger than the available RAM, we can say the file is not cached into RAM. And, in this situation, making random accesses is expensive.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of zizi21

ASKER

Thank you very much for all the replies. I am studying it now.
Avatar of zizi21

ASKER

"If you read the data sequentially, it will take twice as long to read the entire file if the data doubles, so sequential reading is also an O(n) operation. "

Thank you very much for your reply. If I understand this correctly, accessing each record of data takes O(1) time (for sequential access) and O(n) for the entire file.
Under that scenario, reading 1 record is O(1), reading n records is O(n)
Avatar of zizi21

ASKER

Thank you very much....
Avatar of zizi21

ASKER

Thank you .
Avatar of zizi21

ASKER

I spent days trying to understand and all of you helped lots...Thank you verymuch.
For very large files, I was saying that because additional cylinders will result in the average seek time in accessing a single record will increase linearly as the number of cylinders increase, then reading one record is O(n), not O(1).

Suppose a file is small, and that the additional records are placed in the same cylinder. In that case the reading of one records is O(1).