Performance optimization of tree like structure

Performance optimization of tree like structure