Category: Algorithms and Data Structures

Python write list to file

Introduction Saving data structures such as lists to permanent storage for later retrieval is a common practice in computer programming. This technique is commonly referred to as data serialization or marshaling. The goal is to translate data into a format suitable for storage or transmission over network. In today's code snippets article, we are going

Selection sort in Python

Introduction Selection sort is a simple in-place (i.e. no auxiliary memory) comparison based sorting algorithm. It is an inefficient algorithm with O(n2) running time as it uses two nested loops. Here is a summary of steps how the algorithm works: Given an unsorted list Start with the first element on the left side Scan all

Insertion sort in Python

Introduction Insertion sort is a simple in place (i.e no need for an auxiliary memory) sorting algorithm. It is an efficient algorithm for small data sets, specially for lists that are partially sorted. For more information about how sorting works, you may refer to the following article For more in depth information about insertion sort

Merge sort in Python

Problem Implement merge sort algorithm in Python. Solution For definition and explanation, You may refer to the following post. This post is just a rewrite in Python. Before jumping directly to the code, check out the following nice YouTube clip Recursive merge sort in python Take a look at the comments for explanation... # Merge