DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Join Date
    Sep 2005

    The irony of it all...

    I turned the assignment in today, and the professor rejected the way I did it. Basically she told me that it was the most inefficent way possible, and to use a frequency array.

    So can someone explain exactly what a frequency array IS (she didn't do a very good job =p), so I don't spend 2 hours on something that should take 30mins?


  2. #17
    Join Date
    Nov 2004


    Its an array of frequencies I presume, but I dind't know that it was a defined
    algorithm concept. The solution I presented at the bottom of page 1 of this thread
    uses such an array and it only scans the charsequence once. You can't do less
    scanning than that if you want to get the job done.

    The bad thing about that solution is that it is far from an object oriented
    approach, it's just "grunt" sequential programming that has resulted in a
    concrete block of code.

    The other solution I presented (the long winded one,... remember ? ) is in
    my opinion a far better solution.
    Last edited by sjalle; 10-31-2005 at 03:11 PM.
    eschew obfuscation

  3. #18
    Join Date
    Sep 2005
    I would use that approach, however the teacher insists that I use a "frequency" array. She wants it to look something like this:

    Input: "Hello World"

    a: 0, b: 0, c: 0, d: 1, e: 1, f: 0, g: 0, h: 1, i: 0, j: 0, k: 0, l: 3, m: 0, n: 0, o: 2, p: 0, q: 0, r: 1, s: 0, t: 0, u: 0, v: 0, w: 1, x: 0, y: 0, z: 0

    Most frequent char: l (3 time(s))

    Somehow she insists I can make an array of 26 counters, and store the "frequencies" of the letters there..and then output the most frequent one. Although I'm not sure how to store the letters in the array, and keep track of their count(s).

  4. #19
    Join Date
    Nov 2004

    I repeat:

    The last solution I posted in this thread does exactly that, and it will
    work for other alphabets also, not just the 26 characters that seems to
    be the only characters in your teachers universe.

    My solution uses an int array of 256 ints, all initially 0. I see no point in
    fiddling with a subset of 26 or whatever, it just clutters up the code.

    As I scan the characters I use each character (integer cast) to select the
    correct int in the array and increment this by 1. When done I just scan
    the 256 ints for the highest value. The index of the highest value is the
    character with the highest frequency.

    mkay ?
    eschew obfuscation

Similar Threads

  1. Replies: 2
    Last Post: 04-15-2005, 09:06 PM
  2. Replies: 3
    Last Post: 04-08-2005, 05:49 AM
  3. Accessing jagged array values
    By Jason Salas in forum ASP.NET
    Replies: 2
    Last Post: 04-20-2003, 11:39 PM
  4. Replies: 1
    Last Post: 04-08-2002, 11:32 AM
  5. SafeArrayCopy SLOWER than iterating string array!
    By Mark Alexander Bertenshaw in forum VB Classic
    Replies: 0
    Last Post: 06-12-2000, 08:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.