[algogeeks] Re: longest common subsequence problem
you can store the two strings in an upside down suffix tree. a simple edge scan of common path will give you all possible (and largest) common substring
[algogeeks] Re: Given an array containing both positive and negative integers, we r required to find the sub-array with the largest sum
Think of the negative numbers as consumers from a warehouse and positive numbers as producers from the warehouse. The problem reduces to plotting the inventory (starting from time = 0 to time = n) and then finding the max amplitude over time axis in +ve quadrant of the inventory profile which can be done in O(n).
[algogeeks] Re: longest common subsequence problem
In perl (hopefully the homework has been due already)... use strict; our %memo; sub lcs { my ($x, $y) = @_; my $key = $x|$y; return $memo{$key} if defined $memo{$key}; my $s = ''; for (my $i = 0; $i length($x); $i++) { for (my $j = 0; $j length($y); $j++) { if (substr($x, $i, 1) eq substr($y, $j, 1)) { my $t = lcs(substr($x, 0, $i), substr($y, 0, $j)) . substr($x, $i, 1) . lcs(substr($x, $i+1), substr($y, $j+1)); $s = $t if length($t) length($s); } } } $memo{$key} = $s; return $s; } print lcs(now is the time for all good men to come to the aid, there are few good men who will aid women);
[algogeeks] Re: Newcomer to neural networks
Thanks a lot Jeff and Mattia I'll get back as soon as I have studied some Rohit