Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Data Structures: Disjoint Sets and Graphs, Lecture notes of Computer Graphics

The Disjoint Sets data structure, including its implementation with find and unionBySize functions, path compression, and analysis. Additionally, it introduces the concept of graphs and their applications, such as the Internet, class hierarchies, and conflict-free exam scheduling.

What you will learn

  • What is the Disjoint Sets data structure and how is it implemented with find and unionBySize functions?
  • What is a graph and what are its main components?
  • How can graphs be used in real-world applications, such as the Internet and class hierarchies?
  • What is the purpose of path compression in Disjoint Sets?

Typology: Lecture notes

2021/2022

Uploaded on 09/12/2022

avni
avni 🇺🇸

4.7

(3)

229 documents

1 / 27

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 225
Data Structures
April 5 Disjoint Sets Finale + Graphs
Wade Fagen-Ulmschneider, Craig Zilles
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download Data Structures: Disjoint Sets and Graphs and more Lecture notes Computer Graphics in PDF only on Docsity!

CS 225

Data Structures

April 5 – Disjoint Sets Finale + Graphs

Wade Fagen-Ulmschneider, Craig Zilles

Disjoint Sets Find int DisjointSets::find(int i) { if ( arr_[i] < 0 ) { return i; } else { return find( arr[i] ); } } 1 2 3 4 void DisjointSets::unionBySize(int root1, int root2) { int newSize = arr_[root1] + arr_[root2]; // If arr_[root1] is less than (more negative), it is the larger set; // we union the smaller set, root2, with root1. if ( arr_[root1] < arr_[root2] ) { arr_[root2] = root1; arr_[root1] = newSize; } // Otherwise, do the opposite: else { arr_[root1] = root2; arr_[root2] = newSize; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Disjoint Sets Analysis The iterated log function: The number of times you can take a log of a number. log(n) = 0 , n ≤ 1 1 + log(log(n)) , n > 1 What is lg( 65536 )*?

Disjoint Sets Analysis In an Disjoint Sets implemented with smart unions and path compression on find : Any sequence of m union and find operations result in the worse case running time of O( ____________ ), where n is the number of items in the Disjoint Sets.

  • Constant time access to any element, given an index a[k] is accessed in O(1) time, no matter how large the array grows
  • Cache-optimized Many modern systems cache or pre-fetch nearby memory values due the “Principle of Locality”. Therefore, arrays often perform faster than lists in identical operations. [0] [1] [2] [3] [4] [5] [6] [7] Array
  • Efficient general search structure Searches on the sort property run in O(lg(n)) with Binary Search
  • Inefficient insert/remove Elements must be inserted and removed at the location dictated by the sort property, resulting shifting the array in memory – an O(n) operation [0] [1] [2] [3] [4] [5] [6] [7] Array [0] [1] [2] [3] [4] [5] [6] [7] Sorted Array
  • First In First Out (FIFO) ordering of data Maintains an arrival ordering of tasks, jobs, or data
  • All ADT operations are constant time operations enqueue() and dequeue() both run in O(1) time [0] [1] [2] [3] [4] [5] [6] [7] Array [0] [1] [2] [3] [4] [5] [6] [7] Unsorted Array [0] [1] [2] [3] [4] [5] [6] [7] Queue (FIFO)
  • Last In First Out (LIFO) ordering of data Maintains a “most recently added” list of data
  • All ADT operations are constant time operations push() and pop() both run in O(1) time [0] [1] [2] [3] [4] [5] [6] [7] Array [0] [1] [2] [3] [4] [5] [6] [7] Unsorted Array [0] [1] [2] [3] [4] [5] [6] [7] Stack (LIFO)

In Review: Data Structures Array

**- Sorted Array

  • Unsorted Array** - Stacks - Queues - Hashing - Heaps - Priority Queues - UpTrees - Disjoint Sets List - Doubly Linked List - Skip List - Trees - BTree - Binary Tree - Huffman Encoding - kd-Tree - AVL Tree Graphs

The Internet 2003 The OPTE Project (2003) Map of the entire internet; nodes are routers; edges are connections.

“Rush Hour” Solution Unknown Source Presented by Cinda Heeren, 2016

Wolfram|Alpha's "Personal Analytics“ for Facebook Generated: April 2013 using Wade Fagen-Ulmschneider’s Profile Data

Conflict-Free Final Exam Scheduling Graph Unknown Source Presented by Cinda Heeren, 2016

Class Hierarchy At University of Illinois Urbana-Champaign A. Mori, W. Fagen-Ulmschneider, C. Heeren Graph of every course at UIUC; nodes are courses, edges are prerequisites http://waf.cs.illinois.edu/discovery/class_hi erarchy_at_illinois/