Notices
Results 1 to 5 of 5

Thread: Writing Algorithms

  1. #1 Writing Algorithms 
    New Member
    Join Date
    May 2010
    Posts
    2
    I'm taking a two year computer science course in high school and i'm having trouble with writing algorithms.
    we are supposed to write algorithms in pseudo code.

    for example:
    A small company sells 200 items per day from three departments:
    linens (code L) Perfumes (code P) Toys (code C)
    Each item is identified by the department code and 3 digits. (eg. C123 )
    Write an algorithm using pseudo code which monitors the sale of the 200 items each day. The following inputs, processing and outputs are all part of the monitoring process:
    -input item identification
    -calculate number of items per day for each of the 3 departments
    -output the percentage of the total items per day by each department
    - only valid codes must be accepted

    that's a question from our top 50 questions sheet for our final exam.
    i have no idea what i am supposed to do. :?


    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Freshman
    Join Date
    Feb 2010
    Posts
    84
    Sounds like you are at the absolute-beginner level, which is great because there's all kinds of interesting things to learn. At that level I'd think what they want is a conceptual solution to the problem. An algorithm is just a recipe for how to do something. I would just try to think through the problem and figure out how I would do each step remembering that a computer is very stupid and needs to be told how to do just about everything.

    For instance, we know from the problem setup that we will get a bunch of strings of alpha-numeric digits as input and need to sort them into bins for each department so we can count them. Since the department is coded in the first character of the string, the algorithm might be:

    1. Get input string;
    2. Look at first character;
    3. Put into bin for that character.

    Then every day:

    1. At end of day;
    2. Count items in each bin;
    3. Calculate percentages:
    a. sum the total number of items in all bins;
    b. for each bin:
    i. divide number in bin by total sum;
    ii. print it out someplace.

    The hard part is coming up with something that validates the codes. You could have a few types of errors:
    1) a non-existent "department code";
    2) an non-existent "item number";
    3) various mixed up department codes and item numbers;
    4) probably even more arcane errors...

    So it just keeps on getting more complicated as you go.


    Reply With Quote  
     

  4. #3  
    New Member
    Join Date
    May 2010
    Posts
    2
    Quote Originally Posted by schip666
    Sounds like you are at the absolute-beginner level, which is great because there's all kinds of interesting things to learn. At that level I'd think what they want is a conceptual solution to the problem. An algorithm is just a recipe for how to do something. I would just try to think through the problem and figure out how I would do each step remembering that a computer is very stupid and needs to be told how to do just about everything.

    For instance, we know from the problem setup that we will get a bunch of strings of alpha-numeric digits as input and need to sort them into bins for each department so we can count them. Since the department is coded in the first character of the string, the algorithm might be:

    1. Get input string;
    2. Look at first character;
    3. Put into bin for that character.

    Then every day:

    1. At end of day;
    2. Count items in each bin;
    3. Calculate percentages:
    a. sum the total number of items in all bins;
    b. for each bin:
    i. divide number in bin by total sum;
    ii. print it out someplace.

    The hard part is coming up with something that validates the codes. You could have a few types of errors:
    1) a non-existent "department code";
    2) an non-existent "item number";
    3) various mixed up department codes and item numbers;
    4) probably even more arcane errors...

    So it just keeps on getting more complicated as you go.
    thank you.. i think this should help :P
    what are arcane errors?
    and do you have any tips on writing and figuring out algorithms in pseudo code that would help me pass my exams and understand better?
    Reply With Quote  
     

  5. #4  
    Forum Freshman
    Join Date
    Feb 2010
    Posts
    84
    Arcane Error: Anything you didn't already think of... Say the total number of items sold on Sunday in Utah is 0 and you try to calculate the percentages. You probably get a floating point number fault from trying to divide by zero in your program which was not setup to catch that particular situation... The list can go on, and on, and on. And on.

    Learning a bit about how to program and what computers expect as their input should guide you in thinking about the algorithms you need. The wiki "Algorithm" article looks pretty good, especially the first block diagram of how to fix a lamp. Reading some of the standard texts by Wirth Algorithms + Data Structures = Programs, or Knuth The Art of Computer Programming would be more advanced ways to confuse yourself.

    Just remember that they are really stupid beings who need to be told how to do everything in explicit detail and you will be fine...
    Reply With Quote  
     

  6. #5  
    New Member
    Join Date
    Jul 2010
    Posts
    1
    great information :-D
    Reply With Quote  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •