Is this algoritham and pseudo correct

  • Thread starter PainterGuy
  • Start date
In summary: Mark44 correct?:rolleyes:is coding algorithm different from normal english algorithm? some one has told me that first your write algorithm in english then you transfer every statement in english algorithm into code of program language you...I think so. I wrote my algorithm in English first and then I transferred it into code.
  • #1
PainterGuy
940
70
hello nice people,

i was writing a algorithm and psedo for some problem here:
[Link Removed]

is there someone who will help me to correct it? you can edit it there on the docs. much grateful for any help you can give me.

cheers
 
Last edited:
Physics news on Phys.org
  • #2
Why don't you just enter what you did right here?
painterguy said:
Five numbers denoted by the variables A, B, C, D, and E are supplied as input. Write an algorithm and pseudocode to print these numbers in descending order of magnitude.

Step 1: Read the input data
Step 2: Compare A, B, C, D, and E
Step 3: Print the largest of five
Step 4: Compare the remaining four numbers
Step 5: Print the largest of four
Step 6: Compare the remaining three numbers
Step 7: Print the largest of three
Step 8: Compare the remaining two numbers
Step 9: Print the largest of two
Step 10: Print the last remaining number
Step 11: Stop

Read the input data
DO WHILE the numbers A, B, C, D, and E are not in descending order
How do you compare five numbers? I know how to compare two numbers, but I don't know how to compare five of them at the same time.
 
  • #3
Mark44, could you remove that quoted text from your post please, if you don't mind? actually i want to change something in that text. if it's possible please do it. i am very grateful for your help.

cheers
 
Last edited:
  • #4
Just copy it from what's in my post and paste it in your reply. You can make changes there.
 
  • #5
Mark44 said:
I know how to compare two numbers, but I don't know how to compare five of them at the same time.

EDIT: To do what the OP wants (based on the quoted text by yourself) is actually relatively simple.

Put the numbers into a list / array. Write a simply function to iterate through the numbers and hold the largest*, print it, remove it from the list. Repeat until list is down to one item and print.

What language are you required to do this in painterguy?

* Example:

Take A, is B bigger than A? No. Hold A.
Is C bigger than A? Yes. Hold C.
And so on through the whole list / array.
Once complete, print that value and remove it from the list.
Repeat.

You would have to build in something to handle equal values.
 
  • #6
jarednjames said:
EDIT: To do what the OP wants (based on the quoted text by yourself) is actually relatively simple.

Put the numbers into a list / array. Write a simply function to iterate through the numbers and hold the largest*, print it, remove it from the list. Repeat until list is down to one item and print.

What language are you required to do this in painterguy?

* Example:

Take A, is B bigger than A? No. Hold A.
Is C bigger than A? Yes. Hold C.
And so on through the whole list / array.
Once complete, print that value and remove it from the list.
Repeat.

You would have to build in something to handle equal values.

hello everyone,:smile:

i want to write this in english. many thanks for helping me out.

cheers:smile:
 
  • #7
painterguy said:
hello everyone,:smile:

i want to write this in english. many thanks for helping me out.

cheers:smile:

I meant programming language.
 
  • #8
jarednjames said:
I meant programming language.

until now i do not know because i know almost nothing about programming!:shy:

many thanks

cheers:smile:
 
  • #9
painterguy said:
until now i do not know because i know almost nothing about programming!:shy:

many thanks

cheers:smile:

But you're asked to write an algorithm as well as a pseudocode.
 
  • #10
jarednjames said:
But you're asked to write an algorithm as well as a pseudocode.

hello,:smile:

yes i too want to write pseudo code. i do not know if pseudo code is require for programming. some good people on this forums are teaching me the basics of programming. :approve:

you can see my algo and pseudo here:--
https://www.physicsforums.com/showthread.php?t=484875

cheers:smile:
 
  • #11
painterguy said:
hello,:smile:

yes i too want to write pseudo code. i do not know if pseudo code is require for programming. some good people on this forums are teaching me the basics of programming. :approve:

you can see my algo and pseudo here:--
https://www.physicsforums.com/showthread.php?t=484875

cheers:smile:

Ah I see, your fine then. That looks ok.

I thought they wanted the actual coding algorithm for the task.
 
  • #12
jarednjames said:
Ah I see, your fine then. That looks ok.

I thought they wanted the actual coding algorithm for the task.

many thanks for your reply. so my algo on 2nd post of Mark44 correct?:rolleyes:

is coding algorithm different from normal english algorithm? some one has told me that first your write algorithm in english then you transfer every statement in english algorithm into code of program language you use.

cheers:smile:
 
  • #13
painterguy said:
many thanks for your reply. so my algo on 2nd post of Mark44 correct?:rolleyes:

Seems ok. Could do with more detail for the comparison section though.
is coding algorithm different from normal english algorithm? some one has told me that first your write algorithm in english then you transfer every statement in english algorithm into code of program language you use.

Well the code version will be what's used in the program itself.

If you are planning a function you should write out what you want it to do and then convert it to code - just gives you a bit of structure and makes things easier.
 
  • #14
jarednjames said:
Seems ok. Could do with more detail for the comparison section though.

Well the code version will be what's used in the program itself.

If you are planning a function you should write out what you want it to do and then convert it to code - just gives you a bit of structure and makes things easier.

many thanks jarednjames.:smile:

it will be a normal english algorithm then. will it not be?:confused: but i think it will be little more technical, will be short, and will require careful thinking than normal english algorithm which i have written. tell me please is it so?

much grateful for helping me out.

cheers:smile:
 
  • #15
painterguy said:
many thanks jarednjames.:smile:

it will be a normal english algorithm then. will it not be?:confused: but i think it will be little more technical, will be short, and will require careful thinking than normal english algorithm which i have written. tell me please is it so?

much grateful for helping me out.

cheers:smile:

What you have in the other thread is correct for what you need.

Just apply it here.
 
  • #16
okey-dokey. many thanks then.:smile:
 
  • #17
IMO the algorithm is NOT OK. My point about comparing five numbers is that you can really compare only two numbers at a time. For instance, to compare A and B you can check to see whether A > B, A == B, or A < B.

To find the largest of three numbers, A, B, and C, you're going to have to compare A with B, A with C, and B with C. My point is that you don't compare A, B, and C all in one operation. Your algorithm should go into some detail about exactly what you're going to do.
 
  • #18
Mark44 said:
IMO the algorithm is NOT OK. My point about comparing five numbers is that you can really compare only two numbers at a time. For instance, to compare A and B you can check to see whether A > B, A == B, or A < B.

To find the largest of three numbers, A, B, and C, you're going to have to compare A with B, A with C, and B with C. My point is that you don't compare A, B, and C all in one operation. Your algorithm should go into some detail about exactly what you're going to do.

I agree (well, exactly as per my example).

Bolded: As per post #13, my clause was it's ok but there does need to be more detail on the comparison.
 

FAQ: Is this algoritham and pseudo correct

Is this algorithm and pseudo code correct?

The answer to this question depends on the specific algorithm and pseudo code in question. Generally, an algorithm and pseudo code are considered correct if they accurately describe the steps needed to solve a specific problem. It is important to carefully review and test the code to ensure it is accurate and efficient.

How can I determine if an algorithm and pseudo code are correct?

To determine if an algorithm and pseudo code are correct, you can follow a few steps. First, carefully review the code and make sure it accurately describes the steps needed to solve the problem. Then, try to run the code with different inputs to see if it produces the expected output. You can also use a debugger or a code analysis tool to identify any potential errors or inefficiencies in the code.

What makes an algorithm and pseudo code incorrect?

An algorithm and pseudo code can be incorrect if they do not accurately describe the steps needed to solve a specific problem. This can result in errors or incorrect outputs when the code is run. Additionally, an algorithm and pseudo code can be incorrect if they are not efficient or if they do not follow best practices for coding.

Can an incorrect algorithm and pseudo code be fixed?

Yes, an incorrect algorithm and pseudo code can be fixed. This may involve identifying and correcting errors in the code, making the code more efficient, or following best practices for coding. It is important to carefully review and test the code to ensure it is accurate and efficient.

Are there any tools or resources available to check the correctness of an algorithm and pseudo code?

Yes, there are various tools and resources available to check the correctness of an algorithm and pseudo code. These include debuggers, code analysis tools, and online code validators. It is also helpful to consult with other programmers or experts in the specific problem domain for feedback and suggestions on improving the code.

Similar threads

Replies
6
Views
1K
Replies
3
Views
904
Replies
9
Views
1K
Replies
49
Views
4K
Replies
1
Views
2K
Replies
2
Views
1K
Back
Top