1. Tubelator AI
  2. >
  3. Videos
  4. >
  5. Education
  6. >
  7. AA 競程 Level 1 試聽課 02:計算程式碼時間複雜度的常見方法 --- 數迴圈

AA 競程 Level 1 試聽課 02:計算程式碼時間複雜度的常見方法 --- 數迴圈

Available In Following Subtitles
English
Variant 1
Posted on:
Video by: AA 競程
Learn how to calculate the time complexity of program code efficiently by understanding common methods like counting loops and operations. Discover the importance of properly defining operations for accurate time complexity calculations.
tubelator logo

Instantly generate YouTube summary, transcript and subtitles!

chrome-icon Install Tubelator On Chrome

Video Summary & Chapters

No chapters for this video generated yet.

Video Transcript

0:01
From this video, we will demonstrate how to calculate the complexity of a program in three videos in a row.
0:10
The complexity of a program is actually a mathematical problem.
0:15
The mathematical problem is the relationship between the number of operations and the value of the program input.
0:25
The operation here refers to the addition and subtraction of basic data forms,
0:31
or the input and output of basic data forms, etc.
0:36
The definition of operation is very important.
0:39
Some people will mistake the call and the call sign for more complicated things as only one operation,
0:47
which causes a calculation error of time complexity.
0:50
We will make another video to remind you guys.
0:55
Now, I will introduce the most common way to control the mouse.
1:00
the calculation method of the number of times.
1:02
Counting each operation,
1:04
including how many times it takes to go back,
1:07
and multiplying the number of times to go back.
1:11
Now we take a real program code as an example.
1:19
In this program code,
1:21
we see that two variables, a and b, are input.
1:27
These two variables are the
1:31
the value of the city input.
1:35
The mathematical problem we need to solve is
1:38
the number of times the city code is executed
1:41
and the value of the input.
1:47
There are many forward and backward circles.
1:52
When we compute,
1:53
we usually compare the forward and backward circles
1:57
比較運算和後面的i++++++等
2:00
because the calculation frequency is usually not more than the lowest calculation in the loop.
2:12
So we only need to calculate how many times all the CNT++ executed.
2:21
按照我們剛才的說法,就是我們只需要數每個CNT++它在多少層迴圈裡面。
2:34
像第九行的CNT++,它是在六、七、八這三行的迴圈裡面。
2:42
The number of times the circle will execute is a, b, b.
2:51
So we multiply all the numbers by a.
2:55
I'll write down the number.
2:58
It will be a...
3:00
x, y, z.
3:05
Next, we see that there is a CNT++ in the 13th row.
3:09
This CNT++ is in the 6th and 12th rows of the loop.
3:16
The sequence is A and A.
3:19
So I wrote it as A x A.
3:24
Lastly, there is a CNT++.
3:27
This time it's in the 16th and 17th rows of the loop.
3:33
So multiply the number of operations of each of them by V times A.
3:42
When calculating the complexity of time,
3:45
there is a concept that we can eliminate those items that have a relatively low growth rate.
3:51
delete those items
3:54
For example, here is an A x B x B
3:58
and here is a B x A
4:00
The growth rate of BxA is definitely smaller than that of AxBxB.
4:07
So we can ignore the AxA.
4:12
So the next time complexity is
shape-icon

Download extension to view full transcript.

chrome-icon Install Tubelator On Chrome

YouTube First AI Assistant

chrome-icon Install On Chrome

AI Art For This Video No image generated for this video yet but here is the example.

ai art
0:09
Prompt
spider man in aladdin style, bright colors, hyper quality, high detail, high resolution, --video --s 750 --v 6. 0 --ar 1:2
ai images

Explore more in Education