MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / rank

Function rank

data_structures/binary_tree/wavelet_tree.py:100–118  ·  view source on GitHub ↗

Returns the number of occurrences of num in interval [start, end] in the list >>> root = build_tree(test_array) >>> rank(root, 6, 3, 13) 2 >>> rank(root, 2, 0, 19) 4 >>> rank(root, 9, 2 ,2) 0 >>> rank(root, 0, 5, 10) 2

(node: Node | None, num: int, start: int, end: int)

Source from the content-addressed store, hash-verified

98
99
100def rank(node: Node | None, num: int, start: int, end: int) -> int:
101 """
102 Returns the number of occurrences of num in interval [start, end] in the list
103
104 >>> root = build_tree(test_array)
105 >>> rank(root, 6, 3, 13)
106 2
107 >>> rank(root, 2, 0, 19)
108 4
109 >>> rank(root, 9, 2 ,2)
110 0
111 >>> rank(root, 0, 5, 10)
112 2
113 """
114 if start > end:
115 return 0
116 rank_till_end = rank_till_index(node, num, end)
117 rank_before_start = rank_till_index(node, num, start - 1)
118 return rank_till_end - rank_before_start
119
120
121def quantile(node: Node | None, index: int, start: int, end: int) -> int:

Callers

nothing calls this directly

Calls 1

rank_till_indexFunction · 0.85

Tested by

no test coverage detected