Algorithm [2] - Huffman coding & Tower of Hanoi

 

1, Tower of Hanoi problem

  Tower of Hanoi: Tower of Hanoi (also known as the Tower of Hanoi) problem stems from an ancient Indian legend of educational toys. When Brahma created the world to do three diamond pillars, from the bottom up pile with 64 gold discs in order of size to a post. Brahma Brahman command to the disk in order of size from the bottom again placed on the other pillars. And predetermined, the disc can not be enlarged in a small disk, a disk can only be moved between the three pillars.

Package com.cnblogs.mufasa; 

public  class Answer1_Hanoi {
     public  static  int Solution1 ( int I) { // recursive call 
        IF (I ==. 1 ) {
             return . 1 ; 
        } the else  IF (I == 2 ) {
             return . 3 ; 
        } the else {
             return 2 * Solution1 (. 1-I) + 1'd ; 
        } 
    } 

    public  static  int Solution2 ( int I) { // direct Numerical Mathematics
        return (int) Math.pow(2,i)-1;
    }

    public static void Solution3(int i, String loc1, String loc2, String loc3) {//递归调用
        if (i == 1) {
            System.out.println("from " + loc1 + " to " + loc3);
            return;
        }
        Solution3(i - 1, loc1, loc3, loc2);//角色反转
        Solution3( 1, loc1, loc2, loc3);
        Solution3( i-1, loc2, loc1, loc3);
    }
}

 

2, save communication bandwidth Huffman coding []

  Huffman coding (Huffman Coding), also known as Huffman coding is a coding method, Huffman coding is a variable word length coding (VLC) a. Huffman proposed in 1952, an encoding method based solely on characters appear different probabilities to construct the average length of the shortest prefix code word, sometimes referred to as the best encoding, usually called Huffman coding (also sometimes referred to as Hough Manchester encoding).

 

Guess you like

Origin www.cnblogs.com/Mufasa/p/11429643.html