make a binary search tree algorithm in Python
Python
🤖 Code Explanation
def inorder(root):
if root:
inorder(root.left)
print(root.data)
inorder(root.right)
def search(root, key):
if root is None or root.data == key:
return root
if root.data < key:
return search(root.right, key)
return search(root.left, key)
r = Node(50)
insert(r,Node(30))
insert(r,Node(20))
insert(r,Node(40))
insert(r,Node(70))
insert(r,Node(60))
insert(r,Node(80))
inorder(r)
x = search(r, 20
More problems solved in Python
-
make a binary search tree algorithm
how do i check if a string is a palindrome
How to delete the repeated elements in an integer array?
Compute the first five Fibonacci numbers
Compute the first five Fibonacci numbers with a O(2) complexity.
remove an element from an array at a specific index
how do i divide a vector by a scalar
find the inverse cosine of a vector
find the inverse cosine of a vector without numpy
find the inverse cosine of an array without numpy
convert a quaternion to euler angles
create a docwidget pyqt5
How do you perform a binary search in a given array
Given string str, How do you find the longest palindromic substring in str
How do you find duplicate characters in a given string
Write a function to sort an array of integers in ascending order
How to check if the given number is a prime number
How do you count the number of vowels and consonants in a given string
comment faire la somme de deux listes