# Pearl No.4 - Kth Smallest in the Union of 2 Sorted Collections

Here is the Pearl No.4: Let A and B be two disjoint ordered collections with distinct elements inside. Their combined size is g…

# Visualise Randomness

It has been almost half year since my last blog post on OCaml. Well, actually I haven't even touched OCaml for that long time. My…

# Permutations

In this post, we will talk about producing permuations using OCaml. Generating permutations was actually one of my first self-hom…

# Pearl No.3 - Saddleback Search

Happy Easter Our easter egg happens to be Pearl 3. A function $f$ can have the following properties: $f$ takes two …

# Binomial Heap

As we described in the previous post, leftist tree is a binary tree based functional heap. It manipulates the tree structure so t…

# Heap - Leftist Tree

Heap is one of most important data structure, where the minimum of all elements can always be easily and efficiently retrieved. …

# Pearl No.2 - The Max Number of Surpassers

In a list of unsorted numbers (not necessarily distinct), such as The surpassers of an element are all elements whose indices…

# Pearl No.1 - The Min Missing Natural Number

Prof. Richard Simpson Bird is a Supernumerary Fellow of Computation at Lincoln College, Oxford, England, and former director of t…

# Recursive Memoize & Untying the Recursive Knot

When I wrote the section of When we need later substitution in Mutable, I struggled. I found out that I didn't fully understand …

# Mutable

While OCaml is a functional programming language and emphasises pure functional style, it allows mutable (variables and values) a…

# Immutable

In pure functional programming, everything is immutable. Strings, lists, values of customised types etc cannot be changed once be…

# Become a BST Ninja - Genin Level

Binary Search Tree (BST) is one of the most classic data structures. The definition for its structure is shown as below: It consi…

One essential of computer programming is repeating some operations. This repetition has two forms: for / while loop and recursion…

# Height, Depth and Level of a Tree

This is a post on the three important properties of trees: height, depth and level, together with edge and path. I bet that most …

# The Magic of Thunk - Async

Currently in post-production. Sorry, I still haven't finished this post. As this will be the last post in the magic of thunk ser…

# The Magic of Thunk - Lazy

The dark side of thunk As discussed previously, thunk is used to encapsulate computations for later uses. Although we may not eva…

# The Magic of Thunk - Stream_list

list The built-in list is a fundamental type in OCaml. We can have a list of numbers such as [1;2;3;4] or functions e.g. [fun x -…

# The Magic of Thunk

A thunk is simply a function with the unit parameter. For example: let f() = 1 + 2 * 3;; Features It is indeed a function and s…