Which is faster to find an item in a hashtable or in a sorted list?

后端 未结 7 2101
栀梦
栀梦 2020-12-24 06:41

Which is faster to find an item in a hashtable or in a sorted list?

7条回答
  •  猫巷女王i
    2020-12-24 07:38

    Assuming that by 'sorted list' you mean 'random-accessible, sorted collection'. A list has the property that you can only traverse it element by element, which will result in a O(N) complexity.

    The fastest way to find an element in a sorted indexable collection is by N-ary search, O(logN), while a hashtable without collissions has a find complexity of O(1).

提交回复
热议问题