शुरू करेंमुफ़्त में शुरू करें

BST का न्यूनतम node खोजना

इस अभ्यास में, आप एक BST पर अभ्यास करेंगे ताकि न्यूनतम node ढूँढ सकें.

अपने कोड को टेस्ट करने के लिए, आप निम्न tree का उपयोग कर सकते हैं:

Graphical representation of a binary search tree.

इसे bst वैरिएबल (लाइन 14) में preload किया गया है:

bst = CreateTree()

आप find_min() मेथड जो परिणाम लौटाता है, उसे इस कोड (लाइन 15) से प्रिंट कर सकते हैं:

print(bst.find_min())

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में Data Structures और Algorithms

पाठ्यक्रम देखें

अभ्यास निर्देश

  • current_node को root के रूप में सेट करें.
  • उपयुक्त subtree के nodes पर iterate करें.
  • current_node के मान को अपडेट करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

class BinarySearchTree:
  def __init__(self):
    self.root = None

  def find_min(self):
    # Set current_node as the root
    current_node = ____
    # Iterate over the nodes of the appropriate subtree
    while current_node.____:
      # Update current_node
      current_node = current_node.____
    return current_node.data
  
bst = CreateTree()
print(bst.find_min())
कोड संपादित करें और चलाएँ