tagged [algorithm]

How can I calculate what date Good Friday falls on, given a year?

How can I calculate what date Good Friday falls on, given a year? Does anyone have a good algorithm to calculate what date Good Friday falls on given the year as an input? Preferably in C#.

What is the complexity of the sorted() function?

What is the complexity of the sorted() function? I have a list of lists and I am sorting them using the following Was wondering what is the runtime complexity of this python function?

18 Feb at 17:28

Select N random elements from a List<T> in C#

Select N random elements from a List in C# I need a quick algorithm to select 5 random elements from a generic list. For example, I'd like to get 5 random elements from a `List`.

How might I find the largest number contained in a JavaScript array?

How might I find the largest number contained in a JavaScript array? I have a simple JavaScript Array object containing a few numbers. Is there a function that would find the largest number in this ar...

4 Sep at 14:20

Equation for testing if a point is inside a circle

Equation for testing if a point is inside a circle If you have a circle with center `(center_x, center_y)` and radius `radius`, how do you test if a given point with coordinates `(x, y)` is inside the...

23 Jun at 15:30

HSL to RGB color conversion

HSL to RGB color conversion I am looking for an algorithm to convert between HSL color to RGB. It seems to me that HSL is not very widely used so I am not having much luck searching for a converter.

24 Nov at 03:8

How do you detect Credit card type based on number?

How do you detect Credit card type based on number? I'm trying to figure out how to detect the type of credit card based purely on its number. Does anyone know of a definitive, reliable way to find th...

How to determine the longest increasing subsequence using dynamic programming?

How to determine the longest increasing subsequence using dynamic programming? I have a set of integers. I want to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_incre...

How to create a trie in c#

How to create a trie in c# Does anyone know where I can find an example of how to construct a trie in C#? I'm trying to take a dictionary/list of words and create a trie with it.

30 Jul at 16:23

Javascript Array.sort implementation?

Javascript Array.sort implementation? Which algorithm does the JavaScript `Array#sort()` function use? I understand that it can take all manner of arguments and functions to perform different kinds of...

28 Jan at 14:18

What's the quickest way to compute log2 of an integer in C#?

What's the quickest way to compute log2 of an integer in C#? How can I most efficiently count the number of bits required by an integer (log base 2) in C#? For example:

23 Jan at 10:19

Picking a random element from a set

Picking a random element from a set How do I pick a random element from a set? I'm particularly interested in picking a random element from a HashSet or a LinkedHashSet, in Java. Solutions for other l...

Red eye reduction algorithm

Red eye reduction algorithm I need to implement red eye reduction for an application I am working on. Googling mostly provides links to commercial end-user products. Do you know a good red eye reducti...

25 Sep at 15:30

C# compare algorithms

C# compare algorithms Are there any open source algorithms in c# that solve the problem of creating a difference between two text files? It would be super cool if it had some way of highlighting what ...

19 Jul at 15:24

Converting a Uniform Distribution to a Normal Distribution

Converting a Uniform Distribution to a Normal Distribution How can I convert a uniform distribution (as most random number generators produce, e.g. between 0.0 and 1.0) into a normal distribution? Wha...

6 Jun at 20:56

Popularity algorithm

Popularity algorithm On SO 18 Joel mentioned an algorithm that would rank items based on their age and popularity and it's based on gravity. Could someone post this? C# would be lovely, but really any...

28 Aug at 14:26

Algorithm for checking transitivity of relation?

Algorithm for checking transitivity of relation? I need to check if relation is transitive or not? Would you please suggest some algorithm to check the transitivity of relations? I am storing relation...

10 Mar at 23:19

Creating all possible k combinations of n items in C++

Creating all possible k combinations of n items in C++ There are n people numbered from `1` to `n`. I have to write a code which produces and print all different combinations of `k` people from these ...

Why doesn't Dijkstra's algorithm work for negative weight edges?

Why doesn't Dijkstra's algorithm work for negative weight edges? Can somebody tell me why Dijkstra's algorithm for single source shortest path assumes that the edges must be non-negative. I am talking...

Efficient Algorithm for Bit Reversal (from MSB->LSB to LSB->MSB) in C

Efficient Algorithm for Bit Reversal (from MSB->LSB to LSB->MSB) in C What is the most efficient algorithm to achieve the following: `0010 0000 => 0000 0100` The conversion is from MSB->LSB to LSB->MS...

29 Jan at 03:53

Why do we check up to the square root of a number to determine if the number is prime?

Why do we check up to the square root of a number to determine if the number is prime? To test whether a number is prime or not, why do we have to test whether it is divisible only up to the square ro...

14 Apr at 17:52

How to round decimal value up to nearest 0.05 value?

How to round decimal value up to nearest 0.05 value? Is there any way to round up decimal value to its nearest 0.05 value in .Net? Ex: 7.125 -> 7.15 6.66 -> 6.7 If its now available can anyone provide...

19 Sep at 12:36

What is the time and space complexity of a breadth first and depth first tree traversal?

What is the time and space complexity of a breadth first and depth first tree traversal? Can someone explain with an example how we can calculate the time and space complexity of both these traversal ...

15 May at 11:19

Removing Duplicate Images

Removing Duplicate Images We have a collection of photo images sizing a few hundred gigs. A large number of the photos are visually duplicates, but with differing filesizes, resolution, compression et...

5 Dec at 16:28

How to write an algorithm to check if the sum of any two numbers in an array/list matches a given number?

How to write an algorithm to check if the sum of any two numbers in an array/list matches a given number? How can I write an algorithm to check if the sum of any two numbers in an array/list matches a...

19 Apr at 10:40