Fn. Called With Same Arguments' Values Many Time (Hw 2 reduce computation time)

My algorithms uses a function of the type .........

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
long double E(int x1, int x2, int x3, int x4, int x5)
// x1..x5 start from 1 and go upto few thousand (2,500)
//For e.g. x1 = 1,..,400; x2 = 1,..,690; x3 = 1,..,1500; x4 = 1,..,980; x5 = 1,..,2400;
{
//decoding of x1,x2,x3,x4,x5 takes place ...... 
//and parmeters are chosen from the problem data set 
dcoding_fn(x1,x2,x3,x4,x5)
{
    ........;
}

for(int l=1; l<5; l++)
for(int i=1; i<5; i++)
{

//case 1:
long doubel f1( parameters of xi )
{
long double g1( parameters of xi );
long double h1( parameters of xi );
................
}

//case 2:
long doubel f2( parameters of xi )
{
long double g2( parameters of xi );
long double h2( parameters of xi );
................
}

//case 3:
long doubel f3( parameters of xi )
{
long double g3( parameters of xi );
long double h3( parameters of xi );
................
}

}

}




that is the function is complex and involves further calls of other funtions



A number of sets {x1,x2,...,xn} are produced during the program run for which the function E() has to be evaluated. The problem is that a set of values of {x1,x2,...,xn} may repeat itself again & again. And it is unnecessary to compute the function value for the same set of values as the value will be the same with only the additional computation time. And computation time has to be minimized for efficient programming.

How can i do this ..............


Somebody told me that hashing can be used here ..... but i don't know whether he is right or not as i have never done hashing ......... it is not known to me .....

Can anybody suggest me a simple way to avoid calling the same function for duplicate sets of values ..... in order to save computation time.?
Is the problem that E(1,2,3,4,5) is in effect a duplicate of E(2,1,4,5,3), or that you get multiple calls of E(1,2,3,4,5)?
@Faldrax .........
the problem is that i get multiple calls of E(1,2,3,4,5)
One option would be to create a struct to hold a set parameters and an STL Set to hold these parameter sets.
You could then use the count method of Set to see if you had already used the set of parameters, exit it you had, add and process if not.
Not sure how efficient this would be, but Set uses binary trees for efficient storage and searching, so should be reasonable.

Topic archived. No new replies allowed.