Click here to Skip to main content
15,911,531 members
Home / Discussions / Algorithms
   

Algorithms

 
Questionhow to make a faster algorithm Pin
roberto_santinni17-Oct-06 11:12
roberto_santinni17-Oct-06 11:12 
AnswerRe: how to make a faster algorithm Pin
ejuanpp17-Oct-06 12:27
ejuanpp17-Oct-06 12:27 
JokeRe: how to make a faster algorithm Pin
toxcct17-Oct-06 12:46
toxcct17-Oct-06 12:46 
AnswerRe: how to make a faster algorithm Pin
Haoman1718-Oct-06 1:17
Haoman1718-Oct-06 1:17 
GeneralRe: how to make a faster algorithm Pin
peterchen21-Oct-06 12:27
peterchen21-Oct-06 12:27 
GeneralRe: how to make a faster algorithm Pin
Haoman1722-Oct-06 7:58
Haoman1722-Oct-06 7:58 
AnswerRe: how to make a faster algorithm Pin
Rob Graham21-Oct-06 13:52
Rob Graham21-Oct-06 13:52 
AnswerRe: how to make a faster algorithm Pin
Xint026-Oct-06 16:50
Xint026-Oct-06 16:50 
How about using a hash-table for the counters and forget about the nested loops.
Assuming you are doing this with .NET 2.0, here's my take on this:
C#
<code lang=cs>
private string DoCount(string input)
{
    string alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890\u0027\u002E\u002C\u003A\u003B\u003F\u0021\u0023\u0028\u0029";
// create hash-table for counters, set initial capacity to number of counters (characters in alphabet).
    Dictionary<char, int> counters = new Dictionary<char, int>(alphabet.Length); 
//initialize just to be safe:
    foreach(char c in alphabet)
        counters[c] = 0;
//count the characters in the input string:
    foreach(char c in input)
        if(counters.ContainsKey(c))
            counters[c]++;
//now output statistics
    string output = string.Empty;
    for (int i = 0; i < alphabet.Length; i++)
    {
        flost percent = 0.0F;
        char c = alphabet[i];
        int count = counters[c];
        if(count > 0)
             percent = (float)count / input.Length;
        output += string.Format("Letter {0} is displayed {1} times.  It is {2:P2} of the whole text.{3}", c, count, percent, Environment.NewLine);
    }
    return output;
}
</code>

Hope it works for you. Big Grin | :-D


-- modified at 22:56 Thursday 26th October, 2006

- Xint0 Cool | :cool:

QuestionWhat is the 13th root of . . . Pin
Bassam Abdul-Baki17-Oct-06 3:59
professionalBassam Abdul-Baki17-Oct-06 3:59 
QuestionHow to draw thick lines using Bresenham's Algorithm? Pin
Arun Chakaravarthy16-Oct-06 23:28
Arun Chakaravarthy16-Oct-06 23:28 
QuestionRUNGE-KUTTA ALGORITH FOR SECOND-ORDER ODE Pin
sahoong15-Oct-06 6:58
sahoong15-Oct-06 6:58 
AnswerRe: RUNGE-KUTTA ALGORITH FOR SECOND-ORDER ODE Pin
franky_mp31-Oct-06 1:48
franky_mp31-Oct-06 1:48 
QuestionTidal elevation calculation Pin
El Corazon12-Oct-06 11:47
El Corazon12-Oct-06 11:47 
AnswerRe: Tidal elevation calculation Pin
Dan Neely13-Oct-06 2:29
Dan Neely13-Oct-06 2:29 
GeneralRe: Tidal elevation calculation Pin
El Corazon13-Oct-06 3:17
El Corazon13-Oct-06 3:17 
GeneralRe: Tidal elevation calculation Pin
Dan Neely13-Oct-06 3:36
Dan Neely13-Oct-06 3:36 
GeneralRe: Tidal elevation calculation Pin
El Corazon13-Oct-06 3:46
El Corazon13-Oct-06 3:46 
AnswerRe: Tidal elevation calculation Pin
fat_boy7-Nov-06 1:16
fat_boy7-Nov-06 1:16 
GeneralRe: Tidal elevation calculation Pin
El Corazon7-Nov-06 2:06
El Corazon7-Nov-06 2:06 
Generalcalculus... [modified] Pin
Anton Afanasyev10-Oct-06 19:27
Anton Afanasyev10-Oct-06 19:27 
GeneralRe: calculus... Pin
Edbert P10-Oct-06 19:32
Edbert P10-Oct-06 19:32 
GeneralRe: calculus... Pin
Anton Afanasyev10-Oct-06 19:36
Anton Afanasyev10-Oct-06 19:36 
GeneralRe: calculus... Pin
Kastellanos Nikos10-Oct-06 23:19
Kastellanos Nikos10-Oct-06 23:19 
GeneralRe: calculus... Pin
peterchen10-Oct-06 21:33
peterchen10-Oct-06 21:33 
GeneralRe: calculus... Pin
Vikram A Punathambekar10-Oct-06 21:46
Vikram A Punathambekar10-Oct-06 21:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.