3 votes 3 votes What is the running time of the following loop? Loop2(n) p <-- 1 for i <-- 1 to 2n do p <-- p*i $\Theta(n^2)$ $\Theta(n)$ $\Theta(n\lg n)$ $\Theta(n^2\lg n)$ Algorithms go-alogrithms-1 time-complexity + – Bikram asked Oct 4, 2016 Bikram 346 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 4 votes 4 votes Loop2(n) p <-- 1 for i <-- 1 to 2n do p <-- p*i Variable used in for loop is i. variable modify after each iteration is p actually. i remain unchange. So for loop will run n time and complexity will be O(n). Digvijay Pandey answered Oct 11, 2016 • selected Oct 11, 2016 by Arjun Digvijay Pandey comment Share Follow See all 2 Comments See all 2 2 Comments reply kamakshi commented Oct 28, 2017 reply Follow Share can u show the steps of execution pls? 0 votes 0 votes chauhansunil20th commented Jan 10, 2019 reply Follow Share @Arjun why it is assumed here that multiplication will take constant time? In general, do we need to consider constant TC for multiplication?, i don't think so. 0 votes 0 votes Please log in or register to add a comment.