Data structures help us to organize the data in the computer, resulting in more efficient programs. An efficient program executes faster and helps minimize the usage of resources like memory, disk. Computers are getting more powerful with the passage of time with the increase in CPU speed in GHz, availability of faster network and the maximization of disk space. Therefore people have started solving more and more complex problems. As computer applications are becoming complex, so there is need for more resources.
|Published (Last):||20 June 2019|
|PDF File Size:||16.53 Mb|
|ePub File Size:||11.63 Mb|
|Price:||Free* [*Free Regsitration Required]|
Write the applications of heap. Answer:- page 84 The stack and heap are used in function calls. When we allocate memory dynamically in our programs, it is allocated from the heap.
The use of priority queue with the help of heap is a major application. The priority queue is itself a major data structure, much-used in operating systems. Similarly priority queue data structure is used in network devices especially in routers. Heap data structure is also employed in sorting algorithms. 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 root the number is used the name 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 necessary that each node should have a maximum of two children nodes. Here a n may have more than two children nodes. To execute the union operation in two sets, we merge the two trees of these sets in such a manner that the root of one tree points to the root of other.
So there will be one root, resulting in the merger of the trees. In the find operation, when we call find x , it helps us to know which set this x belongs to.
Internally, we find this x in a tree in the forest. When this x is found in a tree the find returns the number at root node the name of the set of that tree. Answer: Page Yes it is an equivalence relation First rule is reflexive i.
Suppose that x is Haris so Haris R Haris. This is true because everyone is related to each other. Second is Symmetry: for all elements x and y, x R y if and only if y R x.
Suppose that y is Saad. If two persons are related, the relationship is symmetric i. Therefore if Haris is brother of Saad, then Saad is certainly the brother of Haris. The family relationship is symmetric.
This is not the symmetric in terms of respect but in terms of relationship. Suppose x is Haris, y is Saad and z is Ahmed.
This is also true in relationships. If you are cousin of someone, the cousin of that person is also related to you. He may not be your first cousin but is related to you. In this process, each cell of the memory not only contains the value of the element but also the information where the next element of the list is residing in the memory. It is not necessary that the next element is at the next location in the memory.
It may be anywhere in the memory. We have to keep a track of it. Thus, in this way, the first element must explicitly have the information about the location of the second element. KHalid Hassan on February 18, at am kia ye question past papers me se liye gye hen??? Jahanzaib Ashiq on February 18, at pm g kuch 2,4.
CS301 Mid term Solved MCQs and Subjective With References by Moaaz