252 views
3 3 votes

Consider the following pseudocode for a function $\verb|process(n)| :$

def process(n):
    count = 0
    i = n
    while i > 1:
        j = 1
        while j < n:
            count += 1
            j = j * 2
        i = i // 2
    return count

Determine the exact number of times the $\verb|count += 1|$ statement is executed when $n=1024$.

1 Answer

1 1 vote
Answer:- 100

Outer Loop with go i=1024,512,256,128,64,32,16,8,4,2,1

Inner Loop will go j= 1,2,4,8,16,32,64,128,256,512,1024

As both the loop will go 10 times

so Count= 10*10=100

 
Answer:
Position:
Show:

Related questions

0 0 votes
1 1 answer
194
194 views
GO Classes asked Feb 6
194 views
Consider a hash table with $M=11$ slots, using Linear Probing with the hash function $h(k, i)=(k+i) \bmod 11$, where $i \in\{0,1, \ldots, 10\}$ is the probe number. The f...
0 0 votes
1 1 answer
242
242 views
GO Classes asked Feb 6
242 views
Which of the following statement(s) is/are TRUE regarding searching and sorting?IF AN INPUT ARRAY IS ALREADY SORTED, BINARY SEARCH TAKES $O(\log n)$ TIME, BUT SEARCHING F...
0 0 votes
1 1 answer
229
229 views
GO Classes asked Feb 6
229 views
In Python, the $\verb|list|$ and $\verb|tuple|$ types handle memory allocation differently. Given the following operations:import sys L = [1, 2, 3] T = (1, 2, 3) L.append...
1 1 vote
1 1 answer
183
183 views
GO Classes asked Feb 6
183 views
def create_multipliers(): return [lambda x: i * x for i in range(4)] multipliers = create_multipliers() result = [m(2) for m in multipliers] print(result)What is ...