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

Method query

data_structures/binary_tree/segment_tree.py:74–84  ·  view source on GitHub ↗

Query the maximum value in the range [a,b]. >>> s = SegmentTree([1, 2, 3, 4, 5]) >>> s.query(1, 3) 3 >>> s.query(1, 5) 5

(self, a, b)

Source from the content-addressed store, hash-verified

72 return True
73
74 def query(self, a, b):
75 """
76 Query the maximum value in the range [a,b].
77
78 >>> s = SegmentTree([1, 2, 3, 4, 5])
79 >>> s.query(1, 3)
80 3
81 >>> s.query(1, 5)
82 5
83 """
84 return self.query_recursive(1, 0, self.N - 1, a - 1, b - 1)
85
86 def query_recursive(self, idx, left, right, a, b):
87 """

Callers 2

show_dataMethod · 0.95
segment_tree.pyFile · 0.45

Calls 1

query_recursiveMethod · 0.95

Tested by

no test coverage detected