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

How to find the periodicity in data?

How to find the periodicity in data? I have a dataset (an array) and I need to find the periodicity in it. How should I proceed? Somebody said I can use FFT but I am not sure how will it give me the p...

18 Dec at 20:26

C# implementation of Google's 'Encoded Polyline Algorithm'

C# implementation of Google's 'Encoded Polyline Algorithm' Does anyone have a concise and robust implementation of Google's [Encoded Polyline Algorithm](http://code.google.com/apis/maps/documentation/...

4 Oct at 02:37

How to create pastel colors programmatically in C#?

How to create pastel colors programmatically in C#? To generate them equally spaced out based on the number of colors wanted. Something that looks like this if 8 is given for the count specified: ![en...

19 Oct at 04:39

Finding all possible combinations of numbers to reach a given sum

Finding all possible combinations of numbers to reach a given sum How would you go about testing all possible combinations of additions from a given set `N` of numbers so they add up to a given final ...

Swap two variables without using a temporary variable

Swap two variables without using a temporary variable I'd like to be able to swap two variables without the use of a temporary variable in C#. Can this be done?

16 Sep at 03:33

Name of a particular algorithm

Name of a particular algorithm I'm trying to determine the name of the algorithm which will determine if a set of blocks listed as Xl,Yl-X2Y2 are part of a contiguous larger block. I'm just really loo...

28 Nov at 17:31

Calculate distance between two latitude-longitude points? (Haversine formula)

Calculate distance between two latitude-longitude points? (Haversine formula) How do I calculate the distance between two points specified by latitude and longitude? For clarification, I'd like the di...

How to find the kth largest element in an unsorted array of length n in O(n)?

How to find the kth largest element in an unsorted array of length n in O(n)? I believe there's a way to find the kth largest element in an unsorted array of length n in O(n). Or perhaps it's "expecte...

15 Sep at 02:37

Unfamiliar symbol in algorithm: what does ∀ mean?

Unfamiliar symbol in algorithm: what does ∀ mean? I'm reading about an algorithm (it's a path-finding algorithm based on A*), and it contains a mathematical symbol I'm unfamiliar with: ∀ Here is the c...

30 Jan at 13:13

I need an optimal algorithm to find the largest divisor of a number N. Preferably in C++ or C#

I need an optimal algorithm to find the largest divisor of a number N. Preferably in C++ or C# I am currently using the following code but its very slow for large numbers ``` static int divisor(int nu...

23 Aug at 06:47

Perlin Noise for 1D?

Perlin Noise for 1D? Try as hard as I can, I cannot find any real tutorials on Perlin\Samplex Noise in 1D. I've searched all around the internet but just cannot find anything. Any sites I do come acro...

10 Jan at 05:21

Best way to randomize an array with .NET

Best way to randomize an array with .NET What is the best way to randomize an array of strings with .NET? My array contains about 500 strings and I'd like to create a new `Array` with the same strings...

24 Oct at 16:19

How to reverse a number as an integer and not as a string?

How to reverse a number as an integer and not as a string? I came across a question "How can one reverse a number as an integer and not as a string?" Could anyone please help me to find out the answer...

19 May at 14:47

Is it possible to get all arguments of a function as single object inside that function?

Is it possible to get all arguments of a function as single object inside that function? In PHP there is [func_num_args](http://php.net/manual/en/function.func-num-args.php) and [func_get_args](http:/...

What are the practical factors to consider when choosing between Depth-First Search (DFS) and Breadth-First Search (BFS)?

What are the practical factors to consider when choosing between Depth-First Search (DFS) and Breadth-First Search (BFS)? I understand the differences between DFS and BFS, but I'm interested to know w...

Multiple Date range comparison for overlap: how to do it efficiently?

Multiple Date range comparison for overlap: how to do it efficiently? To check for overlap in two different dateranges, `{Start1, End1}` and `{Start2, End2}` I am checking: The question is, . If I hav...

What's the fastest way to compare two arrays for equality?

What's the fastest way to compare two arrays for equality? I have two arrays of objects which are likely to have the same values, but in a different order, e.g. I wish to treat these two arrays as equ...

11 Nov at 09:50

C# Determine Duplicate in List

C# Determine Duplicate in List Requirement: In an unsorted List, determine if a duplicate exists. The typical way I would do this is an n-squared nested loop. I'm wondering how others solve this. Is t...

22 Feb at 15:59

How to draw gridline on WPF Canvas?

How to draw gridline on WPF Canvas? I need to build a function drawing gridline on the canvas in WPF: ![example gridline](https://i.stack.imgur.com/XHVJv.png) How would I go about this?

22 Jun at 02:42

Calculate mean and standard deviation from a vector of samples in C++ using Boost

Calculate mean and standard deviation from a vector of samples in C++ using Boost Is there a way to calculate mean and standard deviation for a vector containing samples using [Boost](http://en.wikipe...

17 Dec at 18:4

Big O, how do you calculate/approximate it?

Big O, how do you calculate/approximate it? Most people with a degree in CS will certainly know what [Big O stands for](http://www.nist.gov/dads/HTML/bigOnotation.html). It helps us to measure how wel...

Fibonacci, Binary, or Binomial heap in c#?

Fibonacci, Binary, or Binomial heap in c#? Are there any heap data structure implementations out there, fibonacci, binary, or binomial? Reference: These are data structures used to implement priority ...

9 Jan at 16:50

Effective method to hide email from spam bots

Effective method to hide email from spam bots On my homepage, I'm using this method to hide my email from spam bots: What do you think about it? Is it effective? What other methods do you know or use?

26 Apr at 10:28

Recommended Open Source C# algorithms & data structures libraries

Recommended Open Source C# algorithms & data structures libraries What algorithms libraries can you recommend? The basic criteria are: - - - Algorithms libraries I have used and can recommend: - [Quic...

7 Aug at 13:57

Best way to find position in the Stream where given byte sequence starts

Best way to find position in the Stream where given byte sequence starts How do you think what is the best way to find position in the System.Stream where given byte sequence starts (first occurence):...

24 Sep at 14:17