**I'm junior in computer science major and I've learnt about binary search tree, and when I finished I found there is a lot of trees in computer science, What is the most important trees for competitive programmers?**

# | User | Rating |
---|---|---|

1 | tourist | 3843 |

2 | jiangly | 3705 |

3 | Benq | 3628 |

4 | orzdevinwang | 3571 |

5 | Geothermal | 3569 |

5 | cnnfls_csy | 3569 |

7 | jqdai0815 | 3530 |

8 | ecnerwala | 3499 |

9 | gyh20 | 3447 |

10 | Rebelz | 3409 |

# | User | Contrib. |
---|---|---|

1 | maomao90 | 171 |

2 | awoo | 164 |

3 | adamant | 162 |

4 | TheScrasse | 159 |

5 | nor | 153 |

5 | maroonrk | 153 |

7 | -is-this-fft- | 152 |

8 | Petr | 146 |

9 | orz | 145 |

10 | pajenegod | 144 |

**I'm junior in computer science major and I've learnt about binary search tree, and when I finished I found there is a lot of trees in computer science, What is the most important trees for competitive programmers?**

↑

↓

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/15/2024 21:13:07 (f1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Green trees. they produce oxygen so you can breathe so you can take part in competitive programming.

Please behave reasonably.

No problem! he answered to your question :) just from different perspective :D

segment;fenwick;treap;heap;splay;etc.

Finally someone respectful :)

heaps ftw! i liked the idea a lot when i first learned it as well as segment trees

There are a few important ones in my opinion:

1) Segment trees — those are very important. There's a lot of confusion with the name, so I do not know how to call them exactly, but I do

NOT MEAN THISbut rather what is explained here (I couldn't find a better link, this is not the best explanation/implementation so you might want to refer to the comments of that blog). Basically segment trees allow you to work fast when you have queries on segments of an array. There is lots to learn about it, ranging from lazy propagation technique, to complicated things you must keep in each node in order to merge them successfully.2) Binary search tree — those are obviously great. Map and set are two STL structures (in C++) that can often save you the time of coding BST yourself, but they often don't use the tree's full potential. It often is required to create one yourself. The most famous BST I know of are AVL, Red-Black, Treap and Splay. In almost every case, they are mutually replaceable!

AVL Tree — Most basic binary search tree that uses rotations to balance itself. The complexity is worst-case O(log) per query.

Red-black Tree — This tree is similar to AVL, but it uses colouring of the vertices to achieve better worktime. It uses rotations to balance itself once again and is O(log) in worst-case per query.

Treap — This is actually a very clever binary search tree and my personal favourite. The structure uses randomization of the tree to build it and there are a few techniques to keep it balanced — usually involving randomization. It is theoretical worst-case O(n), but if you use randomization it is O(log) on average, and the worst-case is practically never achieved.

Splay tree — This one is interesting and it has complexity of amortized O(log) per query. I do not use it so I don't know much about it, but in some specific cases it actually performs really well.

3) Heaps — heaps are lovely structures to get min/max and there are actually quite a few of them. Knowing the regular heap is usually enough, but out of curiosity or desire for crazy optimizations, you might want to read about more of them:

Binary heap (regular heap) ; Binomial heap ; (Strict and not) Fibonacci heap ; Pairing heap ; Brodal queue (theoretically optimal, though its author claims it's too complicated for practical use)

And in general wikipedia has a good article on heaps.

This is all I can think of now, those are the tree-structures I use mostly. Each of them has tons of applications and details, and lots of them are mutually replaceable. Some of them like segment trees can be static or dynamic, and most of them have a persistent variation.

Hope that helps :)

Yes, Help me well :)

Thank You.

This is also a nice explanation of Segment Trees.

Suffix trees ( ͡° ͜ʖ ͡°)

wantootree