@@ -26,6 +26,17 @@ 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
+ 3
34
+
35
+ >>> count_inversions_bf([1, 1, 2, 4, 4]
36
+ 0
37
+
38
+ >>> count_inversions_bf([])
39
+ 0
29
40
"""
30
41
31
42
num_inversions = 0
@@ -53,6 +64,17 @@ def count_inversions_recursive(arr):
53
64
C: a sorted copy of `arr`.
54
65
num_inversions: int, the total number of inversions in 'arr'
55
66
67
+ Examples
68
+ --------
69
+
70
+ >>> count_inversions_recursive([1, 4, 2, 4, 1])
71
+ [1, 1, 2, 4, 4], 3
72
+
73
+ >>> count_inversions_recursive([1, 1, 2, 4, 4])
74
+ [1, 1, 2, 4, 4], 0
75
+
76
+ >>>> count_inversions_recursive([])
77
+ [], 0
56
78
"""
57
79
if len (arr ) <= 1 :
58
80
return arr , 0
@@ -87,6 +109,15 @@ def _count_cross_inversions(P, Q):
87
109
R: array-like, a sorted array of the elements of `P` and `Q`
88
110
num_inversion: int, the number of inversions across `P` and `Q`
89
111
112
+ Examples
113
+ --------
114
+
115
+ >>> _count_cross_inversions([1, 2, 3], [0, 2, 5])
116
+ [0, 1, 2, 2, 3, 5], 4
117
+
118
+ >>> _count_cross_inversions([1, 2, 3], [3, 4, 5])
119
+ [1, 2, 3, 3, 4, 5], 0
120
+
90
121
"""
91
122
92
123
R = []
0 commit comments