?
Solved

Exponential algoritm

Posted on 2003-11-04
2
Medium Priority
?
646 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
bcladd earned 1500 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Six Sigma Control Plans
Progress
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

764 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