Trifusion and Implementation Python in less than 128 words

Tri fusion follows the divide paradigm to rule that consists of dividing the initial task into two similar smaller tasks.

The algorithm is as follows:
We divide the list to be sorted into two halves.
We sort every one of them.
The two halves obtained are merged to reconstruct the sorted list.

This algorithm is applied recursively, i.e. until the list to be sorted is made up of a single item.

Tri fusion (source: wikipedia)
#Tri merger function of division of the table
def tri_fusion (table):
    if len (table)<= 1:></= 1:> 
        return table
    pivot - len (table)//2
    Table1 - Table 1[:pivot]
    Table2 - Table2[pivot:]
    left - tri_fusion (table1)
    right - tri_fusion (table2)
    fusion - fusion (left, right)
    return fusion


#Tri fusion function of 2 lists
def fusion (table1, table2):
    indice_tableau1 0
    indice_tableau2 0    
    taille_tableau1 - len (table1)
    taille_tableau2 - len (table2)
    tableau_fusionne[]
    while indice_tableau1<taille_tableau1 and=""></taille_tableau1><taille_tableau2:></taille_tableau2:>
        If table1< table[indice_tableau1]au2:></ tableau2[indice_tableau2]:>
            tableau_fusionne.append (table1[indice_tableau1])
            indice_tableau1 1
        else
            tableau_fusionne.append (table2[indice_tableau2])
            indice_tableau2 1
    while indice_tableau1<taille_tableau1:></taille_tableau1:>
        tableau_fusionne.append (table1)
        indice_tableau1
    while indice_tableau2<taille_tableau2:></taille_tableau2:>
        tableau_fusionne.append (table2)
        indice_tableau2
    return tableau_fusionne

Table[11, 222, 3, 899, 24, 5, 46, 67]
print (table)
tableau_trie - tri_fusion (table)
print (tableau_trie)

One thought on “Trifusion and Implementation Python in less than 128 words”

Comments are closed.