Saturday, November 24, 2012

Very Simple My Own Shell in C

Do you want to publish source codes in your blog or web site as follows.
Visit Source Code Formatter
 #include<stdio.h>  
 #include<stdlib.h>  
 #include<string.h>  
 int main(){  
       char buf[256]={0};  
       printf("\n\n\n");  
       while(1){  
            printf("\nMOSH : ");  
            if (fgets(buf, sizeof(buf), stdin) == NULL){  
                fprintf(stderr, "Invalid input command!\n");  
                exit(-1);  
              }  
              buf[strlen(buf)-1]='\0';  
            system(buf);  
       }       
       return 0;  
 }  

Saturday, November 10, 2012

Maximum matching in bipartite graph using Hopcroft Karp algorithm in C ++

Do you want to publish source codes in your blog or web site as follows.
Visit Source Code Formatter
 /*******************************************************/  
 /*       2nd Takehome Assignment         */  
 /*Instructions :                    */  
 /*   Data should be input to the program using text */  
 /*     file (EX: test.txt)            */  
 /*   INPUT FORMAT:                 */  
 /*     4 5 5                   */  
 /*     1 8                    */  
 /*     1 5                    */  
 /*     2 6                    */  
 /*     3 9                    */  
 /*     4 7                    */  
 /*   first three integers (n,m and e)        */  
 /*     n: number of left hand nodes        */  
 /*     m: number of right hand node        */  
 /*     e: number of incedent edges        */  
 /*    next integer(g[u][v])            */  
 /*      g[u][v]: adjecent verteces        */  
 /*******************************************************/  
 #include <iostream>  
 #include <vector>  
 #include <stdio.h>  
 #include <stdlib.h>  
 #include <string.h>  
 #include <queue>  
 #include <fstream>  
 using namespace std;  
 #define MAX 10000 //maximum allowed couples  
 #define NIL 0  
 #define INF (1<<28) //infinity  
 vector<int> G[MAX]; // G[0]= NIL u G1[G[1---n]] u G2[G[n+1---n+m]]  
 int n,m,e,match[MAX],dist[MAX];  
 //Breadth first search  
 bool bfs() {  
   int i, u, v, len;  
   queue<int> Q;  //an integer queue  
   for(i=1; i<=n; i++) {  
     if(match[i]==NIL) { //i is not matched  
       dist[i] = 0;  
       Q.push(i);  
     }  
     else dist[i] = INF;  
   }  
   dist[NIL] = INF;  
   while(!Q.empty()) {  
     u = Q.front();  
     Q.pop();  
     if(u!=NIL) {  
       len = G[u].size();  
       for(i=0; i<len; i++) {  
         v = G[u][i];  
         if(dist[match[v]]==INF) {  
           dist[match[v]] = dist[u] + 1;  
           Q.push(match[v]);  
         }  
       }  
     }  
   }  
   return (dist[NIL]!=INF);  
 }  
 //depth first search  
 bool dfs(int u) {  
   int i, v, len;  
   if(u!=NIL) {  
     len = G[u].size();  
     for(i=0; i<len; i++) {  
       v = G[u][i];  
       if(dist[match[v]]==dist[u]+1) {  
         if(dfs(match[v])) {  
           match[v] = u;  
           match[u] = v;  
           return true;  
         }  
       }  
     }  
     dist[u] = INF;  
     return false;  
   }  
   return true;  
 }  
 int hopcroft_karp() {  
   int matching = 0, i;  
   // match[] is assumed NIL for all vertex in G  
   while(bfs())  
     for(i=1; i<=n; i++)  
       if(match[i]==NIL && dfs(i))  
         matching++;  
   return matching;  
 }  
 //read data file in to an array  
 int openDataFile(char *filename){  
   int A, B;  
   ifstream infile(filename);  
   if (!infile) { //fill not found  
     printf("There was a problem opening file %s for reading.\n",filename);  
     return 0;  
   }  
   printf("Opened %s for reading.\n", filename); //file opened  
   infile >> n >> m >>e; // for perfect matching n=m  
   while (infile >> A >> B) { //read adjecent verteces  
     G[A].push_back(B);  
   }  
 }  
 //main method starts here  
 int main() {  
   printf("\n*******************************\n\tFind Stable Cuples\n*******************************\n");  
   char filename[256] = {0};  
   int NumOfMatches,i;  
   printf("Enter data file name : ");  
   scanf("%s",&filename);  
   openDataFile(filename);  
   while(1){  
     int choice;  
     printf("\n*******************************\n\tFind Stable Cuples\n*******************************\n");  
     printf("Enter 1 : Find Optimal Solution\n");  
     printf("Enter 2 : Add New Data File\n");  
     printf("Enter 0 : Exit\n");  
     printf("\nEnter :");  
     scanf("%d",&choice);  
     if(choice==1){  
       openDataFile(filename);  
       NumOfMatches=hopcroft_karp(); //find matching perfect matching couples  
       printf("Number of couples matched : %d\n",NumOfMatches);  
       for(i=1;i<=n;i++){  
         printf("%d matched with %d\n",i,match[i]);  
       }  
     }else if(choice==2){  
       printf("Enter data file name : ");  
       scanf("%s",&filename);  
     }  
     else if(choice==0){  
       printf("Program Terminated\n");  
       exit(0);  
     }  
     else{  
       printf("Error : Wrong Input\n");  
     }  
   }  
   return 0;  
 }  

Maximum matching in bipartite graph using Ford Fulkerson algorithm in C

Do you want to publish source codes in your blog or web site as follows.
Visit Source Code Formatter
 /*******************************************************/  
 /*       2nd Takehome Assignment         */  
 /*    Maximum matching marriage couples using   */  
 /*      Ford Fulkerson Algorithm         */  
 /*Instructions :                    */  
 /*   Data should be input to the program using text */  
 /*     file (EX: test.txt)            */  
 /*   INPUT FORMAT:                 */  
 /*     10 10                   */  
 /*     1 6                    */  
 /*     1 7                    */  
 /*     2 7                    */  
 /*     3 6                    */  
 /*     3 8                    */  
 /*     3 10                    */  
 /*     4 7                    */  
 /*     4 10                    */  
 /*     5 7                    */  
 /*     5 9                    */  
 /*   first two integers (n and e)          */  
 /*     n: number of nodes in the graph      */  
 /*     e: number of incedent edges        */  
 /*    next integer(u,v)              */  
 /*      g[u][v]: adjecent verteces        */  
 /*******************************************************/  
 #include <stdio.h>  
 #include <stdlib.h>  
 // Basic Definitions  
 #define WHITE 0   //nodes status  
 #define GRAY 1  
 #define BLACK 2  
 #define MAX_NODES 1000   //maximum allowed nodes  
 #define INFINITY 1000000000  
 // variable Declarations  
 int n; // number of nodes  
 int e; // number of edges  
 int capacity[MAX_NODES][MAX_NODES]; // capacity matrix  
 int flow[MAX_NODES][MAX_NODES];   // flow matrix  
 int color[MAX_NODES]; // store node status  
 int parent[MAX_NODES]; // array to store augmenting path  
 int min (int x, int y) {  
   return x<y ? x : y; // returns minimum of x and y  
 }  
 // A Queue for Breadth-First Search  
 int head,tail;  
 int q[MAX_NODES+2];  
 void enqueue (int x) { //add to queue  
   q[tail] = x;  
   tail++;  
   color[x] = GRAY;  
 }  
 int dequeue () {    //remove from queue  
   int x = q[head];  
   head++;  
   color[x] = BLACK;  
   return x;  
 }  
 // Breadth-First Search for an augmenting path  
 int bfs (int start, int target) {  
   int u,v;  
   for (u=0; u<n+2; u++) { //initialize node status  
     color[u] = WHITE;  
   }  
   head = tail = 0;  
   enqueue(start);  
   parent[start] = -1;  
   while (head!=tail) {  
     u = dequeue();  
     // Search all adjacent white nodes v. If the capacity  
     // from u to v in the residual network is positive,  
     // enqueue v.  
     for (v=0; v<n+2; v++) {  
       if (color[v]==WHITE && capacity[u][v]-flow[u][v]>0) {  
         enqueue(v);  
         parent[v] = u;  
       }  
     }  
   }  
   // If the color of the target node is black now,  
   // it means that we reached it.  
   //printf("%d\n",color[target]);  
   return color[target]==BLACK;  
 }  
 // Ford-Fulkerson Algorithm  
 int max_flow (int source, int sink) {  
   int i,j,u;  
   // Initialize empty flow.  
   int max_flow = 0;  
   for (i=0; i<n+2; i++) {  
     for (j=0; j<n+2; j++) {  
       flow[i][j] = 0;  
     }  
   }  
   // While there exists an augmenting path,  
   // increment the flow along this path.  
   printf("\nAugmented Path :\n");  
   while (bfs(source,sink)) {  
     // Determine the amount by which we can increment the flow.  
     int increment = INFINITY;  
     for (u=sink; parent[u]!=(-1); u=parent[u]) {  
       increment = min(increment,capacity[parent[u]][u]-flow[parent[u]][u]);  
     }  
     //printf("\n%d\n",increment);  
     // Now increment the flow.  
     for (u=sink; parent[u]!=(-1); u=parent[u]) {  
       flow[parent[u]][u] += increment;  
       flow[u][parent[u]] -= increment; // Reverse in residual  
     }  
     printf("\t");  
     // Path trace  
     for (u=sink; parent[u]!=(-1); u=parent[u]) {  
       printf("%d<-",u);  
     }  
     printf("%d adds %d incremental flow\n",source,increment);  
     max_flow += increment;  
     //printf("\n\n%d %d\n\n",source,sink);  
   }  
   //printf("%d\n",s);  
   // No augmenting path anymore. We are done.  
   return max_flow;  
 }  
 // Reading the input file and the main program  
 int read_input_file() {  
   int a,b,i,j;  
   char filename[256] = {0};  
   printf("Enter data file name : ");  
   scanf("%s",&filename);  
   FILE* input = fopen(filename,"r");  
   if(!input){  
     printf("There was a problem opening file %s for reading.\n",filename);  
     return 0;  
   }  
   // read number of nodes and edges  
   fscanf(input,"%d %d",&n,&e);  
   // initialize empty capacity matrix  
   for (i=0; i<n+2; i++) {  
     for (j=0; j<n+2; j++) {  
       capacity[i][j] = 0;  
     }  
   }  
   // read edge capacities  
   for (i=0; i<e; i++) {  
     fscanf(input,"%d %d",&a,&b);  
     if(a==b){  
       printf("ERROR : Graph is not bipartite");  
       return 0;  
     }  
     capacity[a][b]= 1; // Could have parallel edges  
   }  
   fclose(input);  
   for(i=0;i<n/2;i++){  
     capacity[0][i+1]= 1;  
     capacity[i+6][n+1]= 1;  
   }  
   return 1;  
 }  
 //Extra works  
 /*void read_input_file_w() {  
   int a,b,c,i,j;  
   FILE* input = fopen(filename,"a+");  
   // read number of nodes and edges  
   fscanf(input,"%d %d",&n,&e);  
   // initialize empty capacity matrix  
   for (i=0; i<n+2; i++) {  
     for (j=0; j<n+2; j++) {  
       capacity[i][j] = 0;  
     }  
   }  
   // read edge capacities  
   for (i=0; i<e; i++) {  
     fscanf(input,"%d %d",&a,&b);  
     capacity[b][a]= 1; // Could have parallel edges  
   }  
   fclose(input);  
   for(i=0;i<n/2;i++){  
     capacity[0][i+6]= 1;  
     capacity[i+1][n+1]= 1;  
   }  
 }  
 void printMatrix(){  
   int i,j;  
   for (i=0; i<=n+1; i++) {  
     for (j=0; j<=n+1; j++) {  
       printf("%d ",capacity[i][j]);  
     }  
     printf("\n");  
   }  
 }*/  
 int start(){  
   int isBipartite=0;  
   while(!isBipartite){  
     printf("\n*******************************\n\tFind Stable Cuples\n*******************************\n");  
     isBipartite=read_input_file();  
     //printMatrix();  
   }  
   return isBipartite;  
 }  
 int main () {  
   int i,j;  
   int isBipartite=0;  
   isBipartite=start();  
   while(isBipartite){  
     int choice;  
     printf("\n*******************************\n\tFind Stable Cuples\n*******************************\n");  
     printf("Enter 1 : Find Optimal Solution\n");  
     printf("Enter 2 : Add New Data File\n");  
     printf("Enter 0 : Exit\n");  
     printf("\nEnter :");  
     scanf("%d",&choice);  
     if(choice==1){  
       printf("\ntotal flow is %d\n",max_flow(0,n+1));  
       printf("\nMatched couples:\n");  
       for (i=1; i<=n; i++)  
           //printf("%d ",parent[i]);  
         for (j=1; j<=n; j++)  
           if (flow[i][j]>0)  
             printf("\tMen:%d matched with Women:%d\n",i,j);  
     }else if(choice==2){  
       isBipartite=start();  
       //printMatrix();  
     }  
     else if(choice==0){  
       printf("Program Terminated\n");  
       exit(0);  
     }  
     else{  
       printf("Error : Wrong Input\n");  
     }  
   }  
   return 0;  
 }  

Sunday, October 21, 2012

Rabin Carp String Matching Algorithm

     Rabin Carp Algorithm is also one of the string matching algorithm. This algorithm is also an improved version of Naive or Brute Force String Matching Algorithm. Because this algorithm is the a very basic sub-string matching algorithm, but it’s good for some reasons. For example it doesn’t require preprocessing of the text or the pattern. The problem is that it’s very slow. That is why in many cases brute force matching can’t be very useful.
     Michael O. Rabin and Richard M. Karp came up with the idea of hashing the pattern and to check it against a hashed sub-string from the text in 1987.Rabin Carp algorithm is one of the better string matching algorithm than Brute Force algorithm. This algorithm avoid comparison of every character of pattern with characters of text in each position. To do that this algorithm uses hashing. Hashing is the process of converting our data in to numerical value. To convert data in to numerical value we should have assign a numerical value for each text in the alphabet and using any hashing functions we can calculate hash value of any pattern. 
As an example if our pattern P=AABCB and we get ascii values of characters.
Then ascii value of A=65,B=66,C=67 and we can get hash value of above pattern using any hashing functions.
Hash function 1
     hash value h(P) = 65+65+66+67+66 = 329
Hash function 2
     hash value h(P) = 65*1+65*2+66*3+67*4+66*5 =991
Like above you can use any hash functions to calculate hash values.
We can say that if two strings are equal, then hash values of these two string must be same. But if hash values of two strings are equal then we can't say these two strings are equal. I may be or not.  This is the basic idea of the Rabin Carp algorithm.

Algorithm
 Compute hash value of pattern[h(P)]  
    Compute hash value of sub string of text[h(t)]  
    If h(P)=h(t)  
      Compare pattern and sub string character by character  
      If mismatch found  
         move by one position and go to second step  
      Else  
         matching sub string found in the text  
    Else  
      move by one position and go to second step  
Lets learn the algorithm using an example.
     Alphabet S = {A,B,C,D,E,F,G,H}
     Text T = AABDCFFACGABBCABHGADEAADG
     Pattern P = BBCABHG

Here i am going to assign value of character in the alphabet instead of assigning ascii values.
Value(A) = 1
Value(B) = 2
Value(C) = 3
Value(D) = 4
Value(E) = 5
Value(F) = 6
Value(G) = 7
Value(H) = 8
     Then hash value of pattern  h(P) = 2+2+3+1+2+8+7 = 25




Hash value of [AABDCFF] is 23. Hash values are not equal. Sub string is not matched. Move by one position.
Hash value of [ABDCFFA] is 23. Hash values are not equal. Sub string is not matched. Move by one position. 

Hash value of [BDCFFAC] is 25. Hash values are equal. Sub string may be matched. Compare pattern with sub string in the text.
First letter B matched with sub string. But second one mismatched. Move by one position.
Hash value of [DCFFACG] is 29. Hash values are not equal. Sub string is not matched. Move by one position. 
Hash value of [CFFACGA] is 26. Hash values are not equal. Sub string is not matched. Move by one position. 
Hash value of [FFACGAB] is 25. Hash values are equal. Sub string may be matched. Compare pattern with sub string in the text.
First letter B  mismatched. Move by one position. Like these you can find matching sub string.
C implementation of Rabin Carp Algorithm

Complexity

The Rabin-Karp algorithm has the complexity of O(nm) where n, of course, is the length of the text, while m is the length of the pattern. So where it is compared to brute-force matching? Well, brute force matching complexity is O(nm), so as it seems there’s no much gain in performance. However it’s considered that Rabin-Karp’s complexity is O(n+m) in practice, and that makes it a bit faster, as shown on the chart below.
Rabin-Karp's complexity is O(nm), but in practice it's O(n+m)!
Note that the Rabin-Karp algorithm also needs O(m) preprocessing time.

Advantages

  1. Not faster than brute force matching in theory, but in practice its complexityis O(n+m)
  2. Good hashing function it can be quite effective and it’s easy to implement!
  3. Multiple pattern matching support
  4. Good for plagiarism, because it can deal with multiple pattern matching!

Disadvantages

  1. There are lots of string matching algorithms that are faster than O(n+m)
  2. It’s practically as slow as brute force matching and it requires additional space
Rabin-Karp is a great algorithm for one simple reason – it can be used to match against multiple pattern. This makes it perfect to detect plagiarism even for larger phrases.

Friday, October 19, 2012

Computer Boot Up Process

What is computer booting?
        Process of bringing up the operating system for users is called computer boot.
This is a simple classification. But behind this word called computer boot, there are sequence of activities done by your computer.
Following is  booting process of Linux operating systems.
What happen when you press the power button of your computer?
        After pressing power button, first of all power is going to power unit of your machine. Then power unit provide amount of power need by each device in mother board and sends a signal to BIOS (Basic Input Output System) chip in mother board. Then BIOS chip starts a process called POST (Power On Self Test). Under this POST process BIOS chip,
  1. Check whether all the devices receives right amount of power and memory is corrupted.
  2. Then check boot order and according to the boot order find boot loader.
Boot loader is a small program and it is in the first sector or in first 512 bytes in your external memory. It may be floppy drive, CD ROM or hard disk. Here is a simple boot loader in assembly. visit
If BIOS found boot loader in external memory, first sector or first 512 bytes of that external memory device loaded in to the main memory(RAM) as first instruction of the boot loader is in 0x7C00 memory address in RAM.
After loading boot loader in to the RAM , address of the first instruction(0x7C00) of boot loader send to PC(Program Counter). Then CPU will execute the boot loader. When boot loader running, it search for the Kernal inside the hard disk. If it is found, then it will loaded in to the RAM and address of first instruction of the kernal send to PC. Then CPU will start execution of the Kernal.
Then kernal load user program called "INIT" and hands over the machine to the user. INIT is the parent process of all the other processes.
INIT process' first job is to make sure your disks are working normally. Then INIT will start several deamons. Deamons are some programs. As a first deamon, INIT will start a program called "GETTY". This program will prepare the machine for users. Nowadays INIT will start several copies of "GETTY"(7 or 8). Therefore you have several virtual consoles. Then INIT will start several deamons like networking and other services.
The most important deamon is xserver. xserver program will manage your display, key board and mouse. Also xservers' main job is to produce color pixel graphics which you normally see on your screen. Last part of the boot process is graphical login. That produces by a program called  "Display Manager".

Wednesday, September 19, 2012

Simple Hello World Game In C

         Do you want to publish source codes in your blog or web site as follows.
                              Visit Source Code Formatter
 ////////////////////////////A Hello World for game/////////////////////////////////  
 ///////////////////////////////By croosetech///////////////////////////////////////  
 /////////////////Visit croosetech.blogspot.com for more////////////////////////////  
 #include <stdio.h>  
 #include <stdlib.h>  
 #include <string.h>  
 #include <time.h>  
 int main(){  
        int a=0,i=0,answer=0,last=0,x=0,exit=0;  
        last=10;  
        unsigned int iseed = (unsigned int)time(NULL);  
     srand (iseed);  
        while(x<5){  
             i=3;  
             a=rand()%last;   
             printf("\n****************************************\n");  
           printf("\tThis is a Hello World Game\n");  
           printf("****************************************\n");  
             printf("I have a number between 0 to %d.\n\n",last-1);  
             while(i>0){  
                  printf("Try to guess my number(%i attemps remaining): ",i);   
                  scanf("%d", &answer);  
                  if(answer<a){  
                       printf("\nYours %d is too small...\n", answer);   
                       i--;  
                       continue;  
                  }  
                  if(answer>a){  
                       printf("\nYours %d is too big...\n", answer);   
                       i--;  
                       continue;  
                  }  
                  if(answer==a){  
                       printf("\nYou're Right! My number is %d!\n\n\t\tCongratz...", a);   
                       break;  
                  }  
             }  
             if(i==0){  
                  printf("\n\t\tYou are looser !!!.\n\t\t GAME OVER\n");  
                  printf("****************************************\n");  
                  printf("To try again press 1(any other to exit): ");  
                  scanf("%d", &exit);  
                  if(exit==1){  
                       x=0;  
                       last=10;  
                       continue;  
                  }  
                  else {  
                       printf("Good bye!!!");  
                       return 0;  
                  }  
             }  
             else{  
                  printf("Now you are move on to next level\n\n");  
                  x++;  
                  last=last+10;  
                  continue;  
             }  
       }  
       if(x==5){  
            system("clear");  
            printf("\t\tAWESOME PERFORMANCE\n\n\n");  
       }  
      return 0;    
 }  

Monday, September 17, 2012

Graeffe's Root Squaring Method

            Graeffe's method is one of the root finding method of a polynomial with real co-efficients. This method gives all the roots approximated in each iteration also this is one of the direct root finding method. Because this method does not require any initial guesses for roots. It was invented independently by Graeffe Dandelin and Lobachevsky. Which was the most popular method for finding roots of polynomials in the 19th and 20th centuries.

Attributes of nth order polynomial

  1. There will be n roots. Sometimes all the roots may real, all the roots may complex and sometimes roots may be combination of real and complex values.
              All the roots are real - (x2 - 5x + 6 = 0)
              All the roots are complex - (5x2 + x +3 = 0)
              Combination of real and complex roots - (5x3 - 4x2 - x - 3 = 0)
  2. There must be at least one real root, if n is odd. Because complex roots are occur in pairs.
  3. Discartes' rule of sign will be true for any n th order polynomial. 

Discartes' rule of sign

      If we get n th order polynomial as f(x) =0,  Discartes' rule of sign says that maximum number of positive roots of the polynomial f(x) =0, is equal to the number of sign changes of the polynomial f(x). Also maximum number of negative roots of the polynomial f(x), is equal to the number of sign changes of the polynomial f(-x).
        EX : let f(x) = x2 - 5x + 6 = 0.  Then f(-x) = x2 + 5x + 6 = 0
                Number of sign changes of f(x) =0 is 2.Because sign change (+ to -) and (- to +). So, f(x) has    maximum 2 positive roots. Number of sign changes of f(-x) =0 is 0. Because sign does not changed. So, f(x) = 0 does not have any negative roots.

 Lets get nth order polynomial as f(x) = 0. Then get {f(√x) * f(-√x) } = g(x) = 0. Then graeffe's method says that square root of the division of successive co-efficients of polynomial g(x) becomes the first iteration roots of the polynomial f(x). Also second iteration roots can get by multiplying  {g(√x) * g(-√x) } = h(x) = 0 and getting quadratic root of the polynomial g(x). Likewise we can reach exact solutions for the polynomial f(x).
EX :  If f(x) = x2 - 5x + 6 = 0 then f(√x) = x - 5√x  + 6 = 0  and f(-√x) = x + 5√x  + 6 = 0.
         g(x) =  x2 - 13x + 36 = 0.
         first iteration roots are,
                          R1 = (36/13)1/2 =  1.664100   and     R2 = (13/1)1/2 = 3.605551
         h(x) = g(√x)*g(-√x) = x2 - 97x + 1296 = 0.
         second  iteration roots are,
                          R1 = (1296/97)1/4 = 1.911869      R2 = (97/1)1/4 = 3.138288
         likewise for the third iteration,  R1 = (c3/c2)1/8 and R1 = (c2/c1)1/8. We can get any number of iterations and when iteration increases roots converge in to the exact roots.

Derivation


  Special cases in Graeffe's method

  1. If maximum power of polynomial is odd and after squaring if any coefficient of the function except the constant term, is zero, the method does not give exact roots.
       Ex :- g(x)=x3-1=0
      after first iteration g1(x)=x3 +0*x2 +0*x-1
      roots: r1=(|-1/0|)1/2      r2= (|0/0|)1/2  
                           r3= (|0/0|)1/2
      But g(x) has a real root (x=1)
  2. For polynomials that have complex roots, the method gives some real values as roots.
      Ex:- f(x) = x2+x+1
             g(x)=f(x).f(-x) = x4+x2+1
             roots: r1=(|1/1|)1/2    r2=(|1/1|)1/2
             But  f(x)  has complex roots. 

Comparision of graeffe's method with other populer methods

  1. žIt is very complex and very hard to doing manually
      but,
    Bisection method is a very simple and robust method
    Newton-Raphson method  is a very powerful method for finding the real root of an equation
             Secant method is an useful root finding method
  2. žThere are no initial guesses, this is direct method
    but,
    Bisection method - there are  two initial guesses.
    Newton raphson method - there is an initial guess.
    Secant method - there are  two initial guesses.
  3. žCan compute all roots from  one execution
    but,
    Bisection method - If polynomial has n root, method should execute n times using incremental search.
    Newton raphson method - this method  also use incremental search.
    Secant method - this is  also use incremental search.
  4. žThis method converge to absolute roots of polynomials
      but,
    Bisection method ,Newton raphson  method also Secant method converge to real roots of polynomials
  5. The  convergence of root finding methods
    Bisection  method - If one of the initial guesses is close to the root, the convergence is slower.
    Newton-Raphson method - It can be divergent if initial guess not close to the root.
    Secant  method - If the initial values aren’t close to the root, there is no guarantee that the      secant method converges.
     Graeffe’s method is faster than bisection method and sometimes, newton raphson method.

Drawbacks in Graeffe's Method

  1. There are some drawbacks in classical graeffe’s
    method,
    žIt is a many-to-one map. It can map well-conditioned polynomials into ill-conditioned ones.
    Ex:f(x) = x2−2x+1, g(x) = x2−1, h(x) = x2+1
       After two Graeffe iterations, all the three
      polynomials are mapped into f(x). It seems unique roots for all polynomials. But they have different real roots .
  2. žIts usual formulation leads to exponents exceeding the maximum allowed by floating-point arithmetic.
    Ex:-  f(x)= (x − 1)(x − 1.01)(x − 2)(x − 3)(x − 4)
                   =−24.24 + 74.5x − 85.35x2 + 45.1x3− 11.01x4 + x5
       Eight Graeffe iterations are not enough to compute the first root. But eight iterations are enough to overflow the IEEE double precision number system.
  3. žIt returns the absolute value of the roots, but not the actual roots.

Researches on Graeffe's Method

  • žThe floating-point arithmetic limitations of computation are avoided in an efficient implementation  called “Tangent Graeffe Iteration” by Malajovich and Zubelli (2001). They found a new variation of Graeffe iteration(Renormalizing), that is suitable to IEEE floating-point arithmetic of modern digital computers.
  • žRenormalization allows us to avoid coefficient growth, and replace a diverging algorithm by a convergent one.
  • žTo recovering the actual value of each root, and recovering pairs of conjugate roots or multiple roots, many algorithms have been proposed, such as reverse Graeffe iteration, splitting algorithms.

References

         Graeffe’s Method