C# Binary Trees and Dictionaries

后端 未结 6 1050
悲哀的现实
悲哀的现实 2020-12-14 03:32

I\'m struggling with the concept of when to use binary search trees and when to use dictionaries.

In my application I did a little experiment which used the C5 libra

6条回答
  •  悲&欢浪女
    2020-12-14 03:52

    You're not comparing "apples with apples", a BST will give you an ordered representation while a dictionary allows you to do a lookup on a key value pair (in your case ).

    I wouldn't expect much size in the memory footprint between the 2 but the dictionary will give you a much faster lookup. To find an item in a BST you (potentially) need to traverse the entire tree. But to do a dictnary lookup you simply lookup based on the key.

提交回复
热议问题