Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-12-06T16:38:57.677Z
Comments.Text: The huge observation here is that the value of `i` is never used in the inner loops.
Comments.UserDisplayName: Stef
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-12-07T04:18:15.643Z
Comments.Text: 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.
Comments.UserDisplayName: ggorlen
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-12-07T05:05:45.790Z
Comments.Text: Honestly  it could be anything
Comments.UserDisplayName: achhainsan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-12-08T13:13:16.930Z
Comments.Text: 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.
Comments.UserDisplayName: Ben I.
Tags: <algorithms>
Title: Is there any visualization techniques to solve time complexity problems?
ThreadText: # 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
  
  