common algorithm's implementation in python