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

  • Home
  • SEARCH
  • 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 6834457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:06:51+00:00 2026-05-26T23:06:51+00:00

Background in case you care, if not skip it: I was recording some audio

  • 0

Background in case you care, if not skip it:

I was recording some audio today for a project, doing it a paragraph at a time. If I messed up the paragraph, I redid it until I got it right, and then moved on the next paragraph. When I loaded them onto the computer, I needed to find the last recording for each paragraph. Without any knowledge of the number of recordings I made for a particular paragraph, how do I go about this? (Don’t you love it when algorithms sneak up into your daily life?)

In algorithms terms, you have an array of elements, where each element is either followed by another element of the same type, or a completely different element. Find each last element of the sequence (the audio clip correctly recorded).

The problem:

So you have an array of objects where each element with an id field, where each id is in the following list. I want the objects that are the last of their id, say in array of id’s like this:

aabbbbbccddddddddddddddeefffffffffggghhhhiiiijjklmnnnnoo

Obviously if the length of the string is n and there are n distinct elements, it will take you n steps to figure it out. I’m more interested in the general algorithm. I could do it with a binary search type algorithm, but I don’t know the runtime of it in the case with no knowledge of the input except the number of total elements.

Also, would knowing the number of distinct id’s change the runtime of the algorithm? This is an interesting problem to me and I’m asking to only satisfy my intellectual curiosity.

  • 1 1 Answer
  • 0 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-26T23:06:52+00:00Added an answer on May 26, 2026 at 11:06 pm

    You should be able to look at the first id, and do a binary search for where that id ends. This can be done in O(log n) time.

    You then step forward to the next element, and redo the binary search for where that id-sequence ends.

    This yields an algorithm of complexity O(m × log n) where n is the number of elements and m the number of distinct elements.

    Assuming n / m (the average number of elements for a specific id) is greater than log n you get a sub-linear algorithm.

    If n / m is less than log n you are better of searching for the end of the id-sequence linearly.

    (Note that this whole analysis depends on the fact that the list is sorted on the IDs. Sorting typically takes time proportional to n × log n so if you need to sort them, you can just as well go with a linear algorithm 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some background.... We're venturing into Azure for the first time and are trying to
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
Background: As a short project over winter break, I'm trying to implement a programming
first time posting here. I'm a beginner in jquery and i ran into some
I want to change ImageView background (in my case gradient color) using selector state
Here is a bit of background just in case there is a different/better way
The two paragraphs after this are background information in case I'm thinking of this
Background : I wanted to distribute a library to some other developers (something along
I'm trying to set the background color of a View (in this case a
I am having problem with displaying div's background overflow in IE (in my case

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.