hdude0164's blog

By hdude0164, history, 3 years ago, In English

Where is this formula used?

left_tree (data) <= node (data) <= right_tree (data)

Binary tree or BST or AVL Tree or Heap

  • Vote: I like it
  • -18
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Probably BST

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Are you sure, anyone please confirm?

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      Yes, because it's BST's properties. When insert new node, we do this:

      void insert(Node*& root, int key, int value) {
        if (!root) 
          root = new Node(key, value);
        else if (key == root->key)
          root->value = value;
        else if (key < root->key)
          insert(root->left, key, value);
        else  // key > root->key
          insert(root->right, key, value);
      }
      

      so it's easy to prove that he's right :3

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

bst