Click here to Skip to main content
15,885,757 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Longest subarray: minimum first element, maximum last element Pin
Member 105660898-Feb-17 10:10
Member 105660898-Feb-17 10:10 
GeneralRe: Longest subarray: minimum first element, maximum last element Pin
Patrice T8-Feb-17 10:56
mvePatrice T8-Feb-17 10:56 
GeneralRe: Longest subarray: minimum first element, maximum last element Pin
Member 105660898-Feb-17 15:15
Member 105660898-Feb-17 15:15 
QuestionAccounting aging algorithm help Pin
kimbhoot26-Jan-17 5:52
kimbhoot26-Jan-17 5:52 
AnswerRe: Accounting aging algorithm help Pin
Gerry Schmitz26-Jan-17 7:08
mveGerry Schmitz26-Jan-17 7:08 
GeneralRe: Accounting aging algorithm help Pin
kimbhoot26-Jan-17 10:51
kimbhoot26-Jan-17 10:51 
GeneralRe: Accounting aging algorithm help Pin
Gerry Schmitz26-Jan-17 11:04
mveGerry Schmitz26-Jan-17 11:04 
GeneralSo I Wrote A Backward Version Of KMP Algorithm In C# That Searches String From Right Pin
Robert Vandenberg Huang9-Jan-17 18:30
professionalRobert Vandenberg Huang9-Jan-17 18:30 
C#
public static int LastIndexOf<T>(this IReadOnlyList<T> s, IReadOnlyList<T> t, int startIndex,
    IEqualityComparer<T> comparer) where T : IEquatable<T>
{
    Validate(s, t, startIndex);

    // Follow the behavior of string.LastIndexOf(string) method.
    if (t.Count == 0) return 0;
    if (s.Count == 0 || s.Count < t.Count) return -1;

    if (comparer == null) comparer = EqualityComparer<T>.Default;
    if (t.Count == 1) return LastIndexOf(s, t[0], startIndex, comparer);

    var table = BuildTable(t, comparer);
    var i = 0;

    while (startIndex - i >= 0)
    {
        if (comparer.Equals(t[t.Count - i - 1], s[startIndex - i]))
        {
            if (i == t.Count - 1)
                return startIndex - t.Count + 1;
            i++;
        }
        else
        {
            if (table[i] > -1)
            {
                startIndex -= i;
                i = table[i];
            }
            else
            {
                startIndex--;
                i = 0;
            }
        }
    }
    return -1;
}


Full source code can be seen here[^].

The method works like String.LastIndexOf which searches string from the last character. The BuildTable method is exactly same with normal KMP algorithm.

I'm not sure if this is the best solution though.
GeneralRe: So I Wrote A Backward Version Of KMP Algorithm In C# That Searches String From Right Pin
Gerry Schmitz26-Jan-17 7:18
mveGerry Schmitz26-Jan-17 7:18 
QuestionMachine Learning for a translation algorithm between numbers and words Pin
Member 1291942623-Dec-16 4:52
Member 1291942623-Dec-16 4:52 
AnswerRe: Machine Learning for a translation algorithm between numbers and words Pin
Richard MacCutchan23-Dec-16 5:06
mveRichard MacCutchan23-Dec-16 5:06 
GeneralRe: Machine Learning for a translation algorithm between numbers and words Pin
Member 1291942623-Dec-16 5:37
Member 1291942623-Dec-16 5:37 
GeneralRe: Machine Learning for a translation algorithm between numbers and words Pin
Nathan Minier23-Dec-16 6:19
professionalNathan Minier23-Dec-16 6:19 
GeneralRe: Machine Learning for a translation algorithm between numbers and words Pin
Member 1291942623-Dec-16 16:00
Member 1291942623-Dec-16 16:00 
GeneralRe: Machine Learning for a translation algorithm between numbers and words Pin
Gerry Schmitz23-Dec-16 6:26
mveGerry Schmitz23-Dec-16 6:26 
GeneralRe: Machine Learning for a translation algorithm between numbers and words Pin
Member 1291942623-Dec-16 16:00
Member 1291942623-Dec-16 16:00 
GeneralRe: Machine Learning for a translation algorithm between numbers and words Pin
Richard MacCutchan23-Dec-16 6:56
mveRichard MacCutchan23-Dec-16 6:56 
GeneralRe: Machine Learning for a translation algorithm between numbers and words Pin
Member 1291942623-Dec-16 16:04
Member 1291942623-Dec-16 16:04 
GeneralRe: Machine Learning for a translation algorithm between numbers and words Pin
Richard MacCutchan23-Dec-16 21:37
mveRichard MacCutchan23-Dec-16 21:37 
GeneralTiny Encryption Algorithm Pin
Rhonnn12-Dec-16 20:45
Rhonnn12-Dec-16 20:45 
AnswerRe: Tiny Encryption Algorithm Pin
Kornfeld Eliyahu Peter12-Dec-16 21:13
professionalKornfeld Eliyahu Peter12-Dec-16 21:13 
AnswerRe: Tiny Encryption Algorithm Pin
Patrice T14-Dec-16 12:37
mvePatrice T14-Dec-16 12:37 
QuestionTiny Encryption Algorithm Pin
Rhonnn12-Dec-16 21:36
Rhonnn12-Dec-16 21:36 
AnswerRe: Tiny Encryption Algorithm Pin
Richard MacCutchan12-Dec-16 21:50
mveRichard MacCutchan12-Dec-16 21:50 
AnswerRe: Tiny Encryption Algorithm Pin
Patrice T14-Dec-16 12:36
mvePatrice T14-Dec-16 12:36 

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.