Skip to content

About

A Java implementation of a plain Binary Tree with level-order insertion, BFS traversal, and DFS traversals (inorder, preorder, postorder). Built without using any inbuilt Java collections. Queue is implemented manually using linked nodes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binary Tree (Level-Order Insertion) — Java Implementation

This repository contains a clean, beginner-friendly Java implementation of a Binary Tree that supports:

  • ✔ Level-order insertion (first empty left or right position)
  • ✔ BFS traversal (level-order)
  • ✔ DFS traversals (Inorder, Preorder, Postorder)
  • ✔ Custom queue implementation using linked nodes
  • ✔ Menu-based user interaction (switch-case based)

No inbuilt Java collections (like LinkedList, Queue, or ArrayList) were used.
Everything is implemented manually for learning core data structures.


⭐ Features

🌳 Binary Tree Structure

A simple binary tree where nodes are inserted top-to-bottom, left-to-right, similar to a complete binary tree.

🔄 Level-Order Insertion

The program finds the first available position using a custom queue.
Example tree when inserting: 10, 20, 30, 40, 50:

10

/
20 30 /
40 50

🔍 BFS Traversal

Prints nodes in level-order using the same queue logic.

🔽 DFS Traversals

  • Inorder: Left → Root → Right
  • Preorder: Root → Left → Right
  • Postorder: Left → Right → Root

📂 Project Structure

BinaryTreeApp.java
├── Node class
├── BinaryTree class
│ ├── insert()
│ ├── bfs()
│ ├── inorder()
│ ├── preorder()
│ └── postorder()
└── NodeQueue class (custom queue)

▶️ How to Run

  1. Clone the repository:
git clone https://github.com/your-username/binary-tree-level-order-java.git

2. Compile:
javac BinaryTreeApp.java

3. Run:
java BinaryTreeApp

🧪 Example Input/Output
Insert nodes:
> 10 20 30 40 50

BFS:
10 20 30 40 50

Inorder:
40 20 50 10 30


📘 Learning Goals

-This project helps you understand:
-How binary trees work internally
-How level-order insertion operates
-How BFS differs from DFS
-How queues enable traversal
-Why custom data structures matter
-Perfect for Data Structure courses, assignments, and interview prep.


📄 License
This project is open-source under the MIT License.


✨ Author
MD Safiul Karim
ID: 2301022
Program: Bachelor of Science Internet of Things & Robotics Engineering
Department of Internet of Things & Robotics Engineering
Session: 2023-24
University of Frontier Technology, Bangladesh
Feel free to use or modify this code for learning or educational purposes.

About

A Java implementation of a plain Binary Tree with level-order insertion, BFS traversal, and DFS traversals (inorder, preorder, postorder). Built without using any inbuilt Java collections. Queue is implemented manually using linked nodes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages