answersLogoWhite

0


Best Answer

Cannot be solved without knowing what an 'Element' is.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program to duplicate element from a set of elements?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is code of finding all subset in a set in c?

Each element of C can either be in a particular subset or not in it - two options for each element of C. So if there are n elements in C, then the number of subsets of C is 2n. These include the null set and C itself.


Write a program to detect duplicate elements in array?

The simplest way of doing this is not very efficient, but provides a quick development time. You want to take all of the elements of the array, add them to a Set, then retrieve them as an array again. Note that this will probably not preserve the order of elements in the array. { Object[] originalArray; // let's pretend this contains the data that // you want to delete duplicates from Set newSet = new HashSet(); for (Object o : originalArray) { newSet.add(o); } // originalArray is now equal to the array without duplicates originalArray = newSet.toArray(); } Now the efficient, and more correct, solution. This one will create a new array of the correct size without duplicates. { Object[] originalArray; // again, pretend this contains our original data // new temporary array to hold non-duplicate data Object[] newArray = new Object[originalArray.length]; // current index in the new array (also the number of non-dup elements) int currentIndex = 0; // loop through the original array... for (int i = 0; i < originalArray.length; ++i) { // contains => true iff newArray contains originalArray[i] boolean contains = false; // search through newArray to see if it contains an element equal // to the element in originalArray[i] for(int j = 0; j <= currentIndex; ++j) { // if the same element is found, don't add it to the new array if(originalArray[i].equals(newArray[j])) { contains = true; break; } } // if we didn't find a duplicate, add the new element to the new array if(!contains) { // note: you may want to use a copy constructor, or a .clone() // here if the situation warrants more than a shallow copy newArray[currentIndex] = originalArray[i]; ++currentIndex; } } // OPTIONAL // resize newArray (using _newArray) so that we don't have any null references Object[] _newArray = new Object[currentIndex]; System.arraycopy(newArray, 0, _newArray, 0, currentIndex); }


How can you make a turbo c program by using one for loop to sort 3 numbers in ascending order?

Use the insertion sort algorithm. Insertion sort works on the premise that a set of 1 can always be regarded as a sorted set, thus in a set of n elements, we can divide the set in two, with a sorted set at the beginning (with 1 element) and an unsorted set at the end (with all other elements). We then take the first element of the unsorted set and insert it into the sorted set, repeating until the unsorted set is empty. We take the first element out of the unsorted set by copying it to a temporary variable, thus creating a gap in its place. We then examine the element to the left of the gap and, if the value is greater than the temporary, we copy it into the gap, effectively moving the gap one place to the left. We stop moving the gap when we reach the start of the array or the element to the left of the gap is not greater than the temporary. We then copy the temporary into the gap, increasing the sorted set by one element and reducing the unsorted set by one element. We can implement this algorithm using just one for loop: void sort (int* a, unsigned s) { // assume a refers to an array of length s for (int i=2; i<s; ++i) { int t = a[i]; // temporarily store a[i] outside the array int g = i; // index g is the "gap" in the array while (0<g && t<a[g-1]) { a[g]=a[g-1]; --g; } // move the gap to the correct insertion point a[g] = t; // insert the temporary } } Thus, to sort 3 numbers: int a[3] = {2, 3, 1}; // unsorted sort (a, 3); assert (a[0]==1); assert (a[1]==2); assert (a[2]==3);


How to program set Cardinality in C plus plus?

The cardinality of a set is simply the number of elements in the set. If the set is represented by an STL sequence container (such as std::array, std::vector, std::list or std::set), then the container's size() member function will return the cardinality. For example: std::vector<int> set {2,3,5,7,11,13}; size_t cardinality = set.size(); assert (cardinality == 6);


The average the sum of the elements divided by the number of elements?

Yes, average is the sum of elements divided by the number of elements Exp:- x1=10, x2=20, x3=30, x4=10. then the average is 10+20+30+10 ------------------ 4 => 17.5 Average = sum of total of element ---------------------------------- no. of elements

Related questions

Why duplicate tuples are not allowed in DBMS?

Since relation is a set, and tuples are element of a set, according to set theory, the elements of a set are not ordered.


What is the definition of elements in regards to math?

Elements can be an element of a set. Lets say you have a set of numbers like A{2,3,5,8,45,86,9,1} B{2,7,0,100} all those numbers are called elements of that set 2 is an element of set A and B 100 is an element of set B 45 is an element of set A


Define set in java?

A Java set is a collection of things that do not contain duplicate elements. Duplicates are prohibited from Java sets.


What is method of listing the element of a set?

The symbol of the elements is £


Why null set is not considered as an element of any set even though it is an subset of every set?

Let set A = { 1, 2, 3 } Set A has 3 elements. The subsets of A are {null}, {1}, {2}, {3}, {1,2},{1,3},{1,2,3} This is true that the null set {} is a subset. But how many elements are in the null set? 0 elements. this is why the null set is not an element of any set, but a subset of any set. ====================================== Using the above example, the null set is not an element of the set {1,2,3}, true. {1} is a subset of the set {1,2,3} but it's not an element of the set {1,2,3}, either. Look at the distinction: 1 is an element of the set {1,2,3} but {1} (the set containing the number 1) is not an element of {1,2,3}. If we are just talking about sets of numbers, then another set will never be an element of the set. Numbers will be elements of the set. Other sets will not be elements of the set. Once we start talking about more abstract sets, like sets of sets, then a set can be an element of a set. Take for example the set consisting of the two sets {null} and {1,2}. The null set is an element of this set.


Does a set with no element belong to any kind of set?

I believe you are talking about subsets. The empty set (set with no elements) is a subset of any set, including of the empty set. ("If an object is an element of set A, then it is also an element of set B." Since no element is an element of set A, the statement is vacuously true.)


Is an empty set element of any set s?

The empty element is a subset of any set--the empty set is even a subset of itself. But it is not an element of every set; in particular, the empty set cannot be an element of itself because the empty set has no elements.


What is roster notation method?

This is a method describing a set by listing each element of the set inside the symbol {}. In listing the elements of the set, each distinct element is listed once and the order of the elements does not matter.


How many subsets does a set N element have?

A set with N elements has 2N subsets.


What do identity property of multiplication mean?

If a set, with multiplication defined over its elements has the identity property it means that there is a unique element in the set, usually denoted by i, such that for every element x in the set, x*i = x = i*x.If the elements of the set are numbers then i = 1.


What is the identity element for multiplication?

An identity element is an element of a set which leaves other elements unchanged when combined with them. For multiplication, the identity element is 1 .


What are the relationship among set?

The possible relationships between two sets (here arbitrarily named A and B) are:If each element of set A is also element of set B (and vice versa), the two sets are equal.If no element of set A is element of set B (and vice versa), the two sets are disjoint.If all elements of set A are also elements of set B, the set A is a subset of set B. If set B contains elements not found in set A, the set A is a proper or strict subset of set B. Set B is called supersetresp. proper superset of A.If set A and set B share some elements, but each set also has elements not found in the other set, the two sets intersect.