School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,360 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,700 people online right now. Registration is fast and FREE... Join Now!




logarithmic loop calculations

 

logarithmic loop calculations

jcmaster2

1 Jun, 2009 - 11:50 AM
Post #1

D.I.C Head
**

Joined: 27 Apr, 2009
Posts: 139



Thanked: 4 times
My Contributions
Help with math calc

Calculating efficiency of loops from both

Gilberg and Hortsmann books...


Logarithmic Loops (multiplication and division):



Where log x (log base x) is the multiple/divisor value

Note with division we flip n and m in the formulas above.

Basically I trying to find an all purpose formula- derived from the following..

A loop where the loop control body is multiplied or divided...

f(n) = ceil(log2 n) or where N is the iterations...

what I came up with

Cases 1 and 2 are applicable to logarithmic loops as well.
3. Valid Execution:

Same test as above except:

for (i = m; i < n; i *= x)
do something

o If the condition is < or > the formula is:

num = ceiling (log x (n / m))

o If the condition is ≤ or ≥ the formula is:

num = floor (log x (n / m)) + 1


Any additional insight for those math inclined with my quest of a general formula..



User is offlineProfile CardPM
+Quote Post


bsaunders

RE: Logarithmic Loop Calculations

1 Jun, 2009 - 03:48 PM
Post #2

D.I.C Addict
****

Joined: 18 Jan, 2009
Posts: 554



Thanked: 42 times
My Contributions
General formula describing what exactly?

num = ceiling (log x (n / m)) and num = ceiling (log x (n / m)) + 1 seem correct to me.

This post has been edited by bsaunders: 1 Jun, 2009 - 03:49 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 07:51PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month