This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes General Computing and the fly likes how to calculate space and time complexity of an algorithm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "how to calculate space and time complexity of an algorithm" Watch "how to calculate space and time complexity of an algorithm" New topic
Author

how to calculate space and time complexity of an algorithm

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 980
    
    2
hii, i m sorry if i am asking this in the wrong forum, i didn't found any specific forum for data structure.
can anyone tell me how we analyze an algorithm. also how we calculate the time and space complexity of any algorithm.
(ie. O(logn) for binary search)..
any examples...

Thank you...
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

What Google search terms did you use to find out information about this?

Did you find any relevant Wikipedia articles?

(The search term I used found a great Wikipedia article on this topic)


JBoss In Action
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 980
    
    2
actually, i want to know..
how we calculate the complexities?
i mean i have a algorithm (say about of 4 or 5 lines), how do i will calculate complexities??
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
So you did not try to use Google at all? Why not?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

If I understand you correctly, what you are trying to do is generate a complexity function for an algorithm that you have. If so, the usual way of doing that is to examine the amount of work done to handle the case where the number of objects in the collection to be processed is 1, then 2, then 3, and so on. In other words, you do this by hand, manually calculating each number.

At time, you need only n=1, n=2 and n=n' + 1 (in other words, figure out the value for any given number using one less than that number), but other times you might need more results. Based on the result, you should be able to come up with a mathematical formula that related the number of objects processed to its complexity. I recall that one of my high level math courses in college covered this. And there were several way to determine the formula based on the progression. But it has been a long time and I don't recall the details.
 
wood burning stoves
 
subject: how to calculate space and time complexity of an algorithm
 
Similar Threads
Good book to understand the Analysis and Design of Algorithm
How to transpose a matrix?
How to become a very good Java programmer?
Timing Complexity
Calculating Cyclomatic complex for a whole class