Solved

Exponential algoritm

Posted on 2003-11-04
2
638 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
ID: 9678382
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
ID: 9720949
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 …

860 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