Posts

Showing posts from July, 2020

Huffman coding algoritnm

Huffman coding algorithm:- Huffman coding .  Huffman  Algorithm was developed by David  Huffman  in 1951. This is a technique which is used in a data compression or it can be said that it is a  coding  technique which is used for  encoding  data. Huffman  is widely  used  in all the mainstream compression formats that you might encounter - from GZIP, PKZIP (winzip etc) and BZIP2, to image formats such as JPEG and PNG. algorithm:-      Huffman(c)      {          n = |c|   //where mod of c is set of character          make a min heap 'Q' with c       [O(n)]          for i in range n-1          // allocated a new node z           z.left = x = extract - min(Q)          z.rigth=y= extract - min(Q)         ...

Insertion sort using java

What is insertion sort in data structure? Insertion Sort  Algorithm.  Insertion sort  is the  sorting  mechanism where the  sorted  array is built having one item at a time. The array elements are compared with each other sequentially and then arranged simultaneously in some particular order.   Algorithm   Now we have a bigger picture of how this sorting technique works, so we can derive simple    steps by which we can achieve insertion sort. Step 1 − If it is the first element, it is already sorted. return 1; Step 2 − Pick next element Step 3 − Compare with all elements in the sorted sub-list Step 4 − Shift all the elements in the sorted sub-list that is greater than the value to be sorted Step 5 − Insert the value Step 6 − Repeat until list is sorted    Let's see a  simple java program  to  sort  an array using  insertion sort  algorithm.    import java.util.*; ...