This project is a Disk-Based B+ Tree implementation written in C++ that utilizes a Common Gateway Interface (CGI) to visualize the tree structure in a web browser.
Unlike a standard in-memory tree, this implementation persists data to a binary file (tree.dat), simulating how actual database systems (like MySQL or SQLite) store indexes on a hard drive using fixed-size pages (4096 bytes).
- B+ Tree Structure: Implements a B+ Tree of Order 5.
- Disk Persistence: Nodes are saved to
tree.dat. If you restart the server, your data remains. - Web Interface: A clear HTML interface to Insert and Search for keys.
- Visual Debugging: The C++ backend generates HTML to visually render the tree nodes, distinguishing between Internal Nodes (orange) and Leaf Nodes (green).
index.html: The entry point. A web form to input values and select "Insert" or "Search".server.py: A Python script that acts as the web server. It handles the CGI requests and automatically opens your browser.common.h: Configuration file. DefinesPage Size,Tree Order, and theNodestructure.functions.h: Header file containing function declarations.storage.cpp: Handles low-level file I/O (reading/writing binary pages to disk).b+_tree.cpp: Contains the core B+ Tree logic (splitting nodes, finding leaves, inserting keys).main_cgi.cpp: The bridge between the web and C++. It reads URL parameters, executes tree operations, and outputs HTML code.
To run this project, you need:
- C++ Compiler: GCC (MinGW for Windows) or Clang.
- Python 3.x: To run the local server.
Open your terminal/command prompt in the project root directory. Run the following command to compile the C++ files into the cgi-bin folder:
For Windows (MinGW):
g++ main_cgi.cpp storage.cpp dommy.cpp -o cgi-bin/tree_app.exeFor Linux/Mac:
g++ main_cgi.cpp storage.cpp dommy.cpp -o cgi-bin/tree_app.exeIn the terminal (still in the project root), run the Python server script:
python server.py- The script should automatically open
http://localhost:8080/index.htmlin your default browser. - Enter a number (e.g.,
10) and click Do. - The page will reload showing the B+ Tree structure.
- Keep inserting numbers (e.g.,
20,5,15,30) to see the tree split and grow.
- A B+ tree web page with two functions
searchandinsert:
- A simple visualization for the operation and the B+ tree:
To clear the database and start with an empty tree, simply delete the tree.dat file that appears in your project folder after running the app. A new one will be created automatically on the next insert.

