# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Trees
#
# ## Binary Tree - PreOrder Traversal, InOrder Traversal and PostOrder Traversal
#
#
# 1. PreOrder Traversal - First root, then left subtree then right subtree
# 2. InOrder Traversal - First left subtree, then root then right subtree (Mathematical computations) 
# 3. PostOrder Traversal - First left subtree, then right subtree then root node (Infix Stack operations using )

# +
# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    
    pre = []
    
    def PreOrder(self, root):

        if root:

            # first root value is printed in pre order
            pre.append(root.val)
            
            # then left subtree
            PreOrder(root.left)
            
            # then right subtree
            PreOrder(root.right)
        
        return pre

    def InOrder(self, root):

        if root:

            InOrder(root.left)

            print(root.val),

            InOrder(root.right)

    def PostOrder(self, root):

        if root:

            PostOrder(root.left)

            PostOrder(root.right)

            print(root.val),
            

node = TreeNode(5)
node.left = TreeNode(4)
node.right = TreeNode(6)
node.left.left = TreeNode(9)
node.left.right = TreeNode(2)
node.right.left = TreeNode(7)
node.right.right = TreeNode(1)

s = Solution()
pre = s.PreOrder(node)
print("Pre Order Traversal: ", pre)

# +
val = "<NAME>"
print(ord(val[4]))

hashed = 0

for i in range(len(val)):
    
    hashed += (ord(val[i]) * (31 ** (len(val) - 1 - i))) % (10 ** 9 + 7)
    
print(hashed)
hashed - 4837933372
# -



StarcoderdataJupyterScriptsDedupFiltered