-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalysis.txt
72 lines (53 loc) · 2.14 KB
/
Analysis.txt
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
61
62
63
64
65
66
67
68
69
70
71
Time Complexity
Task0:
worse case complexity: O(2)
algorithm:
print resulting string to console [complexity: O(1)]
Total Complexity: [O(1)+ O(1)]
Task1:
worse case complexity: O(n) + O(n) + O(nlogn)
algorithm:
1.Function call for calls
a) initialize empty set [complexity: O(1)]
b) map through an addition of calls and update set [complexity: O(len(calls))]
c) return result [complexity: O(1)]
2.Function call for texts
a) initialize empty set [complexity: O(1)]
b) map through an addition of texts and update set [complexity: O(len(texts))]
c) return result [complexity: O(1)
3.Assigning to another set (call_set and text_set) [complexity: O(1) + O(1)]
4.Set update : [complexity: O(nlogn)]
5.Print and length: [O(1) + O(1)]
Total Complexity: [O(1)+O(len(calls))+O(1)+O(1)+ O(len(texts))+O(1)+O(1)+O(1)+O(1)+O(nlogn)+O(1)+O(1)]
Task2:
worse case complexity: O(n)
algorithm:
1. initialize empty dictionary [complexity: O(1)]
2. map through an addition of calls and texts to update set [complexity: O(n)]
3. Max function [complexity: O(n)]
4. print resulting string to console [complexity: O(1)]
Total Complexity: [O(1)+O(n)+O(n)+O(1)]
Task3:
worse case complexity: [Part A: O(nlogn), Part B: O(n)]
algorithm:
Part A:
1. initialize empty set [complexity: O(1)]
2. map through an addition of calls and texts to update set [complexity: O(n)]
3. sort function [complexity: O(nlogn)]
4. print resulting string to console [complexity: O(1)]
Total Complexity: [O(1)+O(n)+O(nlogn)+O(1)]
Part B:
1. initialize empty set [complexity: O(1)]
2. map through an addition of calls and texts to count [complexity: O(n)]
3. round function [complexity: O(1)]
4. print resulting string to console [complexity: O(1)]
Total Complexity: [O(1)+O(n)+O(1)+O(1)]
Task4:
worse case complexity: O(nlogn)
algorithm:
1. initialize two empty sets [complexity: O(1)+O(1)]
2. map through an addition of calls and texts to update set [complexity: O(n) + O(n)]
3. Set difference [complexity : O(n) + O(n) + O(n)]
4. sort function [complexity: O(nlogn)]
5. print resulting string to console [complexity: O(1))]
Total Complexity: [O(2n)+O(nlogn)+O(3)]