11 What is the BigO running time for this code Explain your
11. What is the Big-O running time for this code? Explain your answer. int i = numItems; while (i > 0) i = i / 2; // integer division will eventually reach zero 12. What is the Big-O running time for this code? Explain your answer. public static int div(int numItems) { if (numItems == 0) return 0; else return numItems%2 + div(numItems/2); } Solution
Time complexity is O(log N) beacuse the loop variables is divided by a constant amount 2 every time.
12)
Time Complexity will be O(log N) beacuse the function variables is divided by a constant amount 2 every time.
Thanks a lot
