patternMinor
What constitutes one unit of time in runtime analysis?
Viewed 0 times
whatconstitutesruntimeanalysistimeoneunit
Problem
When calculating runtime dependence on the input, what calculations are considered? For instance, I think I learned that array indexing as well as assignment statements don't get counted, why is that?
Solution
When doing complexity calculations we generally use RAM model. In this model we assume that array indexing is O(1). Assignment statement is just like assigning some value to some variable ins array of variables. This is just for convenience. It simplifies analysis of the algorithm. In real world array indexing takes $\approx$ O(log I) where I is number of things indexed.
We generally consider things that depend on size of input e.g. loops. Even if there is O(1) operation in the loop and it is executed n times then algorithm runs for O(n) time.
But O(1) operation outside of loop take only constant time and O(n) + O(1) = O(n).
Read about radix sort algorithm from CLRS.
We generally consider things that depend on size of input e.g. loops. Even if there is O(1) operation in the loop and it is executed n times then algorithm runs for O(n) time.
But O(1) operation outside of loop take only constant time and O(n) + O(1) = O(n).
Read about radix sort algorithm from CLRS.
Context
StackExchange Computer Science Q#13254, answer score: 6
Revisions (0)
No revisions yet.