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 8521277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:46:40+00:00 2026-06-11T06:46:40+00:00

I have a bunch of (date)intervals which might overlap. The intervals come from different

  • 0

I have a bunch of (date)intervals which might overlap. The intervals come from different sources. I want to ‘flatten’ this ‘timeline’ and then find all intervals where no interval was.

If you look at: http://www.dgp.toronto.edu/people/JamesStewart/378notes/22intervals/
to the “A more complex example” section. I thus want to find the intervals where no composer was alive.

How do I do that? and how would you implement such a thing in PHP?
Does PHP also have some easy functions for building the tree?

many thx!

edit
My input is a number of arrays (2, 3 or 4) with each containing start and stop dates like so:

 $myarray1[0]['start']['date'] = 'somedate'
 $myarray1[0]['stop']['date'] = 'somedate'
 $myarray1[1]['start']['date'] = 'somedate'
 $myarray1[1]['stop']['date'] = 'somedate'
 $myarray1[2]['start']['date'] = 'somedate'
 $myarray1[2]['stop']['date'] = 'somedate'

the same goes for myarray2, myarray3 and so

  • 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-06-11T06:46:41+00:00Added an answer on June 11, 2026 at 6:46 am

    Basic algorithm

    For each composer, create two objects. One is a birth object with the composer’s name and the year of birth. The other is a death object, again with the composer’s name and the year of death.

    Now sort these objects together.

    Keep an int, initialised to 0 for num_composers_alive.

    Iterate through the ordered list of objects. Every time you encounter a birth object, increment num_composers_alive. Every time you encounter a death object, decrement num_composers_alive.

    While incrementing or decrementing, every time you hit a death and decrement, check if num_composers_alive went to 0. If so, you just entered a period when no composer was alive. Output that number or store it somewhere. Every time you hit a birth and increment, check if num_composers_alive is now 1. If so, you just ended a period when no composer was alive. Output that number or store it somewhere.

    Implementation

    This is going to depend on the form of your input and output. I don’t believe PHP has a native concept of trees, but I might be wrong on that. Try implementing the above, and open a separate question if you get stuck.

    To be honest, I’m not sure why you need trees to solve the above problem anyway, but maybe it’s for something else.

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

Sidebar

Related Questions

I have bunch of temporal data which I want to convert to RDF format.
My query is this. I have a bunch of entries and i want to
I have some data in an Excel spreadsheet, which represents a bunch of date-times
I have a bunch of entries in a database, which I want to sort
I have a bunch of objects that have a value and a date field:
I have bunch of strings, some of which are fairly long, like so: movie.titles
I have bunch of lists like this: out[3] [[3]] [1] forum=28&mid=11883 [2] forum=29&mid=11884 out[4]
We have bunch of Domain Entities which should be rendered to an html format,
I have a bunch of files in a folder checked out from a repository.
I have a bunch of html files that come with my app and are

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.