CSE 373
Back to Top
Site logo of CSE 373
CSE 373
  • Home / Calendar
  • Syllabus
  • Projects
    • P0 - CSE 143 Review
      • System Setup
      • Using IntelliJ
      • Programming
      • Unit Testing
      • Commit & Submit
    • P1 - Deques
      • Getting Started
      • Programming
      • Tests
    • P2 - Maps
      • Map Interface
      • Iterator Interface
      • ArrayMap Implementation
      • ChainedHashMap Implementation
      • Tests and Submission
    • P3 - Heap
      • Programming
    • P4 - Mazes
      • Introduction
      • Disjoint Sets
      • Kruskal's Algorithm
      • Dijkstra's Algorithm
  • Exercises
  • Exams
  • Office Hours
  • Course Staff
  • Resources

  • Course Tools
  • EdStem
  • Anonymous Feedback
Acknowledgements

Disjoint Sets


  1. Disjoint Sets
  2. An Optimized Implementation

Disjoint Sets¶

Signature Description
void makeSet(T item) Creates a new set containing just the given item and with a new integer id.
int findSet(T item) Returns the integer id of the set containing the given item.
boolean union(T item1, T item2) If the given items are in different sets, merges those sets and returns true. Otherwise does nothing and returns false.

The disjointsets package contains the disjoint sets data structures required by Kruskal’s algorithm. We include a default, inefficient implementation in the skeleton.

The inefficient implementation will be replaced by the optimized UnionBySizeCompressingDisjointSets implementation to generate mazes.

An Optimized Implementation¶

Task

Implement UnionBySizeCompressingDisjointSets using union-by-size, path compression, and array representation optimizations.

Implementation notes:

  • We recommend reviewing the lecture slides and section materials before implementing your disjoint sets.
  • The Gradescope tests will directly inspect the pointers field so be sure to store the array representation of your disjoint sets there.

In the next section, you will use your optimized disjoint sets implementation to speed up KruskalMinimumSpanningTreeFinder.

Search

Search the class website; related sections and pages will appear below. Note: this search is not as forgiving with typos as other search engines.