What is lft & rgt in account doctype?

I came across these 2 fields in account doctype. What are they actually used for?

Those fields are required to generate tree view for a doctype

These fields are used for creating a tree structure for the account doctype.

@revant_one @ManasSolanki . I noticed that this field is also being used to order accounts in reports? I am trying to have the direct expense display above indirect expense in P&L . Where do i tinker around exactly to achieve this?

Reviving this topic.

@revant_one are the fields lft and rgt used only for tree view purposes, is it possible to safely restrict the scope of lft and rgt fields to one single company?

As explained by @vigneshsekar here [Requesting Help] Optimised approach to create Chart of Accounts,
our use case requires us to store data related to multiple independent companies, each with its own Chart of accounts. While we programmatically create the COA for one company, we observe that the lft and rgt for other companies’ accounts are also updated, slowing down the performance. To avoid this, we would like the COA for each company to have its own range of lft and rgt.

Any help or suggestions in this regard will be much appreciated.