|
Ok i got your point since the both intervals should have start data end date
and since these intervals should be valid intervals( startdate< enddate)
the only cond i should check is if the first interval's end date is before the second interval start date
and vise verse.
thanks
|
|
|
|
|
khalil.kamel wrote: the only cond i should check is if the first interval's end date is before the second interval start date
and vise verse.
Why vice versa!
After sorting these are the possible output
---first----------
---second----
---first----------
---second----
---first----------
---second----
All are covered by only one check (first's end >= second's start).
Eslam Afifi
|
|
|
|
|
It can also be that
-----------first-----------
---------second-----------
Just to be complete. So I think it is another small check, but in total not difficult.
Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
|
|
|
|
|
It can also appear that the second starts first, but still overlaps the first. Or not overlapping the first.
So I would check both not just first end and second start.
Just to be complete.
Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
|
|
|
|
|
Thank you for your reply.
Eslam Afifi wrote: first = the one that has the minimum start date
second = the other one
Eslam Afifi wrote: After sorting these are the possible output
In that case, the second becomes the first before applying the overlapping check. Or did I misunderstood your message?
Eslam Afifi
|
|
|
|
|
first define "first"
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
Yes sorry had a bad time yesterday. Simply overhead this stuff.
Can happen.
Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
|
|
|
|
|
No problem. It happens all the time. Have a great day
Eslam Afifi
|
|
|
|
|
Thanks
You too.
Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
|
|
|
|
|
Why do you even need an algorithm for this?
If you have the pairs (A,B) and (C,D) (assuming the enddate is always after the startdate - if not just swap them)
return (A > C && A < D) || C < B;
works because:
two cases are handled:
1) A is after C, they only overlap if A is also before D otherwise (A,B) is completely after (C,D)
2) A is before C, they only overlap if C is somewhere before B otherwise (C,D) is completely after (A,B)
disclaimer: it was 2 AM when I wrote this, it could easily be complete crap. Sorry!
|
|
|
|
|
will am asking this question becuase i need to take care of my performance issue. taking into concideration
that there are many date intervals i should check and your code ( my old code ) is not good at that scenario regardin performance
|
|
|
|
|
I severely doubt there is a faster way. If, however, you are checking overlap on many dates at once (which I suspect you are, because you are having a performance issue with it), there is a better algorithm than a naive "O(n*n) tests" algorithm. I don't remember it now, but I'm quite sure it exists..
|
|
|
|
|
If you mean that you're checking more than 2 intervals at the same time you can sort them by start date ascending (complexity depends on the choosen sorting algorithm) then loop over them and check with the next interval for the next's start date < current's end date (O(n) complexity).
And you're welcome.
Eslam Afifi
|
|
|
|
|
bool overlap=(start2>=start1 && start2<end1) ||
(start1>=start2 && start1<end2);
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
As far as I recall, I make only two comparisons: ( Start1 <= End2 ) && ( End1 >= Start2 )
I believe that properly handles all the possible situations.
|
|
|
|
|
That looks great.
However I would rewrite it as ( Start1 <= End2 ) && (Start2 <= End1 ) to stress symmetry, which should be present in the expression.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Tomahto!
|
|
|
|
|
Nah. It is tomato, you do know that.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Well Yes I think this covers all possible cases , anyways am going to implement it again in my work since it is stated as a buggggggggggggg , and i will reply back for all of you if there is any scenario that this cases doesnt cover,
|
|
|
|
|
Hi,
you can trust PIEBALD to give good advise.
and you can verify for yourself there are only five cases, which you can easily check by hand.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I thought there were 6 cases?
0) S1 E1 S2 E2 (1 entirely before 2)
1) S1 S2 E1 E2 (1 halfway before 2, partly overlapping)
2) S2 S1 E1 E2 (1 contained within 2)
3) S2 S1 E2 E1 (1 partly contained within 2, partly extending beyond it)
4) S2 E2 S1 E1 (1 entirely after 2)
5) S1 S2 E2 E1 (case 2 inverted - 2 contained within 1)
Did I do something wrong?
|
|
|
|
|
That is a valid stance.
However if you call the larger one S1-E1 then your #2 cannot occur. And the 5 remaining cases are all really distinct.
That is an advantage of symmetric problems given symmetric solutions: you tend to get fewer cases.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Ah yes that's true thanks
edit: no wait, that's an extra comparison, cheaters
So it's still 3, unless you already known they are ordered.. Last modified: 42hrs 13mins after originally posted --
|
|
|
|
|
Hello,
An encryption program produces the following output for a text input
HlNmVaGYVPE!
nNCDp6cR19bsiplYwcVklA!!
Zlv417YGpmY!
just seeing if it is possible to know what kind of encryption is used to encrypt the data ?
modified on Monday, July 6, 2009 4:15 PM
|
|
|
|