è¦ç´ ã®æ¿å ¥ãåé¤ãã©ã³ãã ã¢ã¯ã»ã¹ãå ¨é¨é«éãªãªã¹ããä½ã£ã
ã¹ããããªã¹ãï¼Skip Listï¼ã¯1990å¹´ã«çºè¡¨ãããæ¯è¼çæ°ããã¢ã«ã´ãªãºã ã§ãè¦ç´ ã®æ¿å ¥ãåé¤ãæ¤ç´¢ã平衡æ¨ã¨åçã®ããã©ã¼ãã³ã¹ã§å®è¡å¯è½ãªãªã¹ãæ§é ã§ãã
Skip Listã¯é£çµãªã¹ãã®å¤å±¤æ§æã«ãªã£ã¦ãã¾ããè·¯ç·ã«ä¾ããã¨ãæä¸å±¤ã®ãªã³ã¯ã¯åé§ åè»ã®ããã«ãå ¨è¦ç´ ãçµãã§ãã¾ããä¸æ¹ãä¸å±¤ã®ãªã³ã¯ã¯æ¥è¡ãç¹æ¥ã®ããã«ãéä¸ã®è¦ç´ ãã¹ãããããããã«ãªã£ã¦ãã¾ãããã®è·¯ç·ãç¹æ¥âæ¥è¡ââ¦âåé§ ã¨ä¹ãç¶ããã¨ã§ãç®çã®è¦ç´ ã«é«éã«å°éã§ããä»çµã¿ã§ãããã£ã¨è©³ãã解説ã¯こちらãこちらã«ããã¾ãã
ã§ããããããæ¬é¡ã§ããSkip Listã®å®è£ ã¯ããã¤ãåºã¦ãããã§ãããSorted Listã¨ãã¦ã®å®è£ ã°ããã§ãè¦ç´ ãä»»æé åºã§æ ¼ç´ã§ãã¦ã©ã³ãã ã¢ã¯ã»ã¹ï¼indexãæå®ãã¦ã®ã¢ã¯ã»ã¹ï¼å¯è½ãªSkip Listãè¦ã¤ãããªãã£ãã®ã§ãèªåã§ä½ã£ã¦ã¿ã¾ããã
é常ã®Skip Listã§ã¯ãåãã¼ãã¯æ¬¡ã®ãã¼ãã¸ã®ãªã³ã¯ããä¿æãã¦ãã¾ãããããã«å°ã工夫ãå ãã¦ãä¸ã®ç»åã®ããã«ã次ãã¼ãã¾ã§ã®ãè·é¢ããæãããããã«ãã¾ããããã¼ãæ¢ç´¢æã«ãã®è·é¢ãå ç®ãã¦ãããã¨ã§ãindexã«ããè¦ç´ ã®åå¾ãO(logN)ã§å®è¡ã§ãã¾ãã
ãã®SkipListã«å ãã¦ãjava.util.Listã¨java.util.Setã両æ¹å®è£ ããSkipListSetã¨ãããã®ãä½ãã¾ããããã¡ãã¯å é¨çã«HashMapãä½µç¨ãã¦ãã¦ãindexOf()ãcontains()ãé«éã«ãªã£ã¦ãã¾ããåã¡ã½ããã®è¨ç®éæ¯è¼ã¯ä»¥ä¸ã®éãã§ãã
ã¡ã½ãã | ArrayList | SkipList | SkipListSet |
---|---|---|---|
get(index) | O(1) | O(logN) | O(logN) |
set(index, element) | O(1) | O(logN) | O(logN) |
add(element) | O(1) | O(logN) | O(logN) |
add(index, element) | O(N) | O(logN) | O(logN) |
remove(index) | O(N) | O(logN) | O(logN) |
remove(element) | O(N) | O(N) | O(logN) |
indexOf(element) | O(N) | O(N) | O(logN) |
contains(element) | O(N) | O(N) | O(1) |
iterator().next() | O(1) | O(1) | O(1) |
ã½ã¼ã¹ã¯ä»¥ä¸ããã©ããã