0

i need to write algo for this problem. i have never written an algo before . please correct me.

there is a list which contains four collumns each with numbers with upto 5 digits and about 10 rows in total. we have to remove the rows containng any number with less than 3 digits. here is how i have tried

  1. read list into multi-dimensional array
  2. for each number in the array if numdigits < 3 delete all numbers of that row

i know this is not the correct algorithm . can you help me correct it .

2
  • 1
    sounds like a great algo to me Commented Oct 26, 2009 at 10:47
  • 1
    If this is homework, you should add the homework tag. Could you post the code you have so far? Commented Oct 26, 2009 at 10:57

2 Answers 2

2

When creating your original list, rather check the individual values then, and not add it to that list if any of the numbers has less than 3 digits, that way reducing the original list size.

EDIT:

foreach row in original_document
{
    bool allMoreThan3Digits = true
    foreach cell in row
        allMoreThan3Digits = allMoreThan3Digits && (ABS(cell.Value) >= 100)

    if (allMoreThan3Digits)
        add row to new list
}

Something like that.

Sign up to request clarification or add additional context in comments.

3 Comments

my origninal is an an excel document. to operate upon it i need to read the excel list into an array . are you saying that while reading it into the array itself i should check for less that 3 digits and then create the array . in that case how would i delete the numbers which are in the same row.
thanks , can you tell me what this line is doing allMoreThan3Digits = allMoreThan3Digits && (ABS(cell.Value) >= 100)
It says allMoreThan3Digits and cell value >= 100. If the number is btween -99 and 99 the result will be false, in which case we do not want to add the row.
0

With up to 5 digits in total in each column? If so here is what I would do.

For each row in list

    For each column in row

        if column number < 100 then
        row delete

4 Comments

It is really not allowed to delete the row you are iterating over in every language. It could result in an iterator pointing to bogus data and being unable to resolve the next item in the collection)
True, but you don't consider 'every language' when writing pseudocode - in fact you don't normally consider any language.
yes i think this algo would work perfectly if use excel's programming language. please give his rating back :-)
jon: even then, if the first column is less than 3 digits, you are still cycling through columns on a row which has just been deleted. This algo is flawed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.