I am drawing a graph which keep on refreshing

Algo
Pmin = starting point of drawing graph line
pmax = ending point of drawing graph line

THpixel = Total Horizontal pixel;
TVpixel = Total Vertical pixel;

pseudo code
loop hpixel <= THpixel
{
    loop Vpixel < pmin
    {
        draw Vpixel with background color
        Vpixel = Vpixel  + 1;
    }

    //drawing min to max line
    loop Vpixel < pmax
    {
        draw Vpixel  with graph color
        Vpixel = Vpixel  + 1;
    }
    loop Vpixel < TVpixel
    {
        draw Vpixel with backround color
        Vpixel = Vpixel  + 1;
    }

    hpixel = hpixel + 1;

}

its complexity will be O(nxm);
THpixel = n;
TVpixel = m

is there any wother ay to reduce the complexity?

最佳答案

你可以从这个算法中删除两个循环
阿尔戈

Pmin = starting point of drawing graph line
pmax = ending point of drawing graph line

THpixel = Total Horizontal pixel;
TVpixel = Total Vertical pixel;

伪码
loop hpixel <= THpixel
{
    // use this method if there is a way to draw this without walking through Box pixels
    // the walking will bring complexity of algorithm again to O(n)
    drawBox(THpixel,TVpixel,backgroungColor);// this is drawing box with background color
    // if there is no way to draw Box, you can remember the last data of graph and when
    //you want to refresh just redraw last graph with background color and draw new one with graph color, so the first step(when 1st time drawing) will took O(mxn) time and the following steps will took O(n) time

    //drawing min to max line
    loop min < Vpixel < pmax
    {
        draw Vpixel  with graph color
        Vpixel = Vpixel  + 1;
    }

    hpixel = hpixel + 1;

}

其复杂度为O(nx(pMAX pmin))=O(n);

10-08 04:05