Why use binary search when you can guess where it should be

Why ignore 50% of what we know about the data1 Everyone learnt binary search in Algo 101. It is the fastest way (among comparison based searches) to find an element in a sorted array. All you need to carry out the algorithms is the comparison between the target element and the element at the current position. It is widely applicable because it assumes so little from the data. But for many real life problems, we do often know something apart from merely the comparison between the two numbers....

Reinventing Catalan numbers

Counting binary trees I was thinking about of the problem of balancing a binary tree, and my mind stumbled across to the question “How many different binary trees with labelled nodes can you make without changing the traversal order?”. After figuring out the answer myself I realized that the numbers of such binary trees are just Catalan numebrs (I was not really into combinatorics - now I am). For example, the following has traversal order 1->2->3->4->5->6->7...

August 10, 2024 · updated December 28, 2024 · 3 min ·  mathematics