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… Thanks for
This post is a rewrite of the following article but in Python Python code If you run the code snippet above, you should get the following output Please leave a comment if you have questions or corrections. Thanks
Refer to the following post for more details. This post is only Python implementation Python code Thanks for reading, for questions or feedback please use the comments section below.
For definition and explanation please refer to the following post. This post is only implementation in Python. Python code If you run the code snippet above you should get 6. Thanks for reading. Please use the comments section below for questions.
For definition and C++ implementation you may refer to the following post. This post reimplements it in Python. Python code If you run the code snippet above you should get the output below If you have comments ? questions ? pease use the comments section below. Thanks for reading.
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
Question Write a recursive function in Python to reverse a string of characters. Solution The reverse of a string is the concatenation of the first character and the reverse of the remaining characters in the string. Recall that the first character is put on the right side when doing the concatenation. Code The following is