Cheap and Secure Web Hosting Provider : See Now

[Solved]: Attempt to write a function with cubed log runtime complexity $O(\log^3 n)$

, , No Comments
Problem Detail: 

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 :

 Ask a Question

 Download Related Notes/Documents


Post a Comment

Let us know your responses and feedback