<p>Say problems like this. I am not looking to the solution of this problem alone. I am looking for a mindset of visualization that you have devised as a trick for yourself.</p>
<p><strong>Find the value of q in terms of n?</strong></p>
<pre><code>function fun(n) {
  let i,
    j,
    p,
    q = 0;
  for (i = 1; i &lt;= n; ++i) {
    p = 0;
    for (j = n; j &gt; 1; j = j / 2) {
      ++p;
    }
    for (k = 1; k &lt; p; k = k * 2) {
      ++q;
    }
  }
  return q;
}

let val_q = fun(36);
console.log(val_q);
</code></pre>
<p>I want to learn how to learn it.</p>
<p>Like is there some visualization techniques that you've devised that helps in solving these kind of problems by hand.</p>

CC BY-SA 4.0
2023-12-06T16:38:57.677Z
The huge observation here is that the value of `i` is never used in the inner loops.
Stef
CC BY-SA 4.0
2023-12-07T04:18:15.643Z
By ["visualization"](https://en.wikipedia.org/wiki/Data_and_information_visualization), do you mean [plotting the time it takes the algorithm to run on different input sizes](https://dev.to/chroline/visualizing-algorithm-runtimes-in-python-f92) to see how it scales, or are you referring more to mental strategies for figuring it out? If the latter, I wouldn't use the word "visualization" as it generally refers to plotting/charting stuff, I think.
ggorlen
CC BY-SA 4.0
2023-12-07T05:05:45.790Z
Honestly  it could be anything
achhainsan
CC BY-SA 4.0
2023-12-08T13:13:16.930Z
This seems a poor exercise to me.  I can't tell exactly what it's doing, but I can see that it's doing it in a nonsensically roundabout way.
Ben I.
<algorithms>
Is there any visualization techniques to solve time complexity problems?
# Is there any visualization techniques to solve time complexity problems?

(Asked by: username_0 on 2023-12-06)

Say problems like this. I am not looking to the solution of this problem alone. I am looking for a mindset of visualization that you have devised as a trick for yourself.
Find the value of q in terms of n?
function fun(n) {
  let i,
    j,
    p,
    q = 0;
  for (i = 1; i <= n; ++i) {
    p = 0;
    for (j = n; j > 1; j = j / 2) {
      ++p;
    }
    for (k = 1; k < p; k = k * 2) {
      ++q;
    }
  }
  return q;
}

let val_q = fun(36);
console.log(val_q);

I want to learn how to learn it.
Like is there some visualization techniques that you've devised that helps in solving these kind of problems by hand.

**Tags:** algorithms

> **Comments:**
> **username_1**: The huge observation here is that the value of `i` is never used in the inner loops.  
> **username_2**: By ["visualization"](https://en.wikipedia.org/wiki/Data_and_information_visualization), do you mean [plotting the time it takes the algorithm to run on different input sizes](https://dev.to/chroline/visualizing-algorithm-runtimes-in-python-f92) to see how it scales, or are you referring more to mental strategies for figuring it out? If the latter, I wouldn't use the word "visualization" as it generally refers to plotting/charting stuff, I think.  
> **username_0**: Honestly  it could be anything  
> **username_3**: This seems a poor exercise to me.  I can't tell exactly what it's doing, but I can see that it's doing it in a nonsensically roundabout way.  

---

## 0 answers

