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,

For definition and C++ implementation you may refer to the following post. This post reimplements it in Python. Python code # N = 0 1 2 3 4 5 6 7 # Fibonacci (N) = 0 1 1 2 3 5 8 13 def Fibonacci (N): # Initial case is 0 by definition if N

Problem Given two integers A less than B. Write Python code to find the greatest common divisor between A and B commonly known as GCD. Definition GCD(A, B) is the largest positive integer that divides A and B without a remainder. We can loop starting at 2 ending at A and whenever we find a