Giter Club home page Giter Club logo

binary-search-tree's Introduction

Binary Search Tree

This C++ project provides an implementation of a Binary Search Tree (BST) data structure with a variety of operations such as insert, search, remove, select, split, and join. It also includes a unique function insert_random that inserts nodes randomly.

Overview

The code contains the following functions:

  • fix_size(Node *T): Updates the size of a node based on the number of its child nodes.
  • insert(Node *T, int k): Inserts a node with key k into the BST.
  • inorder_traversal(Node *T): Returns a vector of key values from an inorder traversal of the BST.
  • find(Node *T, int k): Searches for a node with key k in the BST and returns it if found.
  • select(Node *T, int r): Returns a node of rank r in the BST.
  • join(Node *L, Node *R): Joins two trees, where all keys in L are less than or equal to keys in R.
  • remove(Node *T, int k): Removes a node with key k from the BST.
  • **split(Node *T, int k, Node **L, Node R): Splits the tree T into two trees L and R based on key k.
  • insert_random(Node *T, int k): Inserts a node with key k into the BST at a random position.
  • printVector(vector v): Prints the elements of a vector.

How to Run

You can compile the program with a C++ compiler, e.g., g++ or clang++. The main function is currently commented out, but it contains a series of tests that you can use to verify the functionality of the BST operations.

Uncomment the main function and then compile and run the program with:

$ g++ -o bst binarySearchTree.cpp
$ ./bst

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.