forest-visualizer is a Python package that provides tools for building and visualizing forest data structures using Turtle Graphics. This package allows users to perform operations like inserting nodes, tree traversal (pre-order, post-order, and level-order), deleting nodes, and drawing the forest structure visually.
This package implements a forest visualization algorithm based on the paper Novel Static Multi-Layer Forest Approach and Its Applications published in MDPI. The paper provides detailed insights into the theoretical foundations of the algorithm.
- Tree Insertion: Insert parent-child relationships to build a forest structure.
- Tree Traversal: Perform pre-order, post-order, and level-order traversals of the forest.
- Node Deletion: Remove nodes and automatically adjust the tree structure.
- Visual Representation: Use Turtle Graphics to draw the forest with customizable node sizes and gaps.
- Path Finding: Find the path from any node to the root.
You can install the forest-visualization package directly from PyPI:
pip install forest-visualization==0.1.3from forest_visualizer import Forest
# Example usage
forest = Forest()
# Inserting nodes
forest.insert('40', 'N/A')
forest.insert('50', '40')
forest.insert('30', '40')
forest.insert('35', '30')
forest.insert('25', '30')
forest.insert('28', '25')
forest.insert('15', '25')
forest.insert('60', '50')
forest.insert('45', '50')
forest.insert('70', '60')
forest.insert('55', '60')
forest.level_traversal()
forest.display()
print(forest.find_parent('25'))
print(forest.find_path_to_root('15'))
#Perform pre-order traversal and print the result
pre_order_result = forest.pre_order_traversal('40')
print("Pre-order traversal result:", pre_order_result)
#Perform pre-order traversal and print the result
post_order_result = forest.post_order_traversal('40')
print("Post-order traversal result:", post_order_result)
forest.draw_tree()
forest.delete_node('25')
forest.draw_tree()
forest.insert('90', '35')
forest.draw_tree()