-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh6-BigO.txt
More file actions
18 lines (18 loc) · 726 Bytes
/
Ch6-BigO.txt
File metadata and controls
18 lines (18 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
6.1: O(n) - correct
6.2: O(n) - correct
6.3: O(1) - correct
6.4: O(n) - false: O(a/b)
6.5: O(log n) - correct
6.6: O(sqrt(n)) - correct
6.7: O(n) - correct
6.8: O(n) - correct
6.9: O(n!) - false: O(n^2), where n = # of elements in the array.
first call to appendoNew takes 1 copy, 2nd 2.. n, totat is a sum
of 1..n, which is O(n^2)
6.10: O(n) - false: O(log n), runtime is # of digits in number
6.11: O(n!) - false: O(kc^k), where k = len of string and c = # chars
in alphabet. It takes O(c^k) time to generate each string. Checking takes
O(k) time
6.12: O(log n) - false: O(b log b + a log b), sorting array b takes O(b log b)
time, then foreach elem in a we do binary search in O(log b) time, so takes
O(a log b) time