Answer the question
In order to leave comments, you need to log in
What is the real complexity of this algorithm?
The question is essentially theoretical, but it also has a practical meaning.
I will set it immediately for two languages, and I will give an abstract example.
Let's say we are given a list of adishers:
and an associative array is given:
const ids = List(['id1', 'id2', 'id3']);
const data = Map({
id1: someData,
id2: someData,
...
idN: someData
});
function getNeedData() {
return data.filter((item) => ids.includes(item.get("id")));
}
Answer the question
In order to leave comments, you need to log in
Pretty common mistake. It is treated or by turning the logic around, as you noticed - go through the list of ids and see if there is one in data.
An even better option is to use some kind of set in ids instead of a list. This will work really fast if ids is long and data is short.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question