CS301-Lec35 handout

# CS301-Lec35 handout - CS301 Data Structures Lecture No 35...

This preview shows pages 1–3. Sign up to view the full content.

CS301 – Data Structures Lecture No. 35 ___________________________________________________________________ Data Structures Lecture No. 35 Reading Material Data Structures and Algorithm Analysis in C++ Chapter. 8 8.2, 8.3 Summary Dynamic Equivalence Problem Example 1 Parent Array o Initialization o Find (i) o Union (i, j) Example 2 o Initialization o union operation o find Operation Running Time Analysis Before talking about the data structure implementation in detail, we will recap the things discussed in the previous lecture. The concepts that came under discussion in the last lecture included the implementation of the disjoint set. It was observed that in case of data elements, we assign a unique number to each element to make sets from these numbers. Moreover, techniques of merger and searching in these sets by using the operations union and find were, talked about. It was seen that if we send a set item or a number to find method, it tells us the set of which this item is a member. It will return the name of the set. This name of set may also be a number. We talked about the union method in which members of two sets join together to form a new set. The union method returns the name or number of this new set. Now we will discuss the data structure used to implement the disjoint sets, besides ascertaining whether this data structure implements the find and union operations efficiently. Dynamic Equivalence Problem We are using sets to store the elements. For this purpose, it is essential to remember which element belongs to which set. We know that the elements in a set are unique and a tree is used to represent a set. Each element in a tree has the same root, so the root can be used to name the set. The item (number) in the root will be unique as the set has unique values of items. We use this root as the name of set for our convenience. Otherwise, we can use any name of our choice. So the element in the

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS301 – Data Structures Lecture No. 35 ___________________________________________________________________ root (the number) is used as the name of the set. The find operation will return this name. Due to the presence of many sets, there will be a collection of trees. In this collection, each tree will be representing one set. If there are ten elements, we will have ten sets initially. Thus there will be ten trees at the beginning. In general, we have N elements and initially there will be N trees. Each tree will have one element. Thus there will be N trees of one node. Now here comes a definition for this collection of trees, which states that a collection of trees is called a forest . The trees used for the sets are not necessarily binary trees. That means it is not necessary that each node should have a maximum of two children nodes. Here a node may have more than two children nodes. To execute the union operation in two sets, we merge the two trees of these sets in
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/21/2010 for the course CS CS301 taught by Professor Dr.naveed malik during the Spring '10 term at Virtual University of Pakistan.

### Page1 / 12

CS301-Lec35 handout - CS301 Data Structures Lecture No 35...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online