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").
2
votes
1answer
89 views
IEnumerable and Predicate sets in .NET (complete, explained)
See a revised version in the answer below
GitHub Repository
Previously: Countable and uncountable sets in .NET (clean version).
Thesis There is a full featured support of countable sets in .NET:...
1
vote
0answers
49 views
Countable and uncountable sets in .NET (set operators, demo)
Up-to-date version: IEnumerable and Predicate Sets in .NET (Complete, Explained).
Previously: Countable and uncountable sets in .NET (clean version).
Disclaimer: Please do not interpret my attempts ...
6
votes
5answers
667 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 ...
2
votes
1answer
77 views
Countable and uncountable sets in .NET (clean version)
Sorry, it used to be some retired garbage in Countable and uncountable sets. Now and here it is clean.
P.S. I would not like to say that this stuff is about to replace functional programming :) No, ...
3
votes
2answers
112 views
Countable and uncountable sets in .NET (IEnumerable and Predicate)
There is a full featured support of countable sets in .NET: IEnumerable<T>. What about uncountable sets; sets defined by predicate? How can they be ...
2
votes
1answer
33 views
DisjointSet with O(1) find and O(1) amortised union
Does this code outperform the common implementation with path-compression and union-by-rank? I'm still okay with a review.
GitHub
...
3
votes
2answers
93 views
Determining if two Strings have common subtrings of a given length in Java
Problem:
Given 2 strings, consider all the substrings within them of length
len. Len will be 1 or more. Returns true if there are any such
substrings which appear in both strings. Compute ...
1
vote
0answers
36 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 ...
4
votes
1answer
127 views
VERY simple C# Set implementation
This is not meant to solve any insane real world problems. I just want to make sure my Set logic is right and the code looks okay. It feels weird implementing it with a ...
3
votes
0answers
119 views
Conways Game of Life using unordered set of coordinates
Previously I had been using an array of bool(dead/live) to represent cells. I looked on code review to see how other people have implemented Conway's Game of Life. Someone in the comments of a post ...
1
vote
1answer
24 views
3
votes
1answer
64 views
List union implementation
I'm trying to implement union from the standard Data.List library. I know it's reinventing the wheel, but reimplementing ...
3
votes
1answer
65 views
Improving Speeds of Tokenisation of large word list for distinct combinations
I'm having trouble with a current algorithm I'm writing that takes a corpa, a list of characters in sets (1 one or larger) with a frequency number attached to it. Against another list of character ...
2
votes
0answers
92 views
An AVL-tree based order statistic tree in Java
I have this java.util.Set implementation that is based on AVL-trees, which implies that the set is sorted. However, it provides two additional operations:
...
1
vote
0answers
42 views
Persistent set (Red black tree) - follow up
Follow up of this question
Things I changed:
Fixed some typos
Renamed variables and method to more descriptive names.(Eliminated 1 letter variables)
Added static method ...
2
votes
1answer
91 views
Persistent set (Red black tree)
This is a partially persistent data structure using a red black tree. It will copy \$O(lg(n))\$ items for each remove or add operation.
...
1
vote
0answers
745 views
Find maximum distance between two adjacent values in a given array [closed]
The following is code I wrote to solve a codility coding test. This scored 77% on correctness & 50% on performance. I need help in improving it further.
Problem statement:
Given a non-...
8
votes
3answers
306 views
3
votes
2answers
113 views
Get missing letters - TopCoder challenge
I'm working on a TopCoder problem which seeks to find the letters preventing an input sentence from being a pangram in all caps, alphabetical order.
MissingLetters.h
...
3
votes
1answer
179 views
Duplicate integers in an array
Code shows duplicate values of integers in an array with indexes and the number of occurrences. Can you please critique my code and provide your thoughts on where I should improve my code?
...
5
votes
2answers
196 views
Find the rarest in a map
Write a method rarest that accepts a map whose keys are strings and
whose values are integers as a parameter and returns the integer value
that occurs the fewest times in the map. If there is a ...
2
votes
2answers
99 views
Immutable subclass of a Set class
If I'm creating an immutable class from an existing class, should I override methods that mutate the property or have an instance of it and write my own methods to read from the property?
I have an ...
5
votes
3answers
401 views
Duplicate words in a text
Here is a simplified implementation to obtain the duplicate words in a text using lambda expressions.
...
3
votes
1answer
565 views
Calculate pairs in a Set (“Sherlock and Pairs” HackerRank challenge)
I have started reading clean code and want to improve my coding practices. Here is my attempt at solving an online puzzle. Please review the code and let me know how could I have written it better in ...
5
votes
1answer
269 views
Implementation of Set data type in Haskell
I'm an advanced beginner Haskell programmer. I implemented a set data type in Haskell and I wanted to find out if I made correct choices when writing it. Would there be a way to improve some of the ...
11
votes
3answers
340 views
“AI” chat program
I've thrown together this simple chat program, and while it works. I think it could certainly use some improvement. Here's how it works.
Obtain user input by removing all punctuation from the input ...
6
votes
2answers
1k views
Sudoku Puzzle Solver
I have written a program to solve Sudoku puzzles as a (fun?) way to learn Python. It solves puzzles as a human would, using reasoning algorithms rather than brute force/backtracking, as I thought it ...
4
votes
4answers
122 views
Increase performance of a method which finds the element removed from an array
Imagine that you have a TreeSet of numbers, and you copy them into an array, but you remove one element of it. You want to know the element removed.
...
2
votes
1answer
85 views
Populate the list based on which datacenter code is running on
This is a follow on to : Efficiently detect datacenter based on server hostname and return the full path.
I have a library which is running in different datacenters in production. I have three ...
2
votes
1answer
160 views
Off-line minimum using disjoint sets
The off-line minimum problem asks us to maintain a dynamic set T of
elements from the domain (1..n) under the operation INSERT and
EXTRACT-MIN. We are give a sequence S of n INSERT and m EXTRACT-...
2
votes
1answer
71 views
Dealing with input and output in Matlab
I just wrote a program which performed some elementary set operations as you can see below. It's the first time I have used input and output of text files so I am mainly looking for critique on that, ...
3
votes
3answers
448 views
Set Class Implementation ADT
Is the following functions implemented correctly for the set class?
Please let me know if any changes need to be made.
...
12
votes
1answer
221 views
Chack miy spellang pleez
For my CS2 project, I am supposed to implement a spell-checker. It is
supposed to follow the following:
Prompt the user for the name of the file containing the dictionary
of correctly ...
2
votes
2answers
163 views
A set of names and a request with asterisks
I have a set of names and a request with asterisks. An asterisk can be replaced with any letter.
For example, there is a set of names: hasad, ahmed, fizo. And there are a few sample requests: hasad, ...
5
votes
3answers
551 views
“Set” your expectations low for this ADT
For my third assignment in CS2, I was given the following:
A set is a special bag that does not allow duplicates. Specify each
operation for a set of objects by stating its purpose, by ...
6
votes
1answer
65 views
Designing a Variable Set
In my application, I need to allow the user to store variables. Variables can only be of specific types, but I effectively handle all variables the same way no matter the type. I would also like to ...
6
votes
5answers
4k views
Number of distinct elements in an array
This is my solution to find the Number of distinct elements in an array. Is there away fast way to do this? It run-time is O(N).
...
8
votes
3answers
507 views
Two sets came to an intersection
Challenge:
Print set intersections.
Specifications:
Your program should accept as its first argument a path to a filename.
Each line in the file is a test case.
Each test case contain ...
2
votes
2answers
165 views
Is there some way of taking advantage of code reuse in this example?
I am implementing a set, using an array as the backend.
Here is how I declared it (and some method implementations):
...
0
votes
1answer
98 views
Java class: for getOrder, getData, updateData operation
Problem Statement :
Design a class for three operations for given set of integers :
...
3
votes
1answer
86 views
Calculating set difference of lists with or without intermediate variables
Which form of the method do you find more readable?
Version with local variables:
...
5
votes
4answers
236 views
Faster Way of Comparing Generic Sets
The following extension method is the limiting factor in the performance of an application I am developing, according to Visual Studio 2012 Performance Analysis profiler.
Is there a faster way to ...
2
votes
1answer
389 views
Finding the subsets of a set
I am trying to write a procedure that finds the power set of a list, that is, the set of 2n subsets (where n is the number of elements in the list). I simply quite find all the subsets. I feel my code ...
2
votes
1answer
70 views
Iterate over items in a set of dicts
I'm using the following code to initialise 8 I/O-ports (i.e. GPIO pins on a Raspberry Pi). That's 4 x 2 pins, each duo controls a switch, A to D, and each duo consists of a pin for On and a pin for ...
5
votes
2answers
1k views
Concurrent Linked Hash Set
Basically I want to create a concurrent LinkedHashSet which returns proper size too.
I am mainly concerned about adding and removing iterations. Suggestions ...
5
votes
1answer
340 views
Producing the intersection of several sequences
Based on this SO answer I have created a method that produce the set intersection of several sequences:
...
3
votes
1answer
79 views
Get object in a Set that is an instance of a generically specified type
Are there ways to simplify the getLoadComponent(Class<T> type) method? The call ...
11
votes
1answer
616 views
Nested Sets in JavaScript
I created a procedural implementation of the nested set model in JavaScript.
The use case for this small library was that the front-end(presented as an MVC) needs to traverse hierarchical data from ...
7
votes
2answers
273 views
Convert a list of sets into the minimum list of non-intersecting sets
I have a list of sets. The same items may appear in multiple sets.
I want to transform this into a new list of sets where:
Each item only appears once in the entire list of sets.
For each set in ...
12
votes
1answer
367 views
Implementing a generic and covariant Set in Scala
I'm struggling with manually implementing a simple purely functional Set that's also generic and covariant on its type parameter:
...