C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Finding a maximal sorted subsequence

By : user2954353
Date : November 22 2020, 01:01 AM
To fix the issue you can do Assume that we're given a set of pairs S={(x_1,y_1),...,(x_n,y_n)} of integers. What is the most efficient way of computing a maximal sequence of elements (a_1,b_1),...,(a_m,b_m) in S with the property that , Yes, it is possible to do it O(n log n).
code :

Share :

## LINQ: Finding maximal element (not maximal value)

By : BRusinov
Date : March 29 2020, 07:55 AM
Jon Skeet has MaxBy in his MoreLINQ library: http://code.google.com/p/morelinq
code :
``````e.OrderByDescending(x => x.SomeProperty).First();
``````

## subsequence of numbers with maximal sum, solution isn't clear

By : Tiffanymiau
Date : March 29 2020, 07:55 AM
With these it helps So as you stated, you iterate over the array in one loop and accumulate sum S. On each step you do S += a[i] and you compare your S to current maximum like max = Math.max(S, a[i]).
Your question is why should we zero S when S < 0. Let's say it happened on step i. Then (S + a[i+1]) < a[i+1] (because S < 0). Since we are looking for maximum subsequent sum its better to start new subsequence from a[i+1] i.e. set S = 0.

## How does finding a Longest Increasing Subsequence that ends with a particular element leads to the solution of finding L

By : David Amram
Date : March 29 2020, 07:55 AM
hope this fix your issue I have understood that to find the solution of LIS problem, we need to find a LIS for every subsequence starting from initial element of the array to the each element that ends with a particular element(the last element), but I am not able to understand how would that help in finally finding a LIS of a given unsorted array, I also understand that this leads to an optimal substructure property and then can be solved, but as mentioned, I dont see how finding LIS(j) that ends with arr[j] will help us. , Consider this sequence as an example:
code :
``````a[]   : 10 20  1  2  5 30  6  8 50  5  7
``````
``````a[]   : 10 20  1  2  5 30  6  8 50  5  7
LIS[] :  1  2  1  2  3  4  4  5  6  3  4
``````
``````50  8  6  5  2  1
``````
``````1 2 5 6 8 50
``````

## Why am I finding the longest increasing subsequence instead of the longest decreasing subsequence?

By : Juan Sarmiento O
Date : March 29 2020, 07:55 AM
I hope this helps . If you are open to any way of looking at it, Wikipedia has some pseudocode which transferred easily into Python and flipped for decreasing subsequence.
code :
``````N = len(X)
P = np.zeros(N, dtype=np.int)
M =  np.zeros(N+1, dtype=np.int)

L = 0
for i in range(0, N-1):
# Binary search for the largest positive j ≤ L
# such that X[M[j]] <= X[i]
lo = 1
hi = L
while lo <= hi:
mid = (lo+hi)//2

if X[M[mid]] >= X[i]:
lo = mid+1
else:
hi = mid-1
# After searching, lo is 1 greater than the
# length of the longest prefix of X[i]
newL = lo

# The predecessor of X[i] is the last index of
# the subsequence of length newL-1
P[i] = M[newL-1]
M[newL] = i
#print(i)
if newL > L:
# If we found a subsequence longer than any we've
# found yet, update L
L = newL

# Reconstruct the longest increasing subsequence
S = np.zeros(L, dtype=np.int)
k = M[L]
for i in range(L-1, -1, -1):
S[i] = X[k]
k = P[k]

S
``````
``````array([38, 20, 15, 14,  6])
``````

## Length of the longest sorted subsequence

By : Anton Emelyanov
Date : March 29 2020, 07:55 AM
wish helps you This is called the Longest Ascending Subsequence problem. You can find it using a simple dynamic programming algorithm described in the article.
If all you need is the length of the longest subsequence, you can do it like this: