Jump to content

Programming Pseudo code Question

Featured Replies

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?

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.

A only tests all elements against the last element, B and C test the first element against the second last element while D tests all the elements correctly.

  • Author

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

For the first element both B and C test arr(i) or arr(index), where i or index = 1 (i.e. element 'm'), against len(arr) -1 (i.e. 5-1 = 4 or element 'a'), which is the second last element not the last element.

  • Author

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?

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

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.