Differentiate between priorityqueue and treeset.



Differentiate between priorityqueue and treeset...

Answer / Nishant Singh

PriorityQueue and TreeSet are data structures used for different purposes:
1. Implementation:n - PriorityQueue is an ordered collection where each element has a priority or key associated with it.n - TreeSet is a self-balancing binary search tree that stores unique elements in sorted order.
2. Operations:n - PriorityQueue offers methods for adding and removing elements based on their priorities, such as add(), remove(), and poll().n - TreeSet provides operations for inserting, deleting, and searching elements based on their values, such as add(), remove(), and contains().
3. Sorted Order:n - PriorityQueue maintains the elements in the order of their priorities, which may not necessarily be the natural ordering.n - TreeSet maintains the elements in their natural ordering by default or a custom comparator if provided.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

What is the use of threaded binary tree?

1 Answers  


In what areas do data structures applied?

1 Answers  


ple.. briefly describe the purpose of having a base case and a recursive case in a recursive algorithm

2 Answers  


How would you dynamically allocate a one-dimensional and two-dimensional array of integers?

1 Answers  


How do you separate zeros from non-zeros in an array?

1 Answers  


What are hash tables good for?

1 Answers  


What is the time complexity of arrays sort?

1 Answers  


What is sort order?

1 Answers  


Is quicksort faster than merge sort?

1 Answers  


What is nsmutablearray?

1 Answers  


Complete structure of hashmap, very detail description, along with the basic coding of the hashmap internal implementation.

1 Answers   Expedia,


How many sorting techniques are there?

1 Answers  


Categories