binary-search-tree

The max value in the max heap isn't the correct value

The max value in the max heap isn't the correct value Question: The program takes as input: (string)’yyyy-mm-dd’, (int)sensor id, (int)covid level. The expected output is: yyyy-mm-dd,covid level. Input: 2022−09−08, 23, 371; 2022−09−08, 2, 3171; 2022−09−08, 12, 43; 2021−03−21, 4, 129 Output: 2022 −09 −08, 3171 I have provided my code below. My output doesn’t …

Total answers: 1

Iterative approach: Validating a binary search tree

Iterative approach: Validating a binary search tree Question: def is_bst(node) q = [node] while q: node = q.pop(0) if node: if node.left: if not node.left.data < node.data: return False q.append(node.left) if node.right: if not node.right.data > node.data: return False q.append(node.right) return True is_bst(root) On educative.io I worked on this practice problem (paywall), but the gist …

Total answers: 1

What is wrong with this iterative solution in validating Binary Search Tree?

What is wrong with this iterative solution in validating Binary Search Tree? Question: The goal is, given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s …

Total answers: 1

Built-in binary search tree in Python?

Built-in binary search tree in Python? Question: Are there any self-balancing binary search tree (RED-BLACK, AVL or others) built-in types in Python 2.7 or Python 3.x? I am looking for something equivalent to Java’s TreeMap or TreeSet. If there are no such built-ins, why have they been ommited? Is there a special reason, for not …

Total answers: 2

How to implement a binary search tree in Python?

How to implement a binary search tree in Python? Question: This is what I’ve got so far but it is not working: class Node: rChild,lChild,data = None,None,None def __init__(self,key): self.rChild = None self.lChild = None self.data = key class Tree: root,size = None,0 def __init__(self): self.root = None self.size = 0 def insert(self,node,someNumber): if node …

Total answers: 18