## Prefix Function Π for KMP (Knuth Morris Pratt) Algorithm in Python

The prefix function Π for a pattern gives an idea about how the pattern matches against shifts of itself. This information can help in avoiding some useless shifts that are performed in the naive algorithm for string matching. It (Π[k]) is defined as the length …

## Haskell code for Set Difference

It’s required not to use the built-in set functions to calculate the difference between the given sets. In this scenario, we need to compare the elements of the sets to find the difference. To figure out if an element of a set is present in …

## Haskell – Finding Power Set of a Set without using set functions

There are several built-in set functions that might help in finding the power set of a given set. But if the use of those build-in sets functions is prohibited as per the requirement, it can be implemented differently. The following code shows one of such …

## Haskell code to calculate the sum of squares of positive integers

Suppose it’s required to calculate the sum of squares of the positive numbers 1,2…n. In Haskell, it can be done using fold function or map function very easily. The code will be just a couple of lines long.

## Remove consecutive duplicates from a list in Haskell

Suppose a given list of integers has some consecutive duplicate entries and it is required to remove those duplicates and to keep just one entry of that integer. This can be done in Haskell programming language using foldr or foldl functions. It can also be done …