MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / floor

Method floor

data_structures/binary_tree/red_black_tree.py:367–382  ·  view source on GitHub ↗

Returns the largest element in this tree which is at most label. This method is guaranteed to run in O(log(n)) time.

(self, label: int)

Source from the content-addressed store, hash-verified

365 return self.left.search(label)
366
367 def floor(self, label: int) -> int | None:
368 """Returns the largest element in this tree which is at most label.
369 This method is guaranteed to run in O(log(n)) time."""
370 if self.label == label:
371 return self.label
372 elif self.label is not None and self.label > label:
373 if self.left:
374 return self.left.floor(label)
375 else:
376 return None
377 else:
378 if self.right:
379 attempt = self.right.floor(label)
380 if attempt is not None:
381 return attempt
382 return self.label
383
384 def ceil(self, label: int) -> int | None:
385 """Returns the smallest element in this tree which is at least label.

Callers 11

test_floor_ceilFunction · 0.95
get_filter_pointsFunction · 0.80
num_digits_fastFunction · 0.80
sieveFunction · 0.80
juggler_sequenceFunction · 0.80
parMethod · 0.80
decimal_to_octalFunction · 0.80
gauss_easterFunction · 0.80
solutionFunction · 0.80
solutionFunction · 0.80

Calls

no outgoing calls

Tested by 1

test_floor_ceilFunction · 0.76