Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 909365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:51:57+00:00 2026-05-15T16:51:57+00:00

Let us presume we have k sequences of fixed length p . Each sequence

  • 0

Let us presume we have k sequences of fixed length p. Each sequence has double values in range 0 to 1.0. For simplicity let us also assume that the sequences are just arrays; in the real implementation, they will be list.

Now, the algorithm needs to find the smallest index the value of which represents a “major upset” in a given sequence. This upset can be a value of 1.0 or a value that goes over a certain threshold (e.g. 0.2). If, for example, moving from j-1 to j the value increases over the threshold, then the index we seek would be j-1.

The upset of 1.0 takes precedence over the threshold value; for instance, if we find an index matching the threshold, we should still check the sequence for containing 1.0.

Finally, the algorithm should produce the smallest index that resulted in the upset.
I have quickly put together some code to test the concept and show you the sort of thing I am after. What I am looking for is a possibly more efficient implementation as this algorithm is going to be executed pretty extensively.

List<double[]> nearCaptures = new ArrayList<double[]>();
double threshold = 0.2;
double majorUpset = 1.0;
int[] indexes = new int[nearCaptures.size()];
for (int i = 0; i < nearCaptures.size(); i++) {
    int index = 0;
    double[] tempArray = nearCaptures.get(i);
    Arrays.sort(tempArray);
    int tempIndex = Arrays.binarySearch(tempArray, majorUpset);
    if (tempIndex > 0) {
        for (int j = 1; j < nearCaptures.get(0).length; j++) {
            if (nearCaptures.get(i)[j] == majorUpset) {
                index = j-1;
                break;
            }
        }
    } else {
        for (int j = 1; j < nearCaptures.get(0).length; j++) {
            if (nearCaptures.get(i)[j] >= nearCaptures.get(i)[j-1] + threshold) {
                index = j-1;
                break;
            }
        }
    }
    indexes[i] = index;
}
Arrays.sort(indexes);
System.out.println(indexes[0]);
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:51:58+00:00Added an answer on May 15, 2026 at 4:51 pm

    Some hints for improving performance (and correctness):

    • When looking for a majorUpset, you perform a sort and a binary search, resulting in O(n log(n)) runtime, followed by a linear search (the for loop). That linear search would be all you need to find whether and where there is a majorUpset.

    • Since tempArray refers to the original array, you mess up your indices when you sort it. If you needed to sort, sort a copy. But as noted above, you won’t need to sort.

    • You access the value nearCaptures.get(i) several times in a loop, where it would be better to store it in a local variable, right at the beginning of the i-loop.

    Addition:

    You might want to perform the search in parallel, because then you can stop as soon as you have found the smallest upset index in any of the arrays.

    int p = nearCaptures.get(0).length;  // p is the common array length
    // search for majorUpset
    for(int j = 0; j < p; j++){
      for (double[] arr : nearCaptures) {
        if (arr[j]==majorUpset) return j; // first majorUpset
      }
    }
    // search for threshold
    for(int j = 1; j < p; j++){
      for (double[] arr : nearCaptures) {
        if (arr[j]>arr[j-1]+threshold) return j-1; // first threshold
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a curl class, called Curl. Let's presume i have this code: $url
Let's presume that I have string like '=&?/;#+%' to be a part of my
Let's presume that we have a t1 table where the integer weight column is
Let us presume I have the following object defined: var myObj = function(){ this.hello
Let's say I have two objects, Master and Slave . Slave has a method
Let presume we have something like this: <div1> <h1>text1</h1> <h1>text2</h1> </div1> <div2> <h1>text3</h1> </div2>
Let's presume I have objects stored in MongoDB with the following structure: Transaction {
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.