Questions tagged [set]
A set is a collection in which no element is repeated, which may be able to enumerate its elements according to an ordering criterion (an "ordered set") or retain no order (an "unordered set").
140
questions
0
votes
3
answers
577
views
Java Generics and ArrayLists
This abomination of code creates arrays based off input from the user. Sample input would be something like "S 4 aba bab baa aab" where:
args[0] = array type (<...
3
votes
1
answer
6k
views
Set class with binary search tree implementation
Here is my Set implementation with binary search tree that compiles. Please let me know what changes are needed to make it better. Thank you.
...
6
votes
4
answers
1k
views
Monty hall python simulation
I have the following code that simulates the monty hall problem (see google for more details). I used sets to do it but is there a more intuitive or efficient way to do it?
...
3
votes
2
answers
2k
views
Set with custom compare
In my project I use std::set with custom Compare function for maintaining an event queue. It fulfills following criteria:
event duplication is not allowed
should ...
2
votes
2
answers
15k
views
Finding the intersection of elements in two sets
Is there another better way to implement those two methods in 1 and 2?
Implement the method contains.
contains returns ...
2
votes
1
answer
45
views
A value set data structure for rapid statistics queries in Java - follow-up
(See the previous iteration.)
Now all operations of the data structure work in exact constant time, yet it came with the price: the state of this set maybe non-sensical. A user may end up with the ...
2
votes
2
answers
74
views
A value set data structure for rapid statistics queries in Java
(See the next iteration.)
This question is an elaboration of my question. Just like the previous implementation, all operations (except clear) run in exact or ...
3
votes
1
answer
964
views
Extract index of first unique element in large array in Swift
I'm using the following code to return the first index of a unique character in a large String. It works fine until I get to large strings, where it times out.
Is ...
2
votes
1
answer
8k
views
Remove Duplicates from Array in Swift 3.0
I ran the following code through a Leetcode.com challenge and it says the runtime for the test cases is 119ms, which puts it at the back of the pack performance wise.
The goal is to remove duplicates ...
2
votes
0
answers
147
views
Spellchecker program is having issues due to vowel checking method
This program takes in a list of 275k or so words from '/usr/share/dict/words' and loads them into HashSet. It then takes in a list of 1000 words (taken from the dictionary and are scrambled (vowel ...
2
votes
1
answer
649
views
Dictionary with ISet key as a collection of names
I'm writing a command-line utility and I need to find commands (and parameters) by name. The name can either be a full name like save or a shortcut ...
6
votes
2
answers
2k
views
Building a set of all subsets recursively in C++
Here is my recursive implementation of a power set function in C++. One thing that concerns me is that I am iterating over the set of sets while modifying its size. The code nevertheless functions as ...
5
votes
2
answers
7k
views
Determining if a relation is reflexive
A binary relation \$R\$ on a set \$A\$ is called reflexive if and only if \$R(a, a)\$ for every element \$a \in A\$.
I want to know if there can be any improvements made on the function below to ...
3
votes
0
answers
124
views
Substitute for `std::array::operator[]` in C++11 by using template-based recursion
What follows is a simplified version of a tentative implementation for a template-based set, named TemplateArgs. For the sake of clarity and focus on the question ...
2
votes
2
answers
194
views
Find combination of sets which sum up to a specified result
Example input :
A) 1, 2
B) 2, 8
C) 7, 8
Required Result : 8, 10
The output from the program with this input should be A + C.
Few notes :
We can only combine 2 sets.
There must ...