<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      算法與數據結構-各種循環的時間復雜度分析(英語)

      前言

      在英語面試中可能需要 用英語表達算法的時間復雜度,這篇博文是學習后自我訓練的筆記,用學過的英語來描述算法的時間復雜度。

      首先介紹如何用英語表達指數冪,然后是各種循環的復雜度分析。

      How to express the exponent?

      M to the power of N = M^N

      x to the power of two thirds = (x)^(2/3)

      x squared = x^2

      x cubed = x^3

      x plus y quantity squared = (x+y)^2

      the sum of X one, X two and so on out to Xn, the whole string in parenthesis,raised to the second power = (x1 + x2 + x3 + ... + xn)^(2)

      simple for-loop with an increment of size 1

      for (int x = 0; x < n; x++) {
          //statement(s) that take constant time
      }
      

      The initialization statement assign 0 to x runs once.

      Java for loop increments the value x by 1 in every iteration.So the x is first 0,then 1,then 2,...,then n-1.

      The increment statement xplusplus runs n times.

      The comparison statement x is less than n runs n plus 1 time.

      Summing them up, we get a running time complexity of for loop of n + n + 1 + 1 = 2*n + 2

      The statements inside the loop runs n times, supposing these statements account for a constant running time of c in each iteration, they account for a running time of c*n throughout the loop's lifetime.Hence the running time complexity is XXX

      for-loop with increments of size k

      for (int x = 0; x < n; x+=k) {
          //statement(s) that take constant time
      }
      

      The initialization statement runs once.

      The incrementation part x+k runs floor(n/k) times

      The comparision statement x<n runs the same time as the incrementation part and one more time in the last iteration.

      The inside the loop runs c * floor(n/k) times.

      Summing them up, the running time complexity is 1 + n/k + n/k + 1 + c * n/k = (c+2)/k* n + 2

      Dropping the leading constants (c+2)/k ==> n + 2

      Dropping the lower order items ==> O(n)

      simple nested for-loop

      for (int i=0; i<n; i++){
          for (int j=0; j<m; j++){
              //Statement(s) that take(s) constant time
          }
      }
      

      The inner loop runs (1+1+m+m)+c*m = (2m+2)+cm

      The outer loop runs (1+1+n+n) + n(2m+2+cm) = (2+c)nm+4n+2 ,which is O(nm)

      Nested for-loop with dependent variables

      for (int i=0; i<n; i++){
          for (int j=0; j<i; j++){
              //Statement(s) that take(s) constant time
          }
      }
      

      Let's start with the inner loop.

      The initialization statement j = 0 runs n times throughout the whole lifetime.

      The comparison statement j < i runs different times when i is set to different value. For example, the first time when i is 0,j<i runs once, the second time when i is 1, the statement runs 2, so when i is n-1, the statement runs n times. So, this statement runs 1+2+...+n times,which is(1+n)*n/2 times.

      The increment statement j++ runs 0 + 1+2+...+n-1 times,which is (n-1)*n/2

      The statement inside the inner loop runs also c(n-1)n/2 times

      As for the outer loop, the statements runs a total of 2n+2 times

      Hence, the running time complexity is n+(1+n)n/2 + (n-1)n/2 + c(n-1)n/2 + 2n+2 which is O(n^2)

      Nested for-loop with index modification(a little bit hard)

      for (int i=0; i<n; i++){
          i*=2;
          for (int j=0; j<i; j++){
              // Statement(s) that take(s) constant time
          }
      }
      

      The initialization statement i=0 runs once;

      How much times dose the comparison statement i <n and i++ and the inside of the outer loop run ?

      To calculate these, we should ignore the i++ after the first iteration. For example i is first 0 , i is then 1, then i is 2, then i is 4... until i is great than n.

      we assume n is greater than 2^k and less than 2^(k+1)

      so, the i *=2 statement runs k times, and the i < n statement runs k+1 times, which k is estimately log2(n).

      The statement j++ of the inner loop inside the outer loop runs

      1+2+4+...+2^log2(n) = 2^(log(n)+1) - 1 = 2*n -1 times

      So the total times is (2n-1)2 + 2 + (2n-1)c

      Hence we can get the sum time of the code is 1 + 1 + 2(2n-1) + 2(2n-1) + 2+ (2n-1)*c

      The term linear in n dominates(支配了) the others and the time complexity is O(n).

      Note that the quiz can have a rough but not a tight bound approximation, that is the outer loop runs at most n times, the inner for-loop iterates at most n times each iteration of the outer loop. So we can conclude that the running time complexity is O(n^2).

      posted @ 2021-05-31 16:54  Ging  閱讀(459)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲丶国产丶欧美一区二区三区| 久久激情影院| 日本丰满少妇裸体自慰| 中文字幕在线日韩| 国产高清视频一区二区乱| 大香伊蕉在人线国产免费| 罗甸县| 福利网午夜视频一区二区| 九九热精品免费在线视频| 日韩欧美视频一区二区三区| 麻豆亚洲精品一区二区| 亚洲av产在线精品亚洲第一站| 亚洲av无码精品蜜桃| 免费国产一级 片内射老| 国产无码高清视频不卡| 日韩高清不卡一区二区三区| 正在播放肥臀熟妇在线视频| 丝袜美腿亚洲综合在线观看视频| 日韩乱码卡一卡2卡三卡四| 人妻偷拍一区二区三区| 99中文字幕国产精品| 最新国产精品拍自在线观看| 无码专区一va亚洲v专区在线| 性一交一乱一伦一| 在线观看中文字幕国产码| 精品无码久久久久久尤物| 久久综合综合久久综合| 成人午夜福利精品一区二区| 亚洲 日本 欧洲 欧美 视频| 久久99久久99精品免视看国产成人| 亚洲AV日韩精品久久久久| 国产偷国产偷亚洲综合av| 潘金莲高清dvd碟片| 国产免费无遮挡吸奶头视频 | 中文国产不卡一区二区| 99热这里只有成人精品国产| 2021国产成人精品久久| 日本精品成人一区二区三区视频 | 十八禁在线观看视频播放免费| 午夜色大片在线观看免费| 小污女小欲女导航|