tagged [algorithm]

Difference between Divide and Conquer Algo and Dynamic Programming

Difference between Divide and Conquer Algo and Dynamic Programming What is the difference between Divide and Conquer Algorithms and Dynamic Programming Algorithms? How are the two terms different? I d...

Reversible shuffle algorithm using a key

Reversible shuffle algorithm using a key How would I code a reversible shuffle algorithm in C# which uses a key to shuffle and can be reversed to the original state? For instance, I have a string: "He...

29 Aug at 23:24

JavaScript - get the first day of the week from current date

JavaScript - get the first day of the week from current date I need the fastest way to get the first day of the week. For example: today is the 11th of November, and a Thursday; and I want the first d...

5 Jan at 09:13

Finding all combinations of well-formed brackets

Finding all combinations of well-formed brackets This came up while talking to a friend and I thought I'd ask here since it's an interesting problem and would like to see other people's solutions. The...

1 Feb at 00:23

Checking if all elements in a list are unique

Checking if all elements in a list are unique What is the best way (best as in the conventional way) of checking whether all elements in a list are unique? My current approach using a `Counter` is: Ca...

11 Mar at 23:14

Tarjan cycle detection help C#

Tarjan cycle detection help C# Here is a working C# implementation of tarjan's cycle detection. The algorithm is found here: [http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algo...

How are ssl certificates verified?

How are ssl certificates verified? What is the series of steps needed to securely verify a ssl certificate? My (very limited) understanding is that when you visit an https site, the server sends a cer...

16 Oct at 20:6

Best hashing algorithm in terms of hash collisions and performance for strings

Best hashing algorithm in terms of hash collisions and performance for strings What would be the best hashing algorithm if we had the following priorities (in that order): 1. Minimal hash collisions 2...

14 Apr at 19:56

Best algorithm for detecting cycles in a directed graph

Best algorithm for detecting cycles in a directed graph Is there an efficient algorithm for detecting cycles within a directed graph? I have a directed graph representing a schedule of jobs that need ...

Finding the position of the maximum element

Finding the position of the maximum element Is there a standard function that returns the position (not value) of the maximum element of an array of values? For example: Suppose I have an array like t...

13 Jul at 22:13

Pythonic way to check if a list is sorted or not

Pythonic way to check if a list is sorted or not Is there a pythonic way to check if a list is already sorted in `ASC` or `DESC` something like `isttimestamps.isSorted()` that returns `True` or `False...

21 Jan at 12:44

Generate large prime number with specified last digits

Generate large prime number with specified last digits Was wondering how is it possible to generate 512 bit (155 decimal digits) prime number, last five decimal digits of which are specified/fixed (eg...

4 Dec at 17:32

traveling salesman problem, 2-opt algorithm c# implementation

traveling salesman problem, 2-opt algorithm c# implementation Can someone give me a code sample of 2-opt algorithm for traveling salesman problem. For now im using nearest neighbour to find the path b...

28 May at 10:54

Listing all permutations of a string/integer

Listing all permutations of a string/integer A common task in programming interviews (not from my experience of interviews though) is to take a string or an integer and list every possible permutation...

26 Dec at 16:38

Check for missing number in sequence

Check for missing number in sequence I have an `List` which contains 1,2,4,7,9 for example. I have a range from 0 to 10. Is there a way to determine what numbers are missing in that sequence? I though...

25 Feb at 18:39

How to compute frequency of data using FFT?

How to compute frequency of data using FFT? I want to know the frequency of data. I had a little bit idea that it can be done using FFT, but I am not sure how to do it. Once I passed the entire data t...

How to trim " a b c " into "a b c"

How to trim " a b c " into "a b c" > [How do I replace multiple spaces with a single space in C#?](https://stackoverflow.com/questions/206717/how-do-i-replace-multiple-spaces-with-a-single-space-in-c...

23 May at 11:52

C# hashcode for array of ints

C# hashcode for array of ints I have a class that internally is just an array of integers. Once constructed the array never changes. I'd like to pre-compute a good hashcode so that this class can be v...

4 Aug at 10:45

What is the most effective way for float and double comparison?

What is the most effective way for float and double comparison? What would be the most efficient way to compare two `double` or two `float` values? Simply doing this is not correct: But something like...

how to measure running time of algorithms in python

how to measure running time of algorithms in python > [Accurate timing of functions in python](https://stackoverflow.com/questions/889900/accurate-timing-of-functions-in-python) [accurately measure ...

23 May at 12:25

Algorithm to compare two images

Algorithm to compare two images Given two different image files (in whatever format I choose), I need to write a program to predict the chance if one being the illegal copy of another. The author of t...

Difference between 2 numbers

Difference between 2 numbers I need the perfect algorithm or C# function to calculate the difference (distance) between 2 decimal numbers. For example the difference between: and is and is and is a...

21 Jul at 07:58

Is there any code or algorithm for signature recognition?

Is there any code or algorithm for signature recognition? My users draw their signature in my application using touch events and I convert it to a bitmap. I want to extract unique specifications of ea...

Split String into smaller Strings by length variable

Split String into smaller Strings by length variable I'd like to break apart a String by a certain length variable. It needs to bounds check so as not explode when the last section of string is not as...

9 Jun at 21:15

Quickest way to find missing number in an array of numbers

Quickest way to find missing number in an array of numbers I have an array of numbers from 1 to 100 (both inclusive). The size of the array is 100. The numbers are randomly added to the array, but the...

16 Oct at 14:8