answersLogoWhite

0


Best Answer

A recursive algorithm is an algorithm which calls itself with "smaller (or simpler)" input values, and which obtains the result for the current input by applying simple operations to the returned value for the smaller (or simpler) input.

Heres a recursive algorithm to reverse a string

char *rev(char str[],int pos1,int pos2)

{

if(pos1<pos2)

{

char temp=str[pos1];

str[pos1]=str[pos2];

str[pos2]=temp;

return rev(str,pos1+1,pos2-1);

}

return str;

}

You can call this function like this

char *r=rev("reverse it",0,9);

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is recursive algorithm and write a recursive algorithm to reverse a string also trace it for any string data?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is it mean by 129 trace in aircraft parts traceability?

It means a trace back to airline.


What are the advantages of using a recursive function in c?

Advantages:Through Recursion one can Solve problems in easy way whileits iterative solution is very big and complex.Ex : tower of HanoiYou reduce size of the code when you use recursive call.Disadvantages :Recursive solution is always logical and it is verydifficult to trace.(debug and understand)Before each recursive calls current values of the variblesin the function is stored in the PCB, ie process controlblock and this PCB is pushed in the OS Stack.So sometimes alot of free memory is require for recursivesolutions.Remember : whatever could be done through recursion could bedone through iterative way but reverse is not true.


How do you access private variable in flex?

In Flex, you access a private variable by calling it from within that class. Remember, the "private" modifier means it cannot be directly accessed outside of the class you declare it in (note I say "directly accessed" you can indirectly access it via public functions which I will show below). Example: declare your variable at the top of your class like this: private var myVariable:String; Then, inside one of your functions of that class, you can access the variable and/or assign it this way: public function changeMyVariable(value:String):void { // sets the private variable to a custom string myVariable="test String"; trace("myVariable is set to "+myVariable); // sets the private variable to the argument passed in myVariable = value; trace("myVariable is now set to" +myVariable); }


What is a backtrace?

A backtrace is another term for a stack trace, in computing, a hierarchical trace of the function calls made by a program, as used in debugging.


C program to find trace and norm of a matrix?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; #include&lt;math.h&gt; void main() { int a[10][10],sum=0,i,j,m,n,trace=0; float norm; printf("enter order"); scanf("%d %d",&amp;m,&amp;n); printf("enter elements "); for(i=0;i&lt;m;i++) {for(j=0;j&lt;m;j++) scanf("%d",&amp;a[i][j]); } for(i=0;i&lt;m;i++) { for(j=0;j&lt;m;j++) { sum=sum+(a[i][j]*a[i][j]); if(i==j) trace=trace+a[i][j]; } } norm=sqrt(sum); printf("norm=%f\n trace=%d",norm,trace); }

Related questions

What is a stack trace?

A 'stack trace' is a list of which functions have been called, based on this information. The stack is very inflexible about allocating memory; everything must be deallocated in exactly the reverse order it was allocated in.


What does the abbreviation XTR stand for?

XTR stands for 'ECSTR' which is Efficient and Compact Subgroup Trace Representation. XTR is an encryption algorithm that generates keys quickly and has small key sizes.


What is a free online reverse directory?

Yes, there is plenty of directories that are online that will trace the number. Usually there is a fee associated with the service. Many investigators are very successful at this.


How do you draw a oval?

Use a Pencil, a string, and 2 nails (or tacks). Mount the 2 nails(or tacks) on a drawing surface. Tie a string into a loop such that it will go around the 2 nails with plenty of extra slack. Lay the string so it encircles the 2 nails. Using your pencil, place it inside the string and pull it one direction so the string loop forms a triangle between 1 nail, the other nail and the pencil point. Now move the string around the nails while keeping the string pulled tight. The pencil will trace an Ellipitcal oval shape.


How can I do a reverse phone lookup?

You can use white pages which is a free online service to trace phone numbers. You can find out their name and address to stop these kind of unwanted calls.


What is the cost of repairing an electrical short in a car?

Unfortunately the question is "how long is a piece of string?" It depends on how easy it will be to find the location of the short, and how accessible that location turns out to be. It might take 20 mins to trace it and 5 mins to fix, or it might take 3 hours to trace, and 4 hours to strip out the dash to get to it.


What is the perimeter of Argentina?

You can find it yourself. Take a world atlas, go to South America and locate the country, Argentina. Note the scale on the map (for example, 10000 to 1). Take a thin string and anchor one end on the map at any boundary point with a pushpin. Slowly trace the boundaries of Argentina by letting the string follow the contour until you return to your pushpin, the starting point. Mark the location on the string. Stretch the string straight, but not too taut. Measure the length of the string with a ruler. Then multiply that value with the number 10000 (from the scale). The product is the perimeter of Argentina.


Can cops trace iPod texts?

Cops cannot track an iPod. The most they can do is a reverse look up on the serial number to find the primary owner.


What is the proper way to hold a circle divider when drawing a circle?

One can draw a circle by finding a round object that is the perfect size and trace the circle. One can also use a compass or string to draw a circle.


What nicknames does Shane Trace go by?

Shane Trace goes by Trace.


Which http methods are used to show the client what the server is receiving?

Trace


What can trace?

Trace, Tracy = Brave