Bifalgorithm post · Computer science one · Sorting

How do sorted collections maintain element order?

How do sorted collections maintain element order? (Computer science one · Sorting) — "The Java Collections framework also provides several sorted data structur…

Ideas in this flowchart

  • The Java Collections framework includes sorted data structures.
  • An ordered collection such as a List can be sorted with Collections.sort().
  • A sorted data structure maintains its ordering as elements are added.
  • New elements are inserted in the appropriate position.
  • Arbitrary insertion of elements in any order is prevented.
  • Java defines the SortedSet<T> interface for sorted collections.
  • TreeSet<T> is an implementation of SortedSet<T>.
  • TreeSet<T> uses a balanced binary search tree, specifically a red-black tree.
  • A TreeSet<T> can be constructed by providing a Comparator<T>.
Feed/

How do sorted collections maintain element order?

No cover

Channel

Computer science one

1 page

"The Java Collections framework also provides several sorted data structures. Though an ordered collection such as a List can be sorted by calling the Collections.sort() method, a sorted data structure maintains an ordering. As you add elements to the data structure, they are inserted in the appropriate spot. Such data structures also prevent you from arbitrarily inserting elements in any order. Java defines the SortedSet<T> interface for sorted collections with a TreeSet<T> implementation. As the name implies, the implementation is a balanced binary search tree, in particular a red-black tree. You can construct a TreeSet<T> by providing it a Comparator<T>."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.