Posts

2. Merge sort

 Merge sort Approach Divide      Divide the n-element sequence to be sorted  into two subsequences of n=2 elements each Conquer  Sort the two subsequences recursively using merge sort. Combine Merge the two sorted subsequences to produce the sorted answer. Merge MERGE(A,p,q,r) A - Array p,q and r - indices into array p <= q <= r A[ p .. q ] , A[ q .. r ] -->  A[ p .. r ] (venv) [velmuruganponnusamy@localhost merge-sort]$ cat merge-sort.py  def merge(A,p,q,r):     # pre-requisities in python     # array slicing and index and length function     L1 = A[ p:q ]     L2 = A[ q:r ]     print("Array - {0} ".format(A))     print( "*" * 80 )     # try without this step and identify why are we performing append stats     # depends on the ascending and descending, 999999999 needs to be changed     # if asc -> positive high value   ...

Python virtual env on centos

 [velmuruganponnusamy@localhost Desktop]$ sudo yum install python-pip [sudo] password for velmuruganponnusamy:  Last metadata expiration check: 0:17:38 ago on Mon 21 Nov 2022 02:32:13 PM IST. Dependencies resolved. ====================================================================================================================================================================================================================  Package                                             Architecture                                   Version                                                 Repository                 ...

Centos 9 guest additions installation steps - Virtual box version 7.0.4

Image
 dnf update  dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm  dnf install gcc kernel-devel kernel-headers make bzip2 perl df -h cd /run/media/velmuruganponnusamy/VBox_GAs_7.0.4  ls -tlr ./VBoxLinuxAdditions.run run from Devices > upgrade guest additions Reference https://technixleo.com/install-virtualbox-guest-additions-rhel-centos/ https://www.tonystechanditblog.com/2021/04/virtualbox-guest-additions-centos.html Full Screen View

1. Insertion Sort

Image
  Input A sequence of unordered number ( a1,a2,a3 .... an) Output a1 <= a2 <= a3 <= a4 <= .... <= an We start with insertion sort, which is an efficient algorithm for sorting a small number of elements . Insertion sort works the way many people sort a hand of playing cards. We start with an empty left hand and the cards face down on the table. We then remove one card at a time from the table and insert it into the correct position in the left hand. To find the correct position for a card, we compare it with each of the cards already in the hand, from right to left Insertion Sort Works Pseudocode INSERTION-SORT(A) 1 for j = 2 to A.length 2 key = A[j] 3 // Insert A[j] into the sorted sequence A[1 .. j - 1 ]. 4 i = j - 1 5 while i > 0 and A[i] > key 6 A[i + 1] = A[i] 7 i = i - 1 8 A[i + 1] =  key Explanation iterates the elements from the 2nd position. compare the elements from right to left and swap them. each loop, we will have th...