Most efficient way of creating tree from adjacency list

后端 未结 2 1703
说谎
说谎 2020-12-28 23:49

I have an adjacency list of objects (rows loaded from SQL database with the key and it\'s parent key) that I need to use to build an unordered tree. It\'s guaranteed to not

2条回答
  •  被撕碎了的回忆
    2020-12-29 00:14

    SortedList is not a good container to use in this context. It is O(n) for insertion operations (the repeated calls to Add()), as it is internally represented as a flat list. Using Dictionary instead of SortedList will be a large improvement, as it is O(1) amortized insertion time.

提交回复
热议问题