Jump to content

Programming Pseudo code Question


KayS

Recommended Posts

I have a programming pseudo code question regarding palindrome theory, meaning a program that checks if the string is the same fowrds to backwrds and backwrds to forwrds.

 

post-87420-0-35318900-1405545591_thumb.png

 

I chose A as my answer because If i use the string "dad" in the array it would return true, the other doe the checking but some results false any suggestions?

Link to comment
Share on other sites

I have no idea in what language it's written but A answer is almost certainly wrong. J is always constant in whole inter loop..


Doing floor( value ) has no sense for integer also. It should be used only for float argument.

Link to comment
Share on other sites

I get it now sorry it was my fault the index actuall starts at 1 and not 0 I just realised it..but what confuses me is that B and C test against the second last element which is a good test but return false :S

 

for example lets say the String in the array is [ m a d a m ] <-- testing the second element "a" with second last "a" would suggest its the correct value.. but then again D seems more reasonable now as "laurieAG" suggested it checks all elements and doesnt rely on comparing the second last.

 

So I think D is the correct answer no

Link to comment
Share on other sites

Am i right to think that B and C are also wrong because they never increment the counter so it would be an endless loop checking the same condition whereas D increments its counter meaning the test changes each time?

Link to comment
Share on other sites

The main problem with B and C is that they do not compare the first element with the last element and B also does not increment the counter. A is the option where all elements are compared with the last element. The FOR and WHILE loops operate differently as the FOR has the counter increment embedded.

 

If you step through each option for each increment and write down what each of the variables are for each of the cycles you will be able to see the differences.

 

KayS, please post your results for 3 cycles of B, C and D.

A     i     j    arr(i)   arr(j)
      1     5      m        m
      2     5      a        m
      3     5      d        m
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.