Click here to Skip to main content
16,007,809 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: analysis of boolean table to optimize code ? Pin
Gerry Schmitz3-Nov-15 8:28
mveGerry Schmitz3-Nov-15 8:28 
AnswerRe: analysis of boolean table to optimize code ? Pin
Patrice T3-Nov-15 17:09
mvePatrice T3-Nov-15 17:09 
Questiongrid search Pin
Member 1208345324-Oct-15 0:21
Member 1208345324-Oct-15 0:21 
AnswerRe: grid search Pin
Patrice T24-Oct-15 22:12
mvePatrice T24-Oct-15 22:12 
AnswerRe: grid search Pin
Richard MacCutchan24-Oct-15 22:48
mveRichard MacCutchan24-Oct-15 22:48 
AnswerRe: grid search Pin
BillWoodruff30-Oct-15 23:10
professionalBillWoodruff30-Oct-15 23:10 
QuestionA max profit question Pin
JStagg14-Oct-15 23:15
JStagg14-Oct-15 23:15 
AnswerRe: A max profit question Pin
Eddy Vluggen20-Oct-15 7:39
professionalEddy Vluggen20-Oct-15 7:39 
QuestionHow can I found max of multiplication of subtree nodes? Pin
mortalphilosopher11-Oct-15 19:56
mortalphilosopher11-Oct-15 19:56 
GeneralRe: How can I found max of multiplication of subtree nodes? Pin
harold aptroot11-Oct-15 21:54
harold aptroot11-Oct-15 21:54 
AnswerRe: How can I found max of multiplication of subtree nodes? Pin
Patrice T13-Oct-15 10:09
mvePatrice T13-Oct-15 10:09 
GeneralRe: How can I found max of multiplication of subtree nodes? Pin
mortalphilosopher13-Oct-15 23:28
mortalphilosopher13-Oct-15 23:28 
GeneralRe: How can I found max of multiplication of subtree nodes? Pin
Matt T Heffron14-Oct-15 8:09
professionalMatt T Heffron14-Oct-15 8:09 
QuestionData selection and classification algorithms Pin
Member 120412687-Oct-15 13:15
Member 120412687-Oct-15 13:15 
SuggestionRe: Data selection and classification algorithms Pin
Matt T Heffron7-Oct-15 14:29
professionalMatt T Heffron7-Oct-15 14:29 
GeneralRe: Data selection and classification algorithms Pin
Member 120412687-Oct-15 16:55
Member 120412687-Oct-15 16:55 
QuestionHow you gonna start with this question? Pin
lebanner6-Oct-15 14:52
lebanner6-Oct-15 14:52 
AnswerRe: How you gonna start with this question? Pin
Afzaal Ahmad Zeeshan6-Oct-15 22:14
professionalAfzaal Ahmad Zeeshan6-Oct-15 22:14 
AnswerRe: How you gonna start with this question? Pin
Sreram K8-Oct-15 7:17
Sreram K8-Oct-15 7:17 
To start with, I would think about a brute force approach, and narrow it down by adding more rules.

Make your algorithm start with 123456789
In the next iteration, make your algorithm obtain: 12345678*9
Next obtain, 12345678+9
and 1234567*89, 1234567+89, 1234567*8*9, 1234567*8+9,... and so on  


If you write an algorithm to fill this series, you can easily see that there are 3^8 possibilities! It might look long enough but it actually is not! I took "three" because there are three possible states: 1. No operation, 2. addition, 3. multiplication. And there are 8 ways you can insert the arithmetic symbols, which is always in-between two numbers.

Now, though the value 3^8 = 6561 is very less, computing huge values won't do any good. What other information do we have? There can't be a '-' sign! That's a good clue. Because, now we know for sure that the value can't reduce and computing values such as 12345*6789 can't be always feasible. So, if there is a number in the expression greater than the required number, from your example, if there is a number greater than 100 in the expression, you don't have to compute the expression to know it is not equal. Simply checking for the "greater than" would help.

Now, we have made the problem shorter, starting with an inefficient brute force algorithm! Now lets make it even shorter. Did you observe that if the entered number is 100, the first few elements in the series would definitely not hold? Let's create a function,
term f(int x) // returns the term, given the term number.

to which if you pass on the term-number you could automatically obtain the element in O(1) time. I call it O(1) because the moment you convert the base-10 number passed on as an integer to the function f to a base-3 number, you have your term! Now each digit of the newly obtained number either becomes + or * or "nothing", and with this we may construct our term. Let's now define rules to skip every term containing numbers greater than 100. To do this, lets speculate and find the term that is at the 1000'th place in the series. Depending on whether the series is greater or lesser, move forwards or backwards in the series (if you are willing to find at-least one solution, or switch to brute force if you want to find all the possible answers).

This is how I would start with the problem. And I would write a quick code and test my hypothesis, and add on more rules to it and make it even more optimized.
AnswerRe: How you gonna start with this question? Pin
Patrice T8-Oct-15 11:47
mvePatrice T8-Oct-15 11:47 
GeneralRe: How you gonna start with this question? Pin
Matt T Heffron8-Oct-15 14:23
professionalMatt T Heffron8-Oct-15 14:23 
GeneralRe: How you gonna start with this question? Pin
Stanley_B70716-Oct-15 5:18
Stanley_B70716-Oct-15 5:18 
AnswerRe: How you gonna start with this question? Pin
Matt T Heffron20-Oct-15 7:05
professionalMatt T Heffron20-Oct-15 7:05 
QuestionWhy is Dijkstra's algorithm implemented with a priority queue O(|E| + |v|log|V|)? Shouldn't it be O(|V|^2)? Pin
Sreram K5-Oct-15 4:45
Sreram K5-Oct-15 4:45 
AnswerRe: Why is Dijkstra's algorithm implemented with a priority queue O(|E| + |v|log|V|)? Shouldn't it be O(|V|^2)? Pin
Sreram K8-Oct-15 7:32
Sreram K8-Oct-15 7:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.