Questions tagged [algorithms]

Mathematical questions about Algorithms, including the analysis of algorithms, combinatorial algorithms, proofs of correctness, invariants, and semantic analyses. See also (computational-mathematics) and (computational-complexity).

An algorithm is an unambiguous specification of how to solve a class of problems. The study of algorithms is the branch of mathematics that specializes in finding efficient (mostly in the terms of time and space complexity) for various computational problems. It often involves combinatorics, number theory and geometry.

The field also includes data structures, computational models and proofs of lower bounds for certain algorithms.

See also and .

10691 questions
45
votes
3 answers

How do I calculate Euclidean and Manhattan distance by hand?

I have a practice problem that I am working on (artificial intelligence), but am unable to calculate the Euclidean and Manhattan distances by hand using the following values: x1: 1.0, 3.2, 4.8, 0.1, 3.2, 0.6, 2.2, 1.1 x2: 0.1, 5.2, 1.9, 4.2, 1.9,…
SnookerFan
  • 581
  • 1
  • 4
  • 10
39
votes
3 answers

Non-power-of-2 FFT's?

If I have a program that can compute FFT's for sizes that are powers of 2, how can I use it to compute FFT's for other sizes? I have read that I can supposedly zero-pad the original points, but I'm lost as to how this gives me the correct answer. If…
user541686
  • 12,494
  • 15
  • 48
  • 93
39
votes
6 answers

Efficiently finding two squares which sum to a prime

The web is littered with any number of pages (example) giving an existence and uniqueness proof that a pair of squares can be found summing to primes congruent to 1 mod 4 (and also that there are no such pairs for primes congruent to 3 mod…
timday
  • 654
  • 1
  • 7
  • 12
38
votes
1 answer

Is War necessarily finite?

War is an cardgame played by children and drunk college students which involves no strategic choices on either side. The outcome is determined by the dealing of the cards. These are the rules. A standard $52$ card deck is shuffled and dealt…
37
votes
3 answers

Computational complexity of least square regression operation

In a least square regression algorithm, I have to do the following operations to compute regression coefficients: Matrix multiplication, complexity: $O(C^2N)$ Matrix inversion, complexity: $O(C^3)$ Matrix multiplication, complexity:…
Andree
  • 473
  • 1
  • 4
  • 6
37
votes
3 answers

Quickest way to determine a polynomial with positive integer coefficients

Suppose that you are given a polynomial $p(x)$ as a black box (i.e. some oracle, to which you feed $x$ and it returns $p(x)$). It is known that the coefficients of $p(x)$ are all positive integers. How do you determine what $p(x)$ is in the quickest…
gt6989b
  • 52,194
  • 2
  • 33
  • 68
36
votes
10 answers

Efficient way to determine if a number is Perfect Square

Is there an efficient method to determine if a very large number (300 - 600 digits) is a perfect square without finding its square root. I tried finding the square root but I realized that even for perfect squares, it wasn't efficient (I used…
Obinna Okechukwu
  • 1,829
  • 1
  • 15
  • 24
36
votes
3 answers

Is there (or can there be) a general algorithm to solve Rubik's cubes of any dimension?

I love solving Rubik's cube (the usual 3D one). But, a lecture by Matt Parker at the Royal Institute (YouTube Link) led me to an app that can simulate a four dimensional rubik's cube. But unfortunately it was so complex, that I soon got bored as I…
36
votes
4 answers

Calculator algorithms

Does there exist a good reference on the algorithms used by calculators, especially on the trigonometric and transcendental functions? I would still like to know how Casio generates its random numbers. I still wonder if they are any good.
John Smith
  • 2,260
  • 2
  • 20
  • 26
35
votes
7 answers

How can I find the square root using pen and paper?

Okay, I know this is very basic question. I learned 2 methods in school. But now, I forget one. Here is a simple method that I know. Find the prime divisors of the number Omit the half of numbers that have been appeared even times multiply the…
Shiplu Mokaddim
  • 961
  • 2
  • 9
  • 18
34
votes
2 answers

Can every number be written as a small sum of sums of squares?

In a practice for a programming competition, one problem asked us to find the smallest number of pyramids which can be built using exactly $n$ blocks, where pyramids have either $k\times k, (k-1)\times (k-1),\ldots,1\times 1$ blocks on each level or…
Alex Becker
  • 58,347
  • 7
  • 124
  • 180
34
votes
3 answers

Is factoring polynomials as hard as factoring integers?

There seems to be a consensus that factorization of integers is hard (in some precise computational sense.) Is it known whether polynomial factorization is computationally easy or hard? One thing I originally thought was that if we could factor…
Chris Brooks
  • 6,967
  • 3
  • 38
  • 61
33
votes
0 answers

Algorithm to find primes up to $n$ in $O\left(\frac{n}{\log n}\right)$?

Consider the problem of given an integer $n$, generating a list of the primes not greater than $n$. An optimized version of the Sieve of Eratosthenes can do such task in $O(n)$, while the more modern Sieve of Atkin can do it in…
Rodrigo
  • 941
  • 6
  • 16
33
votes
2 answers

Calculate variance from a stream of sample values

I'd like to calculate a standard deviation for a very large (but known) number of sample values, with the highest accuracy possible. The number of samples is larger than can be efficiently stored in memory. The basic variance formula is: $\sigma^2…
user6677
  • 433
  • 1
  • 4
  • 5
32
votes
12 answers

Computing irrational numbers

I am genuinely curious, how do people compute decimal digits of irrational numbers in general, and $\pi$ or nth roots of integers in particular? How do they reach arbitrary accuracy?
user242891