Click here to Skip to main content
15,886,919 members
Home / Discussions / Algorithms
   

Algorithms

 
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 
QuestionPlease explain Shell Sort Algorithm Pin
Member 1176097730-Sep-15 16:55
Member 1176097730-Sep-15 16:55 
AnswerRe: Please explain Shell Sort Algorithm Pin
Richard Andrew x641-Oct-15 4:41
professionalRichard Andrew x641-Oct-15 4:41 
AnswerRe: Please explain Shell Sort Algorithm Pin
Patrice T2-Oct-15 15:28
mvePatrice T2-Oct-15 15:28 
GeneralRe: Please explain Shell Sort Algorithm Pin
Member 121089222-Nov-15 20:40
Member 121089222-Nov-15 20:40 
AnswerRe: Please explain Shell Sort Algorithm Pin
Patrice T2-Nov-15 21:10
mvePatrice T2-Nov-15 21:10 
QuestionAlgoritmo de Ford Fulkerson Pin
Josevas28-Sep-15 9:55
Josevas28-Sep-15 9:55 
SuggestionRe: Algoritmo de Ford Fulkerson Pin
Matt T Heffron28-Sep-15 13:04
professionalMatt T Heffron28-Sep-15 13:04 
AnswerRe: Algoritmo de Ford Fulkerson Pin
Richard Deeming29-Sep-15 1:54
mveRichard Deeming29-Sep-15 1:54 
QuestionChecking whether a directed graph is a unique path graph Pin
Member 119734749-Sep-15 22:49
Member 119734749-Sep-15 22:49 
AnswerRe: Checking whether a directed graph is a unique path graph Pin
Patrice T12-Sep-15 2:32
mvePatrice T12-Sep-15 2:32 
QuestionGet X Axis label and interval Pin
NJdotnetdev3-Sep-15 7:21
NJdotnetdev3-Sep-15 7:21 

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.