Insertion Sort in Python

Introduction If you’re majoring in Computer Science, Insertion Sort is most likely one of the first sorting algorithms you have heard of. It is intuitive and easy to implement, but it’s very slow on large arrays and is almost never used to sort them. Insertion sort is often illustrated by comparing it to sorting a hand of cards while playing rummy. For those of you unfamiliar with the game, most players want the cards in their hand sorted in ascending […]

Read more

Merge Sort in Python

Introduction Merge Sort is one of the most famous sorting algorithms. If you’re studying Computer Science, Merge Sort, alongside Quick Sort is likely the first efficient, general-purpose sorting algorithm you have heard of. It is also a classic example of a divide-and-conquer category of algorithms. Merge Sort The way Merge Sort works is: An initial array is divided into two roughly equal parts. If the array has an odd number of elements, one of those “halves” is by one element […]

Read more

Heap Sort in Python

Introduction Heap Sort is another example of an efficient sorting algorithm. Its main advantage is that it has a great worst-case runtime of O(n*logn) regardless of the input data. As the name suggests, Heap Sort relies heavily on the heap data structure – a common implementation of a Priority Queue. Without a doubt, Heap Sort is one of the simplest sorting algorithms to implement and coupled with the fact that it’s a fairly efficient algorithm compared to other simple implementations, […]

Read more

Selection Sort in Python

Introduction Sorting, although a basic operation, is one of the most important operations a computer should perform. It is a building block in many other algorithms and procedures, such as searching and merging. Knowing different sorting algorithms could help you better understand the ideas behind the different algorithms, as well as help you come up with better algorithms. The Selection Sort algorithm sorts an array by finding the minimum value of the unsorted part and then swapping it with the […]

Read more

Binary Search in Python

Introduction In this article, we’ll be diving into the idea behind and Python implementation of Binary Search. Binary Search is an efficient search algorithm that works on sorted arrays. It’s often used as one of the first examples of algorithms that run in logarithmic time (O(logn)) because of its intuitive behavior, and is a fundamental algorithm in Computer Science. Binary Search – Example Binary Search works on a divide-and-conquer approach and relies on the fact that the array is sorted […]

Read more

Bucket Sort in Python

Introduction In this tutorial, we’ll be diving into the theory and implementation of Bucket Sort in Python. Bucket Sort is a comparison-type algorithm which assigns elements of a list we want to sort in Buckets, or Bins. The contents of these buckets are then sorted, typically with another algorithm. After sorting, the contents of the buckets are appended, forming a sorted collection. Bucket Sort can be thought of as a scatter-order-gather approach towards sorting a list, due to the fact […]

Read more

K-Means Clustering with Scikit-Learn

Introduction K-means clustering is one of the most widely used unsupervised machine learning algorithms that forms clusters of data based on the similarity between data instances. For this particular algorithm to work, the number of clusters has to be defined beforehand. The K in the K-means refers to the number of clusters. The K-means algorithm starts by randomly choosing a centroid value for each cluster. After that the algorithm iteratively performs three steps: (i) Find the Euclidean distance between each […]

Read more

Levenshtein Distance and Text Similarity in Python

Introduction Writing text is a creative process that is based on thoughts and ideas which come to our mind. The way that the text is written reflects our personality and is also very much influenced by the mood we are in, the way we organize our thoughts, the topic itself and by the people we are addressing it to – our readers. In the past it happened that two or more authors had the same idea, wrote it down separately, […]

Read more

Linear Regression in Python with Scikit-Learn

There are two types of supervised machine learning algorithms: Regression and classification. The former predicts continuous value outputs while the latter predicts discrete outputs. For instance, predicting the price of a house in dollars is a regression problem whereas predicting whether a tumor is malignant or benign is a classification problem. In this article we will briefly study what linear regression is and how it can be implemented using the Python Scikit-Learn library, which is one of the most popular […]

Read more

Phonetic Similarity of Words: A Vectorized Approach in Python

In an earlier article I gave you an introduction into phonetic algorithms, and shows their variety. In more detail we had a look at the edit distance, which is also known as the Levenshtein Distance. This algorithm was developed in order to calculate the number of letter substitutions to get from one word to the next. As you may have already noted in the previous article, there are different methods to calculate the sound of a word like Soundex, Metaphone, […]

Read more
1 2 3