@@ -26,6 +26,15 @@ def count_inversions_bf(arr):
26
26
-------
27
27
num_inversions: The total number of inversions in `arr`
28
28
29
+ Examples
30
+ ---------
31
+
32
+ >>> count_inversions_bf([1, 4, 2, 4, 1])
33
+ 4
34
+ >>> count_inversions_bf([1, 1, 2, 4, 4]
35
+ 0
36
+ >>> count_inversions_bf([])
37
+ 0
29
38
"""
30
39
31
40
num_inversions = 0
@@ -53,6 +62,15 @@ def count_inversions_recursive(arr):
53
62
C: a sorted copy of `arr`.
54
63
num_inversions: int, the total number of inversions in 'arr'
55
64
65
+ Examples
66
+ --------
67
+
68
+ >>> count_inversions_recursive([1, 4, 2, 4, 1])
69
+ ([1, 1, 2, 4, 4], 4)
70
+ >>> count_inversions_recursive([1, 1, 2, 4, 4])
71
+ ([1, 1, 2, 4, 4], 0)
72
+ >>> count_inversions_recursive([])
73
+ ([], 0)
56
74
"""
57
75
if len (arr ) <= 1 :
58
76
return arr , 0
@@ -87,6 +105,13 @@ def _count_cross_inversions(P, Q):
87
105
R: array-like, a sorted array of the elements of `P` and `Q`
88
106
num_inversion: int, the number of inversions across `P` and `Q`
89
107
108
+ Examples
109
+ --------
110
+
111
+ >>> _count_cross_inversions([1, 2, 3], [0, 2, 5])
112
+ ([0, 1, 2, 2, 3, 5], 4)
113
+ >>> _count_cross_inversions([1, 2, 3], [3, 4, 5])
114
+ ([1, 2, 3, 3, 4, 5], 0)
90
115
"""
91
116
92
117
R = []
0 commit comments