473,323 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Algorithm problem

zorgi
431 Expert 256MB
Hi all

I have a Algorithm problem. I have data that comes in an array:

Expand|Select|Wrap|Line Numbers
  1. $b = array( "A", "B", "C");
  2.  
This array $b is than passed to function. Lets call this function fun:

Expand|Select|Wrap|Line Numbers
  1. function fun($b){
  2.     /*
  3.     *Some code
  4.     */    
  5.     return $result;
  6. }
  7.  
What fun does doesnt really metter, what metters is that if passed

array( "A", "B", "C")
or
array( "C", "B", "A")

fun will not produce same result. I need to pick the best result out of all possible results. So in this case I need to compare data from 6 different data sets:

array( "A", "B", "C")
array( "A", "C", "B")
array( "B", "A", "C")
array( "B", "C", "A")
array( "C", "A", "B")
array( "C", "B", "A")

that is 3! = 3 * 2 * 1 = 6 possible solutions

When data sample is so small as in this example there is no problems to this logic but lets imagine $b has only 10 elements. That gives us
10! = 10 * 9* 8 *7 *6 *5 *4 *3 *2 *1 = 3,628,800 possible solutions according to http://en.wikipedia.org/wiki/Factorial and that is sort of scenario I can expect with this application. Even better, I can expect number of elements to go over 1000 and 1000! is very very big number :))) so I need elegant solution (algorithm) as brutal force solution can be too brutal in this case.

I realize that this is maybe not the best place to post this problem as it is not strictly php problem but if I can only get a direction that would be much appreciated.

Thank You
Jan 21 '10 #1
3 1562
Atli
5,058 Expert 4TB
@zorgi
How exactly do you define "best"?
Jan 21 '10 #2
zorgi
431 Expert 256MB
How exactly do you define "best"?
Well, fun always returns an integer. I need to choose the highest.
Jan 21 '10 #3
Atli
5,058 Expert 4TB
I'm having a hard time seeing a way to work around having to "brute force" the entire list of possibilities. I mean, if you need to pick the highest fun() output out of a list of input values, you are going to have to run each of the inputs values through fun().

Unless you can eliminate some of the input values without running them through fun()? (Impossible to know, really, without knowing the fun() algorithm)

The best you could do is optimize how the return values of fun() are compared.
Jan 21 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jack Smith | last post by:
Hello, any help appreciated with following problem. I figured out the algorithm (I think), just having trouble proving it is optimal. Suppose we are given n tasks each of which takes 1 unit...
16
by: cody | last post by:
I have to write an algorithm with must ensure that objects are put in buckets (which are always 4 in size). The objects have two properties: A and B. It is not allowed that in a bucket are objects...
17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
10
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
2
by: Sherrie Laraurens | last post by:
Hi all, I'm trying to write a generic algorithm routine that will take begin and end iterators of a container, iterate through the range and perform a "calculation" of sorts. The trouble is...
2
by: Julio C. Hernandez Castro | last post by:
Dear all, We have just developped a new block cipher called Raiden, following a Feistel Network structure by means of genetic programming. Our intention now consists on getting as much feedback...
10
by: Sunway | last post by:
hello guys i have a bunsh of questions in java and algorithm most of them i didnt have a problem in them but two i had a diffculty in them could u help me in them please coz its urgent . the...
11
by: Dijkstra | last post by:
Hi folks! First, this is the code I'm using to expose the problem: ------------------------------------------------------------------ #include <functional> #include <string> #include...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.