Agatha Wilson
Agatha Wilson

Reputation: 1

Frequency count method

I'm a newbie in data structures, this question appeared in a model question paper.

Calculate the frequency count of the statement x = x+1; in the following code segment

for (i = 0; i< n; i++)
    for (j = 0; j< n; j*=2)
        x = x + 1;

My question is would (*) affect the frequency count? There are no brackets.

Upvotes: 0

Views: 541

Answers (1)

Thomas
Thomas

Reputation: 473

j*=2 means j=j*2 (multiplication). But since j starts at 0, it will always stay 0. You have an infinite loop.

The brackets can usually be implicit if you have just one line.

It would be easier to answer knowing in what language you are working.

Upvotes: 3

Related Questions