Skip to main content

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

1 vote
1 answer
82 views

Rewriting the java.util.concurrent.ConcurrentSkipListMap to a version without concurrency constructs

I have essentially rewrote the java.util.concurrent.ConcurrentSkipListMap into a version without concurrency constructs (...
coderodde's user avatar
  • 28.9k
2 votes
1 answer
80 views

Compare and merge sets from unstructured variables for automatic differentiation

I have developed an automatic differentiation module for my software. Usually AD comes in two forms; forward mode or reverse mode and very clever approaches, beyond me, might mix both. Typically the ...
Attack68's user avatar
  • 461
2 votes
0 answers
50 views

Set-like Operation in C - Advent of Code 2021 Day 3

I am relatively new to C programming and am currently completeing challenges of Advent of Code 2021 to elevate my skills. I am excited to share my solution for the puzzle on Day 3 and am eager to ...
Noob-in-C's user avatar
1 vote
1 answer
79 views

Collection that uses a bitset to store a huge set of unique integers from a given range (rev. 1)

Some (skippable) context: I'm writing program that minimizes an arbitrary logical function. Such function takes an unsigned integer as an argument and returns either ...
Piotr Siupa's user avatar
2 votes
4 answers
178 views

Comparison of two excel files ignoring line order

Below is a simple method which compares contents of two excel files ignoring the line order. This method is working as expected. But, one of my peers in their code review mentioned that initializing ...
AutoTester999's user avatar
3 votes
3 answers
155 views

IPv4 filter in Java

I have a simple class for representing IPv4-addresses via int values, and a simple IP-address filter that works like a set of IPv4-addresses. ...
coderodde's user avatar
  • 28.9k
8 votes
3 answers
143 views

Compressed output of set in Python

In order to provide a better output of sets with many consecutive elements (a similar class could be written for a list or tuple,...
Looser User's user avatar
2 votes
1 answer
190 views

Yet another Wordle Game

This Jupyter Notebook code for the Wordle game works. After a lot of fixes, I have it working as it should. The code is a jumbled mess. I am open to any suggestions and/or criticism of my code. I am ...
Ashish's user avatar
  • 23
1 vote
1 answer
60 views

SortedIntSet: a set of integers that can be iterated in ascending order in O(N) time

I needed a set with the following properties: can be iterated in ascending or descending order in \$O(N)\$ time the usual set operations (contains, add, remove, discard) can still be done in \$O(1)\$ ...
joseville's user avatar
  • 486
4 votes
1 answer
892 views

Vectorset, a faster std::set

I decided to implement a vectorset, which is intended to be faster than std::set for the 3 fundamental operations, namely insert,...
verven's user avatar
  • 41
2 votes
1 answer
129 views

How many times element of one array occurs in another array?( HackerRank sparse arrays problem)

with basic knowledge of multiset and vectors in c++ I solved the following problem. How can I improve my code and also handle any input errors? Problem statement: There is a collection of input ...
Samir's user avatar
  • 143
2 votes
2 answers
148 views

Radio with channels

Realize the Radio and Channel classes that represent radio and a radio station. The radio class offers an argumentless constructor and the following methods: addChannel: stores and returns a new ...
Giuseppe's user avatar
1 vote
1 answer
90 views

A simple Java integer integer hash set - follow-up 2

(See the previous version.) Now I have this: com.github.coderodde.util.IntHashSet: ...
coderodde's user avatar
  • 28.9k
1 vote
0 answers
79 views

A simple Java integer hash set - follow-up

(See the previous version.) (See the next version.) After incorporating changes in the previous post, I came up with this implementation. However, I left hashing as it is. ...
coderodde's user avatar
  • 28.9k
6 votes
4 answers
1k views

A simple Java integer hash set

(See the next version.) The following data structure implements a hash table based set for int values: ...
coderodde's user avatar
  • 28.9k
1 vote
1 answer
278 views

Managing duplicate class instances in a javascript Set

I have a class called Thing. For simplicity, let's say it initializes with a unique id, and that's all that's unique about it: ...
Seth Lutske's user avatar
3 votes
1 answer
355 views

Take element of a Set collection depending on the value of another element

I had to populate the fields of a Service object using a Set (HashSet) with any configuration parameters -> ...
jpestana's user avatar
2 votes
3 answers
223 views

Sort an array of integers with a hashset

I was trying to make a sorting algorithm for an array of integers. Here's are the steps/theory: It turns an array into a HashSet, iterates over every integer value ...
Kudos B's user avatar
  • 21
5 votes
2 answers
763 views

Filtering a List based on a Suffix and avoid duplicates

I was wondering if there is a better way to solve this issue. I have a list like this: ...
Andrea Ciufo's user avatar
0 votes
1 answer
165 views

Find a powerset of a set in C

The code below is an implementation of purely recursive solution to find a powerset of any given set. The input set is a string, and the output - array of strings. Both of them are wrapped into a ...
anfauglit's user avatar
  • 103
1 vote
0 answers
37 views

Set operations on a tree / Hierarchical set class

Initially, I posted this question on StackOverflow. I wanted to know if there's an existing library that implements the concept I have in mind, which is the following. I want to define a hierarchy/...
Hlib Babii's user avatar
4 votes
2 answers
4k 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 ...
user366312's user avatar
2 votes
0 answers
110 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 ...
The T's user avatar
  • 451
1 vote
1 answer
42 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 ...
Mayday's user avatar
  • 135
5 votes
2 answers
132 views

Bloom Filter in Haskell

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 ...
Bertrand's user avatar
  • 151
6 votes
1 answer
430 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 ...
Arjen's user avatar
  • 63
4 votes
2 answers
185 views

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

I have the following collection : ...
tigrou's user avatar
  • 421
4 votes
1 answer
101 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 ...
dfhwze's user avatar
  • 13.9k
4 votes
2 answers
115 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 ...
Michael Ziluck's user avatar
2 votes
2 answers
220 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'...
Cooper's user avatar
  • 21
3 votes
1 answer
135 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 ...
LeoVen's user avatar
  • 337
4 votes
2 answers
1k 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 ...
user200188's user avatar
3 votes
1 answer
110 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 ...
coderodde's user avatar
  • 28.9k
0 votes
1 answer
107 views

java.util.Set extension/implementation

Lately, I was working on some experimental java.util.Set extension, IdSet: ...
Wojciech Karwacki's user avatar
2 votes
1 answer
176 views

Powerset of collection in Clojure

Similar to this question, here's another implementation. Assume the input is already a set. ...
dimid's user avatar
  • 303
7 votes
1 answer
3k 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 ...
greg's user avatar
  • 1,017
4 votes
2 answers
4k 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 ...
greg's user avatar
  • 1,017
3 votes
1 answer
234 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. ...
Harshal's user avatar
  • 141
1 vote
1 answer
133 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 ...
Rick's user avatar
  • 586
1 vote
1 answer
3k 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 ...
Curious's user avatar
  • 13
0 votes
2 answers
2k 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. ...
Prathu Baronia's user avatar
1 vote
1 answer
314 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 ...
Onorio Catenacci's user avatar
4 votes
2 answers
6k 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 ...
jtdans's user avatar
  • 43
2 votes
1 answer
1k 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 ...
nuxie's user avatar
  • 23
2 votes
2 answers
162 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 ...
heapOverflow's user avatar
3 votes
3 answers
306 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 ...
briancaffey's user avatar
2 votes
1 answer
293 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 ...
Darcy Harding's user avatar
6 votes
2 answers
395 views

is_subset Python implementation

I wanted to ask for a code review for my implementation of Set: ...
NinjaG's user avatar
  • 2,469
11 votes
1 answer
9k 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 ...
Adam Jones's user avatar
1 vote
3 answers
3k 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 ...
cody.codes's user avatar
  • 1,935

15 30 50 per page