-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimecomplexity
60 lines (48 loc) · 1.69 KB
/
timecomplexity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Time complexity- it is amount of time taken by algorithm to run.
Big O Notation-O
Big Theta-Q
Big Omega- _^_
_^_ Best Case - Constant
O Worst Case-> directly proportional to n
Q (theta) avg case- directly proportional to n
Avg Time- 1+ 2+ 3+ ...... +n/n= n(n+1)/2
Avg directly proportional to n.
Best - omega(1)
worst- O(n)
Avg- theta(n)
constant Time- O(1)
Linear Time- O(n)
Logarthmic Time- O(log n)
Quadratic Time-O(n^2)
cubic Time- O(n^3)
for(i=1 ;i<n;i++)--------------------------------------------------- O(n)\
\ O(n *n)----O(n^2)--- Time Complexity
O(1)- --- Space Complexity
{ /
for(int j=1;j<n;j++) ----------------------------------------- O(n) /
{
cout << "">
}
}
for(int i=0;i<10;i++)----------------- O(1)---------Time Complexity
O(1)--------space complexity
{
some constant statement
}
for(i=0 to n)
{
--------
--------
}
TC- O(n)
SC- O(1)
for( i=1 to n)---------n______________________________________________________|
{ | TC- O(n^3)
for(i=1 to n)--------------------------------------------n | SC- O(1)
{ |
for(i=1 to n)------------------------------n |
{
statement;
}
}
}