Two elements of a binary search tree (BST) are swapped by mistake.
Using a binary search tree or dividing the string into segments as long as the square root of the length of the string will solve the problem.
It maintains the free space in heap as nodes in a Cartesian binary search tree format.
Red-black tree is a self-balancing binary search tree.