0% found this document useful (0 votes)
17 views

Algorithm

The document describes three algorithms: Merge Sort, Insertion Sort, and Huffman Coding. Merge Sort works by recursively splitting an array in half and merging the sorted halves. Insertion Sort iterates through an array, inserting each element into the sorted portion. Huffman Coding creates a binary tree from frequencies by repeatedly combining the two least frequent nodes until a single tree remains.

Uploaded by

md.ujjal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Algorithm

The document describes three algorithms: Merge Sort, Insertion Sort, and Huffman Coding. Merge Sort works by recursively splitting an array in half and merging the sorted halves. Insertion Sort iterates through an array, inserting each element into the sorted portion. Huffman Coding creates a binary tree from frequencies by repeatedly combining the two least frequent nodes until a single tree remains.

Uploaded by

md.ujjal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

 𝑨𝒍𝒈𝒐𝒓𝒊𝒕𝒉𝒎: 𝑴𝒆𝒓𝒈𝒆 𝑺𝒐𝒓𝒕

MERGEA_SORT(array,p,r)
1. if p<r
2. q=floor((p+r/2))
3. MERGEA_SORT(array,p,q)
4. MERGEA_SORT(array,q+1,r)
5. MERGE(array,p,q,r)
MERGE (array, p, q, r)

1. n1 = q - p + 1

2. n2 = r - q
3. let L[1..n1 + 1] and R[1..n2 + 1] be new arrays

4. for i = 1 to n1
5. L[i] = array[p + i - 1]
6. for j = 1 to n2
7. R[j] = array[q + j]
8. L[n1 + 1] = Infinity
9. R[n2 + 1] = Infinity
10. i = 1
11. j = 1
12. for k = p to r
13. if L[i] <= R[j]
14. array[k] = L[i]
15. i = i + 1
16. else
17. array[k] = R[j]
18. j = j + 1
 𝑨𝒍𝒈𝒐𝒓𝒊𝒕𝒉𝒎: 𝑰𝒏𝒔𝒆𝒓𝒕𝒊𝒐𝒏 𝑺𝒐𝒓𝒕

INSERTION_SORT(array)

1. For j=2 to array.length


2. Key=array[j]
3. Insert array[j] into the sorted sequence array[1..j-1]
4. I=j-1
5. While i>0 and array[i]>key
6. Array[i+1]=array[i]
7. i=i-1
8. array[i+1]=key

 𝑨𝒍𝒈𝒐𝒓𝒊𝒕𝒉𝒎: 𝑯𝒖𝒇𝒇𝒎𝒂𝒏 𝑪𝒐𝒅𝒊𝒏𝒈

HUFFMAN (C)

1. n = |C|
2. Q = C
3. for i = 1 to n – 1
4. allocate a new node z
5. z.left = x = EXTRACT_MIN (Q)
6. z.right= y = EXTRACT_MIN (Q)
7. z. freq = x.freq + y.freq
8. INSERT (Q, Z)
9. return EXTRACT_MIN (Q)

You might also like