Solved

Exponential algoritm

Posted on 2003-11-04
2
636 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
strCount chalenge 3 71
Hide vba in gp 7 83
C# code editing and collaboration 3 99
Please help| Getting the syntax error in below query. 2 47
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This article will show, step by step, how to integrate R code into a R Sweave document
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

896 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

14 Experts available now in Live!

Get 1:1 Help Now