Best Answer

Call your reversal function reverse().

If you have an empty string, return the empty string (this is the condition for ending recursion). You can also end the recursion when your string has a length of a single character (return the single character), but you must still account for the possibility of empty strings.

Otherwise, separate the string into two parts: for example, the first letter, and the remaining string (see Note 1). Return the reverse() of the second part, joined to the reverse() of the first part.

For example, if your string is "abc", your function would have to return reverse("bc") + reverse("a"). reverse("bc") will, in turn, result in reverse("c") + reverse("b"), so the result will be "cba".

User Avatar

Wiki User

โˆ™ 2010-11-01 11:40:26
This answer is:
User Avatar
Study guides

Create a Study Guide

Add your answer:

Earn +20 pts
Q: What is the algorithm for reverse a given number recursively?
Write your answer...
Related questions

Write an algorithm to print the multiplication table for a given number?

I will write some pseudocode, I suppose that counts as an algorithm. // Given: Number n for i = 1 to 9 print the following: n + " x " + i + " = " + n * i

Fox pro program to reverse the given number?

reverse programe in fox pro

A Write the algorithm to concatenate two given strings?

a write the algorithm to concatenate two given string

Enter a number and draw a flow chart to get the reverse of the given number and the number is 435?


Write an algorithm to find sum of n given numbers?

write algorithem to find the sum of given n number

How can you generate a palindrome from a given number?

You write the number and then follow it with the digits in reverse order.

Write algorithm to insert a node at a given position in a circular linked list?

write algorithm to insert a node at given location

What name is given to prime numbers that you can reverse to make another prime number?

A mirror prime.

What can the reverse lookup be used to find?

The reverse lookup is a telephone number data base. Instead of looking up a phone number based on a given name, a name can be looked up based on a given phone number. It is useful when receiving phone calls from an unknown phone number.

Write a program to find the sum of squares of the given number?

Algorithm and Flowcharts for a program to compute the sum of the squares of the numbers for a given range used for loop

Write an algorithm to check whether the given number is odd or even?

Type your answer here... i think we should first enter 1 number then check it

What is the definition of Algorithm in computer science?

While there is no generally accepted formal definition of "algorithm", an informal definition could be "a process that performs some sequence of operations." For some people, a program is only an algorithm if it stops eventually. For others, a program is only an algorithm if it stops before a given number of calculation steps (

What are the characteristics of an algorithm. Describe with an example?

While designing an algorithm as a solution to a given problem, we must take care of the following five important characteristics of an algorithm.

Write an algorithm and draw a corresponding flowchart to search a number in the given list of numbers and also display its position?

please give me an algorithm and a corresponding flow chart that displays list of numbers from 1 to 20.

Write an algorithm to print the factorial of given number and then draw the flowchart?

write an algorithm to print the factorial of a given number and then draw the flowchart. This looks like someones homework, defiantly someone looking for the easy way. When it comes to programming, the more you do the better you get. Experience counts (making your own mistakes and learning from the mistake).

Why algorithm needs to solve programming problem?

This is the definition of an algorithm - a list of orders of how to solve a given programming problem.

How do you write a program that outputs a given characters in reverse?

write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)

Write a program to find the reverse of a given number with help of function?

suppose you are given the number9254In order to reverse it, you must eliminate each value and reverse it.For example,9254 / 1000 = 99254 % 1000 = 254then254 / 100 = 2254 % 100 = 54then54 / 10 = 554 % 10 = 4and your final digit is 4.I will leave it up to you to figure out how to implement this, but that is the algorithm for extracting digits.It should be clear how to use loops to abstract this problem into a "reverse" function.

What is the Algorithm for reverse a given number?

Assuming you want to reverse the digits of the number: numToReverse <- the number we want to reverse revNum <- new number as numToReverse is reversed while numToReverse is not 0 // shift digits left revNum = revNum * 10 // tack on rightmost digit of numToReverse revNum = revNum + (numToReverse modulus 10) // shift digits right numToReverse = numToReverse / 10 // numToReverse is now 0 // revNum is now the reverse of (the original value of) numToReverse

In term of computer science what is deterministic algorithm?

In computer science, deterministic algorithm is an algorithm which, given a particular input, always produces the same result. This is used to increase the efficiency of machines.

Write an algorithm draw flowchart to find that the given no is prime or not?


Program for print reverse string of given number in java?

I suggest to convert the number to a String, or better directly to a StringBuffer, object. Then use the reverse() method of the StringBuffer class.

Is there an algorithm that yields only prime numbers?

What exactly do you mean "yields only prime numbers"? If you mean a formula that when given the numbers n=1, 2, 3, ... and so on generates the nth prime number (or a different prime number for each n) then no. If you mean an algorithm whereby a number can be tested to be a prime number then yes. (Using this prime_test algorithm, a simple algorithm can be written that would supply numbers one at a time to it and use its result to decide whether to yield the tested number or not, only yielding those numbers which pass the test.)

What is Vector generation algorithm?

It is a basic algorithm for generating lines on computer screen. line is generated between given 2 endpoints

What is the relationship between a program and an algorithm?

An algorithm is a system independent idea; a program is a concrete implementation of that idea for a given computer system.