BST Traversal.pdf

Document Details

IncredibleGalaxy1978

Uploaded by IncredibleGalaxy1978

Camarines Sur Polytechnic Colleges

Tags

binary search tree tree traversal data structures

Full Transcript

def preorder(root): if root: # Traverse root print(str(root.val) + "->", end=‘’) # Traverse left preorder(root.left) # Traverse right preorder(root.right) def inorder(root): if root: # Traverse left inorder(root.left) # Traverse root print(str(root.val...

def preorder(root): if root: # Traverse root print(str(root.val) + "->", end=‘’) # Traverse left preorder(root.left) # Traverse right preorder(root.right) def inorder(root): if root: # Traverse left inorder(root.left) # Traverse root print(str(root.val) + "->", end='') # Traverse right inorder(root.right) def postorder(root): if root: # Traverse left postorder(root.left) # Traverse right postorder(root.right) # Traverse root print(str(root.val) + "->", end='') 8 3 10 1 6 14 4 7 13 8 3 10 1 6 14 4 7 13 8 3 1 6 4 7 10 14 13 8 3 10 1 6 14 4 7 13 1 3 4 6 7 8 10 13 14 8 3 10 1 6 14 4 7 13 1 4 7 6 3 13 14 10 8 1 2 3 4 5 6 7 8 9 10 11 13 14 1 2 3 4 5 6 7 8 9 10 11 13 14 1 2 4 8 9 5 10 11 3 6 13 7 14 1 2 3 4 5 6 7 8 9 10 11 13 14 8 4 9 2 10 5 11 1 6 13 3 14 7 1 2 3 4 5 6 7 8 9 10 11 13 14 8 9 4 10 11 5 2 13 6 14 7 3 1 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 124795368 1 2 3 4 5 6 7 8 9 794251368 1 2 3 4 5 6 7 8 9 974528631

Use Quizgecko on...
Browser
Browser