New Coder

Start coding!

Only editable by group admins

  • Last updated December 7, 2015 at 4:39 PM by hankish
  • Evidence visible to public
Once you have written your first lines of code, paste them into the window as evidence. Make sure to tell us what coding language its in, and give a shout out to the person or organization who taught you how to code!

Note: When posting your evidence you can click the "</>" button on the right of the toolbar to insert a code block.  That will make your code look pretty.

All posted evidence

You can invert a binary tree using recursive and iterative approaches. Below are the three approaches to solve this problem:

Recursive Approach: Swapping the left and right child of every node in subtree recursively.
Using Iterative preorder traversal: Converting recursive approach to iterative by using stack.

https://favtutor.com/blogs/invert-binary-tree
codypeltz41 Over 2 years ago

Invert a Binary Tree

class Node:
   def __init__(self, data):
      self.left = None
      self.right = None
      self.data = data

   def PrintTree ( self ) :
       if self.left :
           self.left.PrintTree ()
       print ( self.data, end= ' ' ) ,
       if self.right :
           self.right.PrintTree ()

class Solution:
    '''
    Function to invert the tree
    '''
    def invertTree(self, root):
       if root == None:
           return
       root.left, root.right = self.invertTree(root.right),self.invertTree(root.left)
       return root

if __name__ == '__main__':
    '''
                10                                              10
              /    \                                          /    \           
            20      30              ========>>              30      20           
           /         \                                      /        \
          40          50                                  50          40 
    '''
    Tree = Node(10)
    Tree.left = Node(20)
    Tree.right = Node(30)
    Tree.left.left = Node(40)
    Tree.right.right = Node(50)
    print('Initial Tree :',end = ' ' )
    Tree.PrintTree()
    Solution().invertTree(root=Tree)
    print('\nInverted Tree :', end=' ')
    Tree.PrintTree()
    
    

Reference : https://favtutor.com/blogs/invert-binary-tree
codypeltz41 Over 2 years ago
The Distance Education Department at Union County College sponsored an #hourofcode and we covered Elsa/Anna, Angry Birds, and Eliza.  

Here is the Python code for a simple calculator:


# Program make a simple calculator
# that can add, subtract, multiply # and divide using functions # define functions def add(x, y): """This function adds two numbers""" return x + y def subtract(x, y): """This function subtracts two numbers""" return x - y def multiply(x, y): """This function multiplies two numbers""" return x * y def divide(x, y): """This function divides two numbers"""

http://www.programiz.com/python-programming/examples/calculator

bethritterguth Over 9 years ago

def registerValidators(self): 
  # TODO: Use JSON-LD for this? 
  contextObj = badgeanalysis.utils.try_json_load(self.context_json) 
  validators = contextObj.get('obi:validation') 
  if validators is not None and isinstance(validators, list): 
    for validator in validators: 
      validationSchema = validator.get('obi:validationSchema') 
      validatesType = validator.get('obi:validatesType')
      schema_json = badgeanalysis.utils.try_json_load(badgeanalysis.utils.fetch_linked_component(validationSchema)) 
      bsv = BadgeSchemaValidator(validation_schema=validationSchema, validates_type=validatesType, schema_json=schema_json, scheme=self) bsv.save() 
  elif isinstance(validators, dict): 
    bsv = BadgeSchemaValidator(self, validation_schema=validators.get('obi:validationSchema'), validates_type=validators.get('obi:validatesType'), scheme=self) 
    bsv.save()
Shoutout to Concentric Sky for making this code possible.

ottonomy Over 9 years ago