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

Method search

data_structures/binary_tree/red_black_tree.py:350–365  ·  view source on GitHub ↗

Search through the tree for label, returning its node if it's found, and None otherwise. This method is guaranteed to run in O(log(n)) time.

(self, label: int)

Source from the content-addressed store, hash-verified

348 return self.search(label) is not None
349
350 def search(self, label: int) -> RedBlackTree | None:
351 """Search through the tree for label, returning its node if
352 it's found, and None otherwise.
353 This method is guaranteed to run in O(log(n)) time.
354 """
355 if self.label == label:
356 return self
357 elif self.label is not None and label > self.label:
358 if self.right is None:
359 return None
360 else:
361 return self.right.search(label)
362 elif self.left is None:
363 return None
364 else:
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.

Callers 1

__contains__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected