@@ -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
+ 3
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,16 @@ 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], 3
70
+ >>>count_inversions_recursive([1, 1, 2, 4, 4])
71
+ [1, 1, 2, 4, 4], 0
72
+ >>>>count_inversions_recursive([])
73
+ [], 0
74
+
56
75
"""
57
76
if len (arr ) <= 1 :
58
77
return arr , 0
@@ -87,6 +106,15 @@ def _count_cross_inversions(P, Q):
87
106
R: array-like, a sorted array of the elements of `P` and `Q`
88
107
num_inversion: int, the number of inversions across `P` and `Q`
89
108
109
+ Examples
110
+ --------
111
+
112
+ >>> _count_cross_inversions([1, 2, 3], [0, 2, 5])
113
+ [0, 1, 2, 2, 3, 5], 4
114
+
115
+ >>> _count_cross_inversions([1, 2, 3], [3, 4, 5])
116
+ [1, 2, 3, 3, 4, 5], 0
117
+
90
118
"""
91
119
92
120
R = []
0 commit comments