How would you deal with the previous problem if the palindrome could have an odd or even length?

What will be an ideal response?


If the palindrome has an odd number of characters, the two pointers meet in the middle (i.e., stop when they are the same). If the palindrome has an even number of characters the pointers are adjacent at the end of the search. Therefore we stop on LeftPointer+1 = RightPointer. If we don’t know whether the string to test is odd or even, we have to test both conditions to determine when to stop.


CMP r1,r2 ;test for end (odd case)
BEQ ExitS ;if leftPointer = rightPointer exit success
ADD r1,r5,#1 ;move leftPointer right one place and save in r5
CMP r5,r2 ;if moved leftPointer = rightPointer exit success
BEQ ExitS

Computer Science & Information Technology

You might also like to view...

A pointing device allows you to manipulate an on-screen pointer and other screen-based graphical controls. Please briefly describe each of these popular pointing devices: touchpads, trackballs, and game controllers.

What will be an ideal response?

Computer Science & Information Technology

Keeping old messages does not slow down retrieval of messages since you are most likely looking only at current messages

Indicate whether the statement is true or false

Computer Science & Information Technology

________ is a background color that appears behind text

Fill in the blank(s) with correct word

Computer Science & Information Technology

The ____________________ layer of the OSI model determines the network’s wiring and signaling types.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology