# 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").

122 questions
Filter by
Sorted by
Tagged with
93 views

### Set<T> data structure in C#

The following data structure is meant for manipulating algebraic/mathematical sets. I want Set<T> to be compatible and interchangeable with any similar data ...
36 views

### Finding data relations of json paths in python

I am kind of new to python, so I am pretty sure there are way better elegant ways to do this. I have made a function that is able to compare two list of possible json object paths, and detect what ...
88 views

I recently implemented a Bloom Filter in Haskell and, although I am not new to functional programming, I am a beginner when it comes to Haskell itself. I'll gladly take any feedback regarding the ...
51 views

### Solving Exact Cover by Three Products in Python

I'm a computer-science hobbyist and found an NP-complete problem that is similar to both subset-product and Exact Cover by 3-sets. Here is a Reduction of Exact-Cover into my problem. I am multiplying ...
108 views

### Ensure difference between sets

An endpoint that my application interacts with allows you to specify which fields are returned in the JSON result. My application will then map the JSON to a POJO using Jackson. Quite often I add more ...
2k views

### An ordered set in C#

I need a generic data structure that ensures that its elements are unique. C# has HashSet<T>, great! As it turns out, the elements have to stay in the order ...
2k views

### Generate powerset in JS

I came across a mock interview question in which the candidate is asked to generate the powerset of a given set. The input set is represented as a unique array of integers. There was no solution ...
71 views

### Remove elements compared with other elements in a Set based on a condition

Simplified the actual problem to focus on comparing/removing performance. Given a set S with n elements , find the most optimal way to compare each element to all others until a condition is met that ...
131 views

### Finding which items have at least one common value with other items

I have the following collection : ...
76 views

### Test for an array being subset of another master array

I was trying to build a small utility function to check if an array is part of other array. It's testing if an array is a subset of another master array. ...
72 views

### Immutable Keyed Set

Description An immutable keyed set is a readonly collection of elements without duplicates or null values having each of the elements linked to exactly one key. Example This simple example ...
449 views

### Union Find implementation

I am trying to complete this challenge. The user should enter a sequence of instructions, = to link two numbers, and ? to query ...
75 views

### Python set based solution to Subset Sum

Working on the 2 element subset sum problem (finding two numbers in a list that sum to a given value), I came up with a relatively short solution code-wise. The code could fit on a single line but I'...
94 views

### Generic Macro Generated Hashset in C

The Hashset uses open addressing, linear probing and Robin Hood hashing for handling collisions. It comes with insert and remove ...
206 views

### Custom Hashset in Java

I have written this custom hashset and though it isn't completed yet, I would like to know if there is anything I am overlooking in terms of clean code conventions. My aim was also to apply generics ...
57 views

### unordered_set: a hash table -based set data structure in C89

In this post, I present a hash table -based set data structure written in C89: unordered_set.h ...
98 views

### java.util.Set extension/implementation

Lately, I was working on some experimental java.util.Set extension, IdSet: ...
71 views

### Powerset of collection in Clojure

Similar to this question, here's another implementation. Assume the input is already a set. ...
2k views

### Sort int array by frequency then value

Problem Take an array of ints as input and run a special sorting algorithm on it. This algorithm must first sort by int frequency, less frequent first, then sort by value. For example ...
1k views

### Data Structures for Counting Duplicates and using std::vector::erase

Problem Dupe detection for a vector of ints. I simply want a count of the unique input characters that occurred at least twice. The goal is to count a dupe only once and ignore that input character if ...
766 views

### Finding Repeat and missing numbers in an array

Problem Statement: You are given a read-only array of n integers from 1 to n. Each integer appears exactly once except A which appears twice and B which is missing. Return A and B. ...
42k views

### Find the uncommon elements from two sets

I am trying to find the uncommon elements from two sets in Java. Here is my way: ...
109 views

### Possible letter combinations of a dial pad in linear time using a recursive approach

Time complexity: I walk the initial unzipped array of keys representing the number O(N) backwards. I then do an inner walk of the proceeding array of letters *O(L^2), mapping it to every value in the ...
2k views

### All subsets of a String in java using recursion

I wrote this code for printing all sets of a String. It also prints the empty subset. Is this the right approach ...
4k views

Is the following functions implemented correctly for the set class? Please let me know if any changes need to be made. ...
185 views

### Grow-only set (CRDT)

I made up a quick and dirty implementation of the G-Set in C#. I was hoping for some feedback on my approach. I'm not totally happy with having the payload public but I can't see that I'm gaining ...
5k views

### From a set of words, output all words that fit a string of random letters (like Scrabble)

I am in my first year of programming with Python 3 and am wondering if anyone had a better way to program this problem. When the user provides up to 7 random letters as a single string, the program ...
625 views

### set implementation based on an array

I was supposed to implement set without using any implemented structures. I would love to know what can I correct in my code, because I am not that much satisfied with its quality, so if you have any ...
38 views

### Implementation of a shift operation for Set in JavaScript that emulates the one for arrays

I discovered that the JavaScript sets are ordered but don't offer a method to take the first element out of the set. For the arrays this operation exists and it's called shift. A very basic ...
213 views

### Finding the number of ways to partition {1,2, …, N} into p1 and p2 such that sum(p1) == sum(p2)

I am trying to write a space and time efficient algorithm to calculate the number of ways to partition a set of integers {1, 2, ..., N} into two partitions such that the sums of integers in the two ...
3k views

...
208 views

### Ruby Connected Components in a Graph

I've written the following code to find the connected components of a graph in ruby, but it is quite slow since I don't use any sensible data structure for the disjoint sets, and hence find_set is ...
123 views

### is_subset Python implementation

I wanted to ask for a code review for my implementation of Set: ...
85 views

### Finding duplicates between n Sets

I have n Objects, Each Object has a Set of "nested" "Neighboring Objects". I need to check if there are duplicates between the "Neighboring Objects" Sets (there are no duplicates inside a single Set ...
96 views

### Sorted set a Queue

I needed a data structure offering both poll returning the smallest element and fast contains. A ...
54 views

### Benchmarking TreeSet in Java against a van Emde Boas tree based integer set

VanEmdeBoasTreeIntegerSet.java ...
5k views

### Concurrent HashSet

I've recently been using HashSet and locking on each method, I found this to not only be a lot of work (was using it in a lot of places) but I started to see inconsistency in my code. I later decided ...
2k views

### Finding common Integers between two lists

Write a method numInCommon that takes two Lists of integers as parameters and returns the number of unique integers that occur in both lists. Use one or more Sets as storage to help you solve this ...
106 views

### Python implementation for Set

I wanted to ask for a code review for my implementation of Set: ...
5k views

### Compute power set of a given set in Python

Problem: Given a set (let's say of integers), return the list of all of its subsets also known as the power set. It looks to be working, but I would like feedback on the algorithm and Python ...
2k views

### Thread safe tbb::concurrent_hash_map and std::set

I have a basic websocket server implemented in C++. I'm using Intel TBB's concurrent hash_map to store all the users, uniquely identified by the id. The concurrent ...
228 views

### Finding added keys, removed keys, and unchanged keys in ordereddict

I'm comparing two OrderedDict objects and I need to find added keys, removed keys, and keys that are present in both (the intersection). Sets are designed for ...
97 views

### Sorted vector/set class that works with simple types (char, int, double, etc…)

I'm new to C++ (approx. 3 months) and have just read Stroustrup's Programming Principles and Practice. Previously used Python a lot. As an exercise I tried to implement a custom container, with the ...
85 views

### Largest divisible subset optimization

So this is my solution to the following leetcode problem: https://leetcode.com/problems/largest-divisible-subset/description/ How could I optimize this code? I think the run time is \\$\mathcal{O}(n^2)...
446 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 (<...
420 views

### Forming sets from pairs of numbers

I do not want to use a new data structure but the existing APIs in Java. Here's a solution. I am thinking if this can be made simpler. Input say ...
7k views

### Powerset (all subsets of a set) in Java

I am trying to get a powerset (all subsets of a set) in Java. So my logic for that is: A given set is one subset, so add so it as it is to result. Remove each element of set from given set and we ...
40 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 ...