Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 49 additions & 28 deletions lib/tree.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# bst allow efficient store + update a sorted, changing dataset
# trees are nonlinear data structures made of nodes that hold data
# nodes connected by edges that define a parent + child relationship
# first node = root node (zero or more child nodes) + is parent node of left & right children
# each node has 0 or 2 children
# filled from left to right
# can have multiple subtrees
# leaf nodes = nodes w/ 0 children



class TreeNode

attr_reader :key, :value
attr_accessor :left, :right

Expand All @@ -10,57 +22,66 @@ def initialize(key, val)
end
end



class Tree
attr_reader :root

def initialize
@root = nil
end

# Time Complexity:
# Space Complexity:
def add(key, value)
raise NotImplementedError


# Time Complexity:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space and time complexity?

# Space Complexity:

# add a value to
def add(node, value)
if node.value == value
return node
elsif value < node.value
insert(node.left, value)
elsif value > node.value
insert(node.right, value)
else
return node = Node.new(value)
end
end

# Time Complexity:
# Space Complexity:
# Time Complexity:
# Space Complexity:

# find a given node

def find(key)
raise NotImplementedError
end

# Time Complexity:
# Space Complexity:
# Time Complexity:
# Space Complexity:

def inorder
raise NotImplementedError
end

# Time Complexity:
# Space Complexity:
# Time Complexity:
# Space Complexity:

def preorder
raise NotImplementedError
end

# Time Complexity:
# Space Complexity:
# Time Complexity:
# Space Complexity:

def postorder
raise NotImplementedError
end

# Time Complexity:
# Space Complexity:
def height
raise NotImplementedError
end
# Time Complexity:
# Space Complexity:

# Optional Method
# Time Complexity:
# Space Complexity:
def bfs
def height
raise NotImplementedError
end

# Useful for printing
def to_s
return "#{self.inorder}"
end
end
end