Questions tagged [discrete-mathematics]

NOTE: Only questions about software development related to discrete mathematics are on topic. Discrete mathematics is the branch of mathematics concerned with discrete phenomena – as opposed to continuous phenomena like geometry, real analysis, physics, etc. Typical discrete math topics are discrete probability, combinatorics, graph theory, algorithms and complexity, but also matrices, difference equations, recurrences.

Discrete mathematics is the branch of mathematics concerned with discrete phenomena – as opposed to continuous phenomena such as geometry, real analysis, and physics. Typical discrete math topics are discrete probability, combinatorics, graph theory, algorithms, and complexity, but also matrices, difference equations, and recurrences. Applications abound in computer science, as many computer models are built upon discrete elements.

Questions relating to discrete mathematics must still be programming-related. Questions that are not programming-related may be asked on mathematics.stackexchange.com.

1083 questions
18
votes
11 answers

Finding the closest fibonacci numbers

I am trying to solve a bigger problem, and I think that an important part of the program is spent on inefficient computations. I need to compute for a given number N, the interval [P, Q], where P is the biggest fibonacci number that is <= to N, and…
user852689
  • 751
  • 1
  • 10
  • 21
17
votes
1 answer

What are some techniques I could use to help gain a better understanding of how the concepts in discrete math are used in programming?

I am trying to gain a better understanding of how discrete math concepts (e.g. set theory) are used in programming. I am familiar with high-school mathematics and have basic understanding of the terms and concepts used in discrete mathematics I…
Salil
  • 9,534
  • 9
  • 42
  • 56
15
votes
3 answers

How to find multiplicative partitions of any integer?

I'm looking for an efficient algorithm for computing the multiplicative partitions for any given integer. For example, the number of such partitions for 12 is 4, which are 12 = 12 x 1 = 4 x 3 = 2 x 2 x 3 = 2 x 6 I've read the wikipedia article for…
TCSGrad
  • 11,898
  • 14
  • 49
  • 70
15
votes
1 answer

Can't find the right energy using scipy.signal.welch

For a given discret time signal x(t) with spacing dt (which is equal to 1/fs, fs being the sample rate), the energy is: E[x(t)] = sum(abs(x)**2.0)/fs Then I do a DFT of x(t): x_tf = np.fft.fftshift( np.fft.fft( x ) ) / ( fs * ( 2.0 * np.pi ) ** 0.5…
gravedigger
  • 359
  • 1
  • 3
  • 13
15
votes
5 answers

Allocate an array of integers proportionally compensating for rounding errors

I have an array of non-negative values. I want to build an array of values who's sum is 20 so that they are proportional to the first array. This would be an easy problem, except that I want the proportional array to sum to exactly 20, compensating…
sea-rob
  • 2,275
  • 1
  • 22
  • 22
14
votes
9 answers

How can I check Hamming Weight without converting to binary?

How can I get the number of "1"s in the binary representation of a number without actually converting and counting ? e.g. def number_of_ones(n): # do something # I want to MAKE this FASTER (computationally less complex). c = 0 …
Pratik Deoghare
  • 35,497
  • 30
  • 100
  • 146
14
votes
1 answer

how to minimize a function with discrete variable values in scipy

I'm trying to optimize a target function that has multiple input variables (between 24 and 30). These variables are samples of three different statistical variables, and target function values are t-test probability values. An error function…
nagylzs
  • 3,954
  • 6
  • 39
  • 70
13
votes
3 answers

Please explain to me the solution for the problem below

Problem: Consider the problem of adding two n-bit binary integers, stored in two n-element arrays A and B. The sum of the two integers should be stored in binary form in an (n + 1)-element array C. State the problem formally and write pseudocode for…
user_1357
  • 7,766
  • 13
  • 63
  • 106
13
votes
2 answers

How to find the local minima of a smooth multidimensional array in NumPy efficiently?

Say I have an array in NumPy containing evaluations of a continuous differentiable function, and I want to find the local minima. There is no noise, so every point whose value is lower than the values of all its neighbors meets my criterion for a…
ptomato
  • 56,175
  • 13
  • 112
  • 165
13
votes
6 answers

How to sum sequence?

How can I sum the following sequence: ⌊n/1⌋ + ⌊n/2⌋ + ⌊n/3⌋ + ... + ⌊n/n⌋ This is simply O(n) solution on C++: #include int main() { int n; std::cin>>n; unsigned long long res=0; for (int i=1;i<=n;i++) { res+= n/i; …
vasylysk
  • 132
  • 10
13
votes
5 answers

count of distinct acyclic paths from A[a,b] to A[c,d]?

I'm writing a sokoban solver for fun and practice, it uses a simple algorithm (something like BFS with a bit of difference). now i want to estimate its running time ( O and omega). but need to know how to calculate count of acyclic paths from a…
sorush-r
  • 10,490
  • 17
  • 89
  • 173
13
votes
1 answer

What is the "Law of the Eight"?

While studying this document on the Evolution of JPEG, i came across "The law of the eight" in Section 7.3 of the above document. Despite the introduction of other block sizes from 1 to 16 with the SmartScale extension, beyond the fixed size 8 in…
TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
13
votes
12 answers

How can I learn higher-level programming-related math without much formal training?

I haven't taken any math classes above basic college calculus. However, in the course of my programming work, I've picked up a lot of math and comp sci from blogs and reading, and I genuinely believe I have a decent mathematical mind. I enjoy and…
levand
  • 8,440
  • 3
  • 41
  • 54
12
votes
5 answers

Difference between Discrete Structures and Discrete Mathematics

I haven't yet found a good answer. Or any answer, for that matter. I've been asked to teach a discrete structures for CS course, but at the same time make sure it's not a discrete mathematics course -- that's offered by the Mathematics…
Barry Brown
  • 20,233
  • 15
  • 69
  • 105
12
votes
10 answers

Compute a derivative using discrete methods

I am looking for a method to compute a derivative using a discrete and fast method. Since now I do not know the type of equation I have, I am looking for discrete methods analog to the ones that we can find for the integral such as, the Euler…
Ryan
  • 131
  • 1
  • 2
  • 8
1
2
3
72 73