473,662 Members | 2,622 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recursion

Write a function that produces the same output as MyFunction but without the
use of recursion.
( perfect C# is not a requirement, you may write in pseudo code )
Aug 13 '07 #1
14 1957
I'm sorry, no one told me there would be a test today....
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"seema" <se***@discussi ons.microsoft.c omwrote in message
news:AD******** *************** ***********@mic rosoft.com...
Write a function that produces the same output as MyFunction but without
the
use of recursion.
( perfect C# is not a requirement, you may write in pseudo code )


Aug 13 '07 #2
This is not a test I just took some samples from book and trying to solve it
.. Please help me.

"seema" wrote:
Write a function that produces the same output as MyFunction but without the
use of recursion.
( perfect C# is not a requirement, you may write in pseudo code )

Aug 13 '07 #3
Can you clarify what MyFunction does? What is it's output?

"seema" wrote:
This is not a test I just took some samples from book and trying to solve it
. Please help me.

"seema" wrote:
Write a function that produces the same output as MyFunction but without the
use of recursion.
( perfect C# is not a requirement, you may write in pseudo code )
Aug 13 '07 #4
Nevermind. I see your previous post. To do it without recursion, just
figure out what it is really doing. You can do this with a loop.

"ModelBuild er" wrote:
Can you clarify what MyFunction does? What is it's output?

"seema" wrote:
This is not a test I just took some samples from book and trying to solve it
. Please help me.

"seema" wrote:
Write a function that produces the same output as MyFunction but without the
use of recursion.
( perfect C# is not a requirement, you may write in pseudo code )
>
>
Aug 13 '07 #5
Hi,

where is Myfunction code?
"seema" <se***@discussi ons.microsoft.c omwrote in message
news:AD******** *************** ***********@mic rosoft.com...
Write a function that produces the same output as MyFunction but without
the
use of recursion.
( perfect C# is not a requirement, you may write in pseudo code )


Aug 13 '07 #6


"ModelBuild er" <Mo**********@d iscussions.micr osoft.comwrote in message
news:EC******** *************** ***********@mic rosoft.com...
Nevermind. I see your previous post. To do it without recursion, just
figure out what it is really doing. You can do this with a loop.

"ModelBuild er" wrote:
>Can you clarify what MyFunction does? What is it's output?

"seema" wrote:
This is not a test I just took some samples from book and trying to
solve it
. Please help me.

"seema" wrote:

Write a function that produces the same output as MyFunction but
without the
use of recursion.
( perfect C# is not a requirement, you may write in pseudo code )

Without giving away one possible solution....I will write this in
descriptive, non pseudo, non actual code :)

I would not use a loop in my own code, rather I would rely on the framework
for doing it for me. You can do this using the Reverse method of the Array
class, after converting the string to a character array, then pass the
results of the Reverse method to the constructor of the string class.
Voila, results!

:)

HTH,
Mythran
Aug 13 '07 #7
According to my textbook on Pascal, written by Robert L. Kruse, any
recussive problem can (and should) be made into a more efficient non-
recursive problem.

The solution is to employ a stack, do stuff you need to do in a loop,
then pop off the stack stuff that you put off. It's straightforward ,
once you get used to it. In fact I find recursion harder to understand
than a loop.

In fact I'm writing code for traversing an N-ary tree non-recursively
right now.

Just put your mind to it.

RL

Aug 13 '07 #8
raylopez99 wrote:
According to my textbook on Pascal, written by Robert L. Kruse, any
recussive problem can (and should) be made into a more efficient non-
recursive problem.

The solution is to employ a stack, do stuff you need to do in a loop,
then pop off the stack stuff that you put off. It's straightforward ,
once you get used to it. In fact I find recursion harder to understand
than a loop.
If you refactor a recursive algorithm so that it uses an explicit stack,
it's still essentially recursive.

Many algorithms implemented recursively can in fact be implemented
iteratively, _and_ without using a stack. Tail recursion is the
classic, obvious example. But if all you're doing is moving the stack
from the compiler-generated code to your own code, then you've done
little else but to obfuscate the underlying algorithm and create more
work for yourself, without changing the basic recursive nature of the
algorithm.

Pete
Aug 13 '07 #9
Okay. (BTW, it would correctly be referred to as MyMethod):

public static MyMethod MyMethod(MyMeth od myMethod)
{
return myMethod;
}

Works for me, friend! Garbage in, garbage out....

--
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"seema" wrote:
Write a function that produces the same output as MyFunction but without the
use of recursion.
( perfect C# is not a requirement, you may write in pseudo code )

Aug 14 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3415
by: Peri | last post by:
I'm trying to create Python parser/interpreter using ANTLR. Reading grammar from language refference I found: or_expr::= xor_expr | or_expr "|" xor_expr For me it looks like infinite recursion. And so it says ANTLR. Maybe I don't understand EBNF notation. For me it should look like this. or_expr::= xor_expr | xor_expr "|" xor_expr and in ANTLR grammar file like this:
12
2749
by: da Vinci | last post by:
Greetings. I want to get everyone's opinion on the use of recursion. We covered it in class tonight and I want a good solid answer from people in the "know" on how well recursion is accepted in modern day applications. Should we readily use it when we can or only when absolutly forced to use it?
43
4149
by: Lorenzo Villari | last post by:
I've tried to transform this into a not recursive version but without luck... #include <stdio.h> void countdown(int p) { int x;
2
1562
by: Csaba Gabor | last post by:
I suppose spring fever has hit at alt.math.undergrad since I didn't get any rise from them when I posted this a week ago, so I am reposting this to some of my favorite programming groups: I'm looking for problems that have double (or more) recursion, where the split is not clean (ie. where there may be overlap). Let's call this overlapped recursion, where the
75
5602
by: Sathyaish | last post by:
Can every problem that has an iterative solution also be expressed in terms of a recursive solution? I tried one example, and am in the process of trying out more examples, increasing their complexity as I go. Here's a simple one I tried out: #include<stdio.h> /* To compare the the time and space cost of iteration against
19
2276
by: Kay Schluehr | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
18
3715
by: MTD | last post by:
Hello all, I've been messing about for fun creating a trial division factorizing function and I'm naturally interested in optimising it as much as possible. I've been told that iteration in python is generally more time-efficient than recursion. Is that true? Here is my algorithm as it stands. Any suggestions appreciated!
13
4516
by: robert | last post by:
My code does recursion loops through a couple of functions. Due to problematic I/O input this leads sometimes to "endless" recursions and after expensive I/O to the Python recursion exception. What would be a good method to detect recursion loops and stop it by user-Exception (after N passes or some complex criteria) without passing a recursion counter parameter through all the funcs? Robert
20
2986
by: athar.mirchi | last post by:
..plz define it.
35
4715
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8546
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.