Although, ZigBee [21] provided a table-free Tree routing algorithm together with an addressing scheme for resource constrained IEEE 802.15.4 [15] devices, it is applicable for symmetric limited-sized tree networks only [6, 7, 8, 9]. This paper has presented an efficient routing algorithm and a flexible, variable-length addressing scheme based on prefix code. The scheme eliminates routing tables and does not limit network size and also allows devices to have arbitrary number of children. It leverages simple mathematical and/or logical equations to take routing decisions and can be applied for almost all types of tree networks. Analytical and simulation results show that this flexible mechanism incurs very low overhead.