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

Introduction Copying data structures such as lists is a frequently performed task in computer programming. For instance, one of the most efficient sorting algorithms is merge sort. Merge sort uses divide and conquer approach to split the unsorted list into two sections in a recursive fashion. To do so, merge sort uses list copying technique.

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

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

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

This post is a rewrite of the following article but in Python Python code def IterativeBinarySearch(A, key, l, r): # As long as left index is less than right index while l A[m]: # Update the left index l = m + 1 # We found the key else: return m # Key was not

Problem Write a Python recursive function to compute the product of two positive integers. Solution The product of two positive integers (A*B) is nothing but the sum of the first integer (A), (B) times Code Here is the code in Python //Includes def RecursiveProduct(a, b): # Base case 1 if a == 0 or b

Fore more information please refer to the following post. This post only implements the solution in Python Code def RecursiveAvg(A, i, n): # Base case if i == n-1: return A[i]/n return A[i]/n + RecursiveAvg(A, i + 1, n) A = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0] print "Average of A

Refer to the following post for more details. This post is only Python implementation Python code # Integer division calculator def Division(numerator, denominator): # Divide by zero special case if denominator == 0: return [-999, -999] # Both are equal special case if numerator == denominator: return [1, 0] quotient = 0 # Get the

For definition and explanation please refer to the following post. This post is only implementation in Python. Python code # Function recieves the input array A def MCSS (A): # Auxiliary array B = # MCSS ending at position 0 is just the first element B.append(A[0]) # Populate B for i in range (1,