Pergunta de entrevista da empresa Leidos

What is the performance difference between searches in a list and a set and what causes the performance difference?

Resposta da entrevista

Sigiloso

12 de mai. de 2018

In at least C++, a list search is O(n) and a set search is either O(log(n)) or O(1) depending on the specific type of set. The linear search of a list is due to the fact that lists are implemented as linked lists. The set search complexity is logarithmic if you're using a set implemented with some form of binary tree or constant if you're using an unordered_set which utilizes hash tables.

2