I'm learning Data Structures and Algorithms now, I have a practical question that asked to write a function with O(log3n), which means log(n)*log(n)*log(n).
public void run(int n) { for (int i = 1; i < n; i *= 2) { for (int j = 1; j < n; j *= 2) { for (int k = 1; k < n; k *= 2) { System.out.println("hi"); } } } } I have come with this solution, but it seems not correct. Please help me out.
Asked By : Timeless
Answered By : usr
Your program is correct. Your could also iterate Math.Log(n)*Math.Log(n)*Math.Log(n) times. Not sure if that is considered cheating.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/2411
0 comments:
Post a Comment
Let us know your responses and feedback