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
12
votes
1 answer

Removing minimum no of edges to disconnect two vertices in a graph

Here I am trying to disconnect two vertices in a graph with minimum edge removal possible. In this graph between two vertices A and Z you can find the answer in many ways. In optimal way you can remove just one edge from A to B. If there is any…
12
votes
3 answers

How to perform discrete optimization of functions over matrices?

I would like to optimize over all 30 by 30 matrices with entries that are 0 or 1. My objective function is the determinant. One way to do this would be some sort of stochastic gradient descent or simulated annealing. I looked at scipy.optimize but…
Simd
  • 19,447
  • 42
  • 136
  • 271
12
votes
5 answers

Fastest modular exponentiation in JavaScript

My problem is to compute (g^x) mod p quickly in JavaScript, where ^ is exponentiation, mod is the modulo operation. All inputs are nonnegative integers, x has about 256 bits, and p is a prime number of 2048 bits, and g may have up to 2048 bits. Most…
pts
  • 80,836
  • 20
  • 110
  • 183
12
votes
3 answers

Uses of Ackermann function?

In our discrete mathematics course in my university, the teacher shows his students the Ackermann function and assign the student to develop the function on paper. Beside being a benchmark for recursion optimisation, does the Ackermann function has…
12
votes
2 answers

Logic Proof of Associative Property for XOR

I came across a common programming interview problem: given a list of unsigned integers, find the one integer which occurs an odd number of times in the list. For example, if given the list: {2,3,5,2,5,5,3} the solution would be the integer 5 since…
Vilhelm Gray
  • 11,516
  • 10
  • 61
  • 114
12
votes
4 answers

Find the "largest" dense sub matrix in a large sparse matrix

Given a large sparse matrix (say 10k+ by 1M+) I need to find a subset, not necessarily continuous, of the rows and columns that form a dense matrix (all non-zero elements). I want this sub matrix to be as large as possible (not the largest sum, but…
BCS
  • 75,627
  • 68
  • 187
  • 294
11
votes
1 answer

Why do the power spectral density estimates from matplotlib.mlab.psd and scipy.signal.welch differ when the number of points per window is even?

matplotlib.mlab.psd(...) and scipy.signal.welch(...) both implement Welch's average periodogram method to estimate the power spectral density (PSD) of a signal. Assuming equivalent parameters are passed to each function, the returned PSD should be…
11
votes
7 answers

Find two missing numbers

We have a machine with O(1) memory and we want to pass n numbers (one by one) in the first pass, and then we exclude the two numbers and we will pass n-2 numbers to the machine. write an algorithm that finds missing numbers.
amin k
  • 1,692
  • 1
  • 12
  • 28
10
votes
3 answers

Is a given set of group elements a set of coset representatives?

I am afraid the question is a bit technical, but I hope someone might have stumbled into a similar subject, or give me a pointer of some kind. If G is a group (in the sense of algebraic structure), and if g1, ..., gn are elements of G, is there an…
DaG
  • 554
  • 1
  • 3
  • 16
10
votes
2 answers

Understanding why Floyd's tortoise and hare algorithm works when applied to an array of integers

I was trying to solve this leetcode problem https://leetcode.com/problems/find-the-duplicate-number/ using my own implementation of the tortoise and hare algorithm which resulted in an infinite loop when given the following array of…
krabinowitz
  • 357
  • 3
  • 11
10
votes
6 answers

Scoring System Suggestion - weighted mechanism?

I'm trying to validate a series of words that are provided by users. I'm trying to come up with a scoring system that will determine the likelihood that the series of words are indeed valid words. Assume the following input: xxx yyy zzz The first…
StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441
9
votes
4 answers

Fastest Algorithm to Find the Minimum Sum of Absolute Differences through List Rotation

By rotating 2 lists either from left to right, Find the smallest possible sum of the absolute value of the differences between each corresponding item in the two lists given they're the same length. Rotation Sample: List [0, 1, 2, 3, 4, 5] rotated…
lambduh
  • 43
  • 11
9
votes
5 answers

Maximum value of postage stamps on an envelope

The postage stamp problem is a mathematical riddle that asks what is the smallest postage value which cannot be placed on an envelope, if the letter can hold only a limited number of stamps, and these may only have certain specified face values. For…
Bobby S
  • 4,006
  • 9
  • 42
  • 61
9
votes
1 answer

Sum of numbers making a sequence

While watching the rugby last night I was wondering if any scores were impossible given you can only score points in lots of 3, 5 or 7. It didn't take long to work out that any number greater than 4 is attainable. 5=5, 6=3+3, 7=7, 8=3+5, 9=3+3+3,…
Daniel
  • 1,994
  • 15
  • 36
9
votes
1 answer

Why does my php code return inf?

I have a math problem where I am trying to calculate the total combination of values in a set... when I try and run my calculation it just returns INF instead of a number... $tally = 1; foreach ($output as $key => $er) { $tally = $tally…
Joey Canadian
  • 123
  • 1
  • 1
  • 6
1 2
3
72 73