Purchase Solution

Running time of a set union implementation

Not what you're looking for?

Ask Custom Question

The input consists of two arrays each representing a set of integers (in each array, each value appears only once). The output is an array representing the union of the two sets - again, each value appears only once. Write a method to implement set union and analyze its running time.

Purchase this Solution

Solution Summary

Solution is presented in pseudo-code form along with plain description for easy understanding. Counts of comparisons as well as assignments are marked for various steps in implementation. Solution analyzes the given implementation for maximum and minimum number of algorithm assignments, worst case algorithm comparisons and maximum number of implementation comparisons.

Solution Preview

Procedure Union

Input: Array set1, Array set2 // Arrays are indexed 0 onwards.
Output: Array set3 // Maximum size of this array is size of set1 + size of set2.

size1 = Number of elements in Array set1
size2 = Number of elements in Array set2
ucount = 0 // To count number of elements in Union Array.

// Check for each element of set1 whether it occurs in set2. If not then copy it to union set3.
for (i=0; i<size1; i++) { // size1 comparisons always.
found = no // size1 assignment operations always.
for (j=0; j<size2; j++) { // size2 comparisons in worst case.
...

Purchase this Solution


Free BrainMass Quizzes
Multiplying Complex Numbers

This is a short quiz to check your understanding of multiplication of complex numbers in rectangular form.

Probability Quiz

Some questions on probability

Geometry - Real Life Application Problems

Understanding of how geometry applies to in real-world contexts

Graphs and Functions

This quiz helps you easily identify a function and test your understanding of ranges, domains , function inverses and transformations.

Know Your Linear Equations

Each question is a choice-summary multiple choice question that will present you with a linear equation and then make 4 statements about that equation. You must determine which of the 4 statements are true (if any) in regards to the equation.