Solved

Exponential algoritm

Posted on 2003-11-04
2
635 Views
Last Modified: 2008-02-26
Hallo experts.
In general:
How (if possible) do I translate an algoritm that uses two while-loops that grow exponential to an algoritm that grows in one dimension instead?
Example:

while not tableOne.EOF

      while not tableTwo.EOF
     
      tableTwo.MoveNext
      wend

tableOne.MoveNext
wend

In this example I need to find every elements in tableTwo with a special status and sum them.
They are then related to tableOne an displayed as this
educationOne(5)
educationTwo(11)
educationThree(3)
. .. .
. .. .
and so on.

My only solution to this is to store the value (inside the pharanteses) in the database whenever any status changes inside the program and not use this algoritm.
But I'm just quoirios if it's possible to do some otherway without storing the value before I want it, and instead calculate it dynamically.

/Sven-Olof

 
0
Comment
Question by:svenoro
2 Comments
 
LVL 11

Accepted Solution

by:
bcladd earned 500 total points
Comment Utility
This is not exponential in growth.

Assuming table1 has N elements and table2 has M elements, this takes O(N*M) time to execute (big-O notation is used to express running times of algorithms. It ignores the exact value of the running time in favor of a simple expression of something approximating proportionality).

Exponential growth would be of the form O(2^N) or O(2^M) or some such.

Okay, now that I am done being pedantic, what about your question.

One suggestion for speeding up the algorithm would be to sort table2 by the special status. If you could group all the elements that should be summed with each element in table1 then you are able to speed up the algorithm to O(N+M) + the cost of the sort. A good sort would be, on average, O(M lg M) (lg is log base 2 but the base of the logarithm is unimportant in big-O).  So if lg M is much smaller than N, you would have a net win with sorting the second table. If necessary you could restore the original order (or work on a copy of table2).

Hope this helps, -bcl
0
 
LVL 2

Expert Comment

by:selim007
Comment Utility
if your data is saved in a database as it seems to be, instead of searching all reacords, why you don't make a query that only retrieves records with the special values you want then work on it. furthermore i think that this can be done totally from SQL and no need for any coding..... but it all depends on what exactly you want to do. but using filtred queries will definetly help you!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now