How to optimize a method written in Java using any of the Algorithm or Data Structure technique? [duplicate]

Multi tool use
Multi tool use











up vote
-1
down vote

favorite













This question already has an answer here:




  • Given a set of rectangles, do any overlap?

    3 answers



  • find overlapping rectangles algorithm

    12 answers




I have a list of rectangles sorted by priority.



While we iterate this List, I will insert a rectangle element into a Set. This set includes discrete rectangles. It means that all rectangles in Set should not overlap each other.



The below code has O(n^2) time complexity. But there seems to be a better way.



public Collection<Box> removeOverlapping(Collection<Box> boxList) {
Collection<Box> boxListRemovedOverlapping = new LinkedList<>();
for (Box box : boxList) {
boolean overlapping = false;
for (Box compBox : boxListRemovedOverlapping) {
if (isBoxOverlapped(box, compBox)) {
overlapping = true;
break;
}
}
if (!overlapping) {
boxListRemovedOverlapping.add(box);
}
}
return boxListRemovedOverlapping;
}









share|improve this question















marked as duplicate by Andreas java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 at 5:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • "But there seems to be a better way" What way would that be, and if so, why didn't you use it?
    – Andreas
    Nov 13 at 5:26












  • What is condition of overlapped box?
    – htpvl
    Nov 13 at 5:31










  • @Andreas I am looking for it.
    – Bongousse
    Nov 13 at 5:32












  • @htpvl The overlapped means one box includes the other or intersects with it.
    – Bongousse
    Nov 13 at 5:33












  • Consider some BSP data structure like R-tree
    – MBo
    Nov 13 at 5:33

















up vote
-1
down vote

favorite













This question already has an answer here:




  • Given a set of rectangles, do any overlap?

    3 answers



  • find overlapping rectangles algorithm

    12 answers




I have a list of rectangles sorted by priority.



While we iterate this List, I will insert a rectangle element into a Set. This set includes discrete rectangles. It means that all rectangles in Set should not overlap each other.



The below code has O(n^2) time complexity. But there seems to be a better way.



public Collection<Box> removeOverlapping(Collection<Box> boxList) {
Collection<Box> boxListRemovedOverlapping = new LinkedList<>();
for (Box box : boxList) {
boolean overlapping = false;
for (Box compBox : boxListRemovedOverlapping) {
if (isBoxOverlapped(box, compBox)) {
overlapping = true;
break;
}
}
if (!overlapping) {
boxListRemovedOverlapping.add(box);
}
}
return boxListRemovedOverlapping;
}









share|improve this question















marked as duplicate by Andreas java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 at 5:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • "But there seems to be a better way" What way would that be, and if so, why didn't you use it?
    – Andreas
    Nov 13 at 5:26












  • What is condition of overlapped box?
    – htpvl
    Nov 13 at 5:31










  • @Andreas I am looking for it.
    – Bongousse
    Nov 13 at 5:32












  • @htpvl The overlapped means one box includes the other or intersects with it.
    – Bongousse
    Nov 13 at 5:33












  • Consider some BSP data structure like R-tree
    – MBo
    Nov 13 at 5:33















up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:




  • Given a set of rectangles, do any overlap?

    3 answers



  • find overlapping rectangles algorithm

    12 answers




I have a list of rectangles sorted by priority.



While we iterate this List, I will insert a rectangle element into a Set. This set includes discrete rectangles. It means that all rectangles in Set should not overlap each other.



The below code has O(n^2) time complexity. But there seems to be a better way.



public Collection<Box> removeOverlapping(Collection<Box> boxList) {
Collection<Box> boxListRemovedOverlapping = new LinkedList<>();
for (Box box : boxList) {
boolean overlapping = false;
for (Box compBox : boxListRemovedOverlapping) {
if (isBoxOverlapped(box, compBox)) {
overlapping = true;
break;
}
}
if (!overlapping) {
boxListRemovedOverlapping.add(box);
}
}
return boxListRemovedOverlapping;
}









share|improve this question
















This question already has an answer here:




  • Given a set of rectangles, do any overlap?

    3 answers



  • find overlapping rectangles algorithm

    12 answers




I have a list of rectangles sorted by priority.



While we iterate this List, I will insert a rectangle element into a Set. This set includes discrete rectangles. It means that all rectangles in Set should not overlap each other.



The below code has O(n^2) time complexity. But there seems to be a better way.



public Collection<Box> removeOverlapping(Collection<Box> boxList) {
Collection<Box> boxListRemovedOverlapping = new LinkedList<>();
for (Box box : boxList) {
boolean overlapping = false;
for (Box compBox : boxListRemovedOverlapping) {
if (isBoxOverlapped(box, compBox)) {
overlapping = true;
break;
}
}
if (!overlapping) {
boxListRemovedOverlapping.add(box);
}
}
return boxListRemovedOverlapping;
}




This question already has an answer here:




  • Given a set of rectangles, do any overlap?

    3 answers



  • find overlapping rectangles algorithm

    12 answers








java algorithm data-structures collections






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 at 6:46









Abhinav

296111




296111










asked Nov 13 at 5:24









Bongousse

214




214




marked as duplicate by Andreas java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 at 5:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Andreas java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 at 5:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • "But there seems to be a better way" What way would that be, and if so, why didn't you use it?
    – Andreas
    Nov 13 at 5:26












  • What is condition of overlapped box?
    – htpvl
    Nov 13 at 5:31










  • @Andreas I am looking for it.
    – Bongousse
    Nov 13 at 5:32












  • @htpvl The overlapped means one box includes the other or intersects with it.
    – Bongousse
    Nov 13 at 5:33












  • Consider some BSP data structure like R-tree
    – MBo
    Nov 13 at 5:33




















  • "But there seems to be a better way" What way would that be, and if so, why didn't you use it?
    – Andreas
    Nov 13 at 5:26












  • What is condition of overlapped box?
    – htpvl
    Nov 13 at 5:31










  • @Andreas I am looking for it.
    – Bongousse
    Nov 13 at 5:32












  • @htpvl The overlapped means one box includes the other or intersects with it.
    – Bongousse
    Nov 13 at 5:33












  • Consider some BSP data structure like R-tree
    – MBo
    Nov 13 at 5:33


















"But there seems to be a better way" What way would that be, and if so, why didn't you use it?
– Andreas
Nov 13 at 5:26






"But there seems to be a better way" What way would that be, and if so, why didn't you use it?
– Andreas
Nov 13 at 5:26














What is condition of overlapped box?
– htpvl
Nov 13 at 5:31




What is condition of overlapped box?
– htpvl
Nov 13 at 5:31












@Andreas I am looking for it.
– Bongousse
Nov 13 at 5:32






@Andreas I am looking for it.
– Bongousse
Nov 13 at 5:32














@htpvl The overlapped means one box includes the other or intersects with it.
– Bongousse
Nov 13 at 5:33






@htpvl The overlapped means one box includes the other or intersects with it.
– Bongousse
Nov 13 at 5:33














Consider some BSP data structure like R-tree
– MBo
Nov 13 at 5:33






Consider some BSP data structure like R-tree
– MBo
Nov 13 at 5:33



















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

PZQj8xzt,TcBkby1Z8a,HJD4E3Q9rJRKawfci2B0n5iEcK38UJkYVdjW3,LgnG5S
YqJN3EE1pceIwrFD3G2K7TGc,IduGZ4LW4KFBqN7h,E4gEJoYMXH7Lcw4aMhOaLUKZ H5B4FIc6

Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

Multiple Hosts connection in Hyperledger Fabric

How to send String Array data to Server using php in android