I'm reading about PriorityQueues in javadocs and it mentions the term tie-breaking. I couldn't undersand what does the term mean. I hope someone could explain.
In Java, comparison is done using a compare(a,b) method (for comparators) or a.compareTo(b) method (for class instances that can be compared). This method is supposed to return a negative number whenever a < b, a positive number when a > b, and 0 when a = b.
However sometimes people just use return value 0 to mean a and b are incomparable (some orderings aren't total). In this case, the PriorityQueue has to decide which element goes first. This is tie-breaking. Specifically some priority queues preserve the order in which zero-comparing elements were inserted, so in that case insertion time is the tie-breaker. Then for a collection of elements where compareTo() always returns 0, the priority queue would act just like a normal queue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With