Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Give the state of the disjoint-sets data structure after the following sequence of operations, starting from singleton sets 1,,8. Usepath compression. In the case of ties, always make the lower numbered root point to the higher numbered ones.

union1,2,union3,4,union5,6,union7,8

,union1,4,union6,7,union4,5,find1

Short Answer

Expert verified

The state of the disjoint-sets data structure using path compression.

Step by step solution

01

Explain the data structure for disjoint sets. 

Disjoint sets can be stored as the directed tree arranged in no particular order.

Parent pointer π and rank are the components of the disjoint set data structure. The union of the disjoint set from the singleton sets can be done by the path compression method.

02

Step 2:Give the state of the disjoint-sets data structure using path compression. 

Consider the properties to perform union of the sets.

Property 1: For rankx<rankπx, Create a root node with rank K by merging the two trees with roots of rank k-1 .

Property 2: Any root node of rank K has at least 2knodes in its tree.

Property 3: If there are n elements overall, there can be at most n2k nodes of rank .

Consider the singleton sets 1,,8. Represent the singleton sets as the nodes with the rank 0 .

Perform ,by using properties.

The node with the lowest number points to the highest number, and the number of nodes or subtrees are represented as degree.

Perform union1,4as follows,

The node 4 has two sub nodes, the degree of the node is updated as 2.

Perform union6,7

By the property 1, node 6 points to the node7 and the degree of the 7 is updated to 2 and the degree of 8 is updated to 3.

Perform union4,5

By the property 1, the node 4 points to 5 and the degrees of node 6,7, and 8 are updated accordingly. The tree has now has the root with larger degree, by applying properties 1 and 2 , merge the tree as follows.

Perform find(1),

Disassociate the nodes with the highest degrees and make them pointed to the higher numbered root as follows.

Therefore, the state of disjoint set data structure is found by the path compression method

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Suppose you are given a weighted graph G=(V,E) with a distinguished vertex s and where all edge weights are positive and distinct. Is it possible for a tree of shortest paths from s and a minimum spanning tree in G to not share any edges? If so, give an example. If not, give a reason.

Show that if an undirected graph with n vertices has k connected components, then it has at least n - k edges.

A binary counter of unspecified length supports two operations: increment (which increases its value by one) and reset (which sets its value back to zero). Show that, starting from an initially zero counter, any sequence of n increment and reset operations takes time O(n); that is, the amortized time per operation is O(1) .

Question: Suppose the symbols a,b,c,d,e occur with frequencies 12,14,18,116,116,respectively.

(a) What is the Huffman encoding of the alphabet?

(b) If this encoding is applied to a file consisting of1,000,1000 characters with the given frequencies, what is the length of the encoded file in bits?

Entropy: Consider a distribution overnpossible outcomes, with probabilities p1,p2,K,pn.

a. Just for this part of the problem, assume that each piis a power of 2 (that is, of the form 1/2k). Suppose a long sequence of msamples is drawn from the distribution and that for all 1in, the ithoutcome occurs exactly times in the sequence. Show that if Huffman encoding is applied to this sequence, the resulting encoding will have length

i-1nmpilog1pi

b. Now consider arbitrary distributions-that is, the probabilities pi are noy restricted to powers of 2. The most commonly used measure of the amount of randomness in the distribution is the entropy.

i-1nmpilog1pi

For what distribution (over outcomes) is the entropy the largest possible? The smallest possible?

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free