Я думаю, что это может произойти с вложенными бинарными поисками , которые O(log n)
.
Вот глупый пример, использующий C #:
public class SuperHeroComparer : IComparer<string>
{
public int Compare(string first, string second)
{
int firstLimboIndex = Limbo.BinarySearch(first);
int secondLimboIndex = Limbo.BinarySearch(second);
if (firstLimboIndex < 0 && secondLimboIndex >= 0) {
return 1;
if (firstLimboIndex >= 0 && secondLimboIndex < 0) {
return -1;
return String.Compare(first, second);
}
}
public static class Continuity
{
public static int IndexOfSuperHero(string name)
{
return SuperHeroes.BinarySearch(name, new SuperHeroComparer());
}
}
Вкод выше, Continuity.IndexOfSuperHero()
будет иметь O(log n)²
сложность.