CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > visual_studio.visual_studio_2005 Tags:
Item Type: NewsGroup Date Entered: 6/19/2007 2:10:05 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 8 Views: 27 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
9 Items, 1 Pages 1 |< << Go >> >|
iuliax
Asp.Net User
From recursive to iterativ function6/19/2007 2:10:05 PM

0/0

I need to write this recursive function in an iterative way: 

private static Control FindControlRecursive(Control root, string id)

{

if (root.ID == id)

return root;

foreach (Control c in root.Controls)

{

Control t = FindControlRecursive(c, id);

if (t != null)

return t;

}

return null;

}


Popa Iulia
____________________
MCP.MCAD.MCSD
ArtemL
Asp.Net User
Re: From recursive to iterativ function6/19/2007 4:55:19 PM

0/0

iuliax, why do you need this? Recursive approach is quite the best here. Or gimme contr arguments.

In other case you do need to know the deep of controls hierarchy to make it iterative


Never ask users what they want, or they'll tell you
ArtemL
Asp.Net User
Re: From recursive to iterativ function6/19/2007 5:02:09 PM

0/0

To make sure have a look at sources (by using .Net Reflector) of Control.FindControl method. It does it recursively.


Never ask users what they want, or they'll tell you
haoest
Asp.Net User
Re: From recursive to iterativ function6/19/2007 6:57:44 PM

0/0

I can write up some psudo code fast:

findcontrol(Control root, string id){
 ArrayList stack = new ArrayList();
stack.AddAll( root.Controls );
while(!stack.empty){
   Control cur = stack.pop();
   stack.AddAll(cur.Controls);
   if (cur.id == id)
      return cur;
   }

}


Debugger is my best friend.
iuliax
Asp.Net User
Re: From recursive to iterativ function6/20/2007 7:17:35 AM

0/0

Recursive is good when the detph is not high. But in my case if I look with ANTS Profiler

i have performance improvements in the case of iterative function.

 


Popa Iulia
____________________
MCP.MCAD.MCSD
iuliax
Asp.Net User
Re: From recursive to iterativ function6/20/2007 7:18:51 AM

0/0

Yes, Control.FindControl is recursive, but only on the same level (seabling)


Popa Iulia
____________________
MCP.MCAD.MCSD
ArtemL
Asp.Net User
Re: From recursive to iterativ function6/20/2007 7:32:07 AM

0/0

I agree with you. Iterative is always more faster. But, if the performance is not the issue recursive algorithms are mostly more understandable to read than the iterative ones.

And in many cases the performance bottlenecks are usually in different places, such as: connection to database, bad sql execution plan, redundant hits to database, etc. You'll gain more benefits when optimise these stuff.

Just my 2 cents.


Never ask users what they want, or they'll tell you
iuliax
Asp.Net User
Re: From recursive to iterativ function6/20/2007 7:51:01 AM

0/0

You must take into account that not all the application are based on the Database servers.

What about client server applications, or COM app or many others?!!?

 


Popa Iulia
____________________
MCP.MCAD.MCSD
stelianx
Asp.Net User
Re: From recursive to iterativ function6/20/2007 9:08:22 AM

0/0

Best iterative way:

OBS: if replacing foreach with a classice for is faster, if replace the classic for with a IEnumerable Next, current is faster more:

Recursive MAY be better if the hierarchy is not high, but after deep 2-3 in the control tree recursion blows us in exponential black hole

private static Control FindControlIterative(Control root, string id)
        {
            Control ctl = root;
            LinkedList ctls = new LinkedList();

            while (ctl != null)
            {
                if (ctl.ID == id)
                    return ctl;
                foreach (Control child in ctl.Controls)
                {
                    if (child.ID == id)
                        return child;
                    if (child.HasControls())
                        ctls.AddLast(child);
                }
                ctl = ctls.First.Value;
                ctls.Remove(ctl);
            }
            return null;
        }
 
Yours,
Popa D. Stelian
MCP/MCAD/MCSD
ROMANIA
9 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
C++ Plus Data Structures Authors: Nell B. Dale, Pages: 781, Published: 2007
Concepts, Techniques, and Models of Computer Programming Authors: Peter Van-Roy, Seif Haridi, Pages: 900, Published: 2004
Computation Theory and Logic Authors: Egon Börger, Pages: 442, Published: 1987
Data Structures and the Standard Template Library Authors: William J. Collins, Pages: 0, Published: -1
Scientific Pascal Authors: Harley Flanders, Pages: 590, Published: 1996
ML for the Working Programmer Authors: Lawrence C. Paulson, Pages: 476, Published: 1996
Mathematical Logic and the Foundations of Mathematics: An Introductory Survey Authors: G. T. Kneebone, Pages: 452, Published: 2001
C++ how to Program: How to Program Authors: Paul J. Deitel, Pages: 1429, Published: 2008

Web:
Performance comparison between recursive and iterative functions ... Performance comparison between recursive and iterative functions C++ ... Just for giggles, I decided to do it as an iterative function for ...
Recursion (computer science) - Wikipedia, the free encyclopedia This result is typical, because iterative functions do not pay the "function- call overhead" as many times as recursive functions, and that overhead is ...
Recursive and Iterative Functions for Generating Fibonacci Numbers Recursive and Iterative Functions for Generating Fibonacci Numbers. Source. Technical Report: TR89-1017. Year of Publication: 1989 ...
From recursive to iterativ function - ASP.NET Forums I need to write this recursive function in an iterative way:. private static Control FindControlRecursive(Control root, string id) ...
CodeProject: Iterative vs. Recursive approaches. Free source code ... Iterative functions – are loop based imperative repetition of a process (in contrast to recursion which has more declarative approach). ...
RECURSION We have discussed the correspondence and relative advantages and disadvantages of recursive function definitions compared with iterative definitions. ...
Recursive self-organizing map as a contractive iterative function ... Recursive self-organizing map as a contractive iterative function system. Peter TINO, Igor FARKAS, Jort VAN MOURIK Lecture notes in computer science, ...
0 6.090, Building Programming Experience Ben Vandiver Lecture 4 ... operation listed before the recursive function, then it is a recursive process. Getting iterative process from recursive:. Example: Pad ...
Recursion Nov 11, 2007 ... Here is the same function coded without recursion. Notice that this iterative solution requires two temporary variables; in general, ...
iterative-processes A function defined like the above, where the recursive call is in tail position is said to be tail-recursive or iterative. ...

Videos:
Fractal Genome See how DNA governs the production of proteins by recursive/iterative function.




Search This Site:










password expiry

hosttitle or portaltitle

please help documents core module 3.0.12 - browsing root portal only

could not connect to database sql server 2005 express

about user login

add textbox when program is running

how do i design custom installation in vb.net

templated control designers and default controls

listview in asp.net

codes for special characters?

need for all betas

time tracker as a subweb

solpartmenu randomly defaults back to default styles

how can i add web deployment project to my asp.net project with visual studio 2005?

data application block

register vwd rc

installation with my hosting provider

quick question - should skin files have intellisence

comparing control panels - dotnetpanel vs helm and others

disabling wizard steps

fxcop built into vs2005?

authorization and controlling the users

membership profiles and roles

question on the first walkthrough. is html source for client or server?

who is online (cf and asp .net)

3.0.4 file manager: database synch

how to handle events in controls , which are loaded at runtime

storing logged in users in the custom membership.

authentication using siteminder

running a webservice

 
All Times Are GMT