Balanced-tree-based maps are a workhorse in functional programming. Because of their disarming simplicity, Chris Okasaki's purely functional red-black trees are a popular means for implementing such maps. In his book, self-balancing binary search trees are less than a page of code. Except that delete is left as an exercise to the reader. Unfortunately, deletion is tricky. Stefan Kahrs devised a wi
We show that the idea of left-leaning reduces one pattern matching in the insertion operation of Okasaki's purely functional red-black trees. We proved in Coq that the invariants of left-leaning red-black trees stand for our purely functional algorithm of the insertion operation. Our benchmark shows that our algorithm is slightly faster than Okasaki's algorithm in some cases. History In 1979, Guib
ãµã¼ãã¹çµäºã®ãç¥ãã ãã¤ãYahoo! JAPANã®ãµã¼ãã¹ããå©ç¨ããã ãèª ã«ãããã¨ããããã¾ãã ã客æ§ãã¢ã¯ã»ã¹ããããµã¼ãã¹ã¯æ¬æ¥ã¾ã§ã«ãµã¼ãã¹ãçµäºãããã¾ããã ä»å¾ã¨ãYahoo! JAPANã®ãµã¼ãã¹ããæ顧ãã ããã¾ãããããããããé¡ããããã¾ãã
ãã®ãã¼ã¸ã¯ããããã¨å¼ã°ãããã¼ã¿æ§é ã®å®è£ ã®ï¼ã¤ã§ãã赤é»æ¨ (ï¼è²æ¨ãred-black tree)ã«ã¤ãã¦è§£èª¬ãããã¼ã¸ã§ãã赤é»æ¨ã¯ãè¦ç´ ã® æ¿å ¥ã»åé¤ã»æ¤ç´¢ãªã©ã®æä½ã \(O(\log n)\) ã®è¨ç®éã§å®è¡åºæ¥ãå¹³è¡¡æ¨ ã§ã(\(n\) ã¯è¦ç´ æ°)ã赤é»æ¨ã¯ãã£ã¦ãããã¨ã¯åç´ãªã®ã§ãããã¨ã«ãã å ´ååãããããããã£ã¦ãç¿å¾ãããã¨ããªããããããã¦ãã¾ã£ã人ã å¤ãã®ã§ã¯ãªãã§ããããï¼ ãããããå®å¿ãã ããããã®ãã¼ã¸ã¯å ´ååããåºæ¥ãã ãæ¸ããã æ¿å ¥æä½ã§ï¼ãã¿ã¼ã³ãåé¤æä½ã§ï¼ãã¿ã¼ã³ããç解ããã°èµ¤é»æ¨ãåãã ããã«æ¸ããã¦ãã¾ããåé¤æä½ã«é¢ãã¦ã¯ãå·¦å³å¯¾ç§°ã®ãã¿ã¼ã³ãçãã° ï¼ãã¿ã¼ã³ç解ããã°ãããã OK ã§ãããããã赤é»æ¨ãåå¼·ãããã¨ãã人 ã¯ãã¡ãããä¸åº¦ã¯åå¼·ãããæ«æãã¦ãã¾ã£ãã¨ãã人ãæ¯éã¨ãèªãã§ã¿ã¦ ãã ããã ãæºåã ã¾
Haskellã§ã®èµ¤é»æ¨ã®å®è£ ã®ç¾ããã«æåãã data Color = R | B data RedBlackSet a = E | T Color (RedBlackSet a) a (RedBlackSet a) balance B (T R (T R a x b) y c) z d = T R (T B a x b) y (T B c z d) balance B (T R a x (T R b y c)) z d = T R (T B a x b) y (T B c z d) balance B a x (T R (T R b y c) z d) = T R (T B a x b) y (T B c z d) balance B a x (T R b y (T R c z d)) = T R (T B a x b) y (T B c z d) balance color a x
éçºãæçãã¦ããã®ã§ããããã§æä½ã®ãã¿ã¼ã³ãããã©ã¤ãã©ãªãoptimaãæ¥æ¬èªã§è§£èª¬ãããã¨æãããã ã解説ã¨ã¯è¨ã£ã¦ãã詳細ãªä»æ§ãã ãã ãã¨è§£èª¬ãããããªãã¨ã¯ããªãããããããªããã¿ã¼ã³ããããªã®ãããè¸ã¾ããä¸ã§ãç°¡åãªå ¥éã¨ä½¿ç¨ä¾ã示ããã¨ã§ããã¿ã¼ã³ãããã®éè¦æ§ãèªèãã¦ãããã®ãçãã ããªãã詳細ãªä»æ§ã«ã¤ãã¦ã¯ããã¥ã¢ã«ãåç §ããããã ãªããã¿ã¼ã³ããããªã®ã Common Lispã«ã¯ãã¿ã¼ã³ãããã©ã¤ãã©ãªãå¤æ°åå¨ãããããã®å¤§åã¯åã«ãã¿ã¼ã³ãããã便å©ã ããã¨ããè¦ç¹ããæã£ã¦ããªãããããã«ãã¿ã¼ã³ãããã¯ä¾¿å©ã§ãããã便å©ãªã ãã§ã¯äººã ã¯ããã使ããã¨ã¯ããªããããæ¬è³ªçãªè¦ç¹ãä¸ããå¿ è¦ãããã ããã OCamlãHaskellãªã©ã®é¢æ°åè¨èªã§ã¯ããããããã¼ã¿ã¯ã代æ°çãã¼ã¿åã¨ãã¦å®ç¾©ãããããã«ã¨ããªããã¼ã¿ã³ã³ã¹ãã©ã¯ã¿ã«ãã£ã¦æ§æããã
Left-Leaning Red-Black Trees Considered Harmful Eddie Kohler Robert Sedgewickâs left-leaning red-black trees are supposedly simpler to implement than normal red-black trees: In this paper, we describe a new variant of red-black trees that meets many of the original design goals and leads to substantially simpler code for insert/delete, less than one-fourth as much code as in implementations in com
Balanced Trees, Part 4: Left Leaning Red-Black Trees Overview While searching around for info about balanced trees, I found some new papers by Robert Sedgewick, describing an algorithm called Left Leaning Red-Black (LLRB) trees. Since Sedgewick (along with Guibas back in 1978) helped come up with the abstraction for red-black trees, I assumed this would be a good algorithm to test. However... Ther
ãç¥ãã
é害
ã©ã³ãã³ã°
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}