[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Exponential algoritm

Posted on 2003-11-04
Medium Priority
647 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
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

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

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

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Make the most of your online learning experience.
Simple Linear Regression
Starting up a Project
###### Suggested Courses
Course of the Month12 days, 17 hours left to enroll

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

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