2010-11-27 2 views

答えて

1

これは入れ子になったbinary searchesで起こる可能性があります。これは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)²複雑さを持つことになります。

関連する問題