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
7
votes
2 answers

Least number of perfect square numbers that sums upto n

The question is: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. Link to the question Example Given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13, return 2 because…
7
votes
2 answers

Given an array of integers, find the minimum number of steps to make each value equal

I was practicing algorithms and came across this question. I was not able to solve it. I read the editorial provided but it doesn't explain the concept or idea behind the solution.here's the question link(Question). Problem Statement--> N boys are…
Divyanshu
  • 363
  • 2
  • 12
7
votes
1 answer

Apparent error in Matlab's perms function

p = perms([0:2]) p = 2 1 0 2 0 1 1 2 0 1 0 2 0 1 2 0 2 1 This function is supposed to display the permutations of a vector in reverse lexicographical order. Hence, I would expect the last…
7
votes
1 answer

What is a good algorithm to check whether or not a number exist in multiple sets without searching them all?

Scenario Let's say you have multiple databases in 3 zones. Zone A, B, and C. Each zone in different geographical location. At the same time, you have an application that will route username and password based on the geographical location of the…
Ahmed
  • 2,825
  • 1
  • 25
  • 39
7
votes
2 answers

Rectangle Coordinates With Respect To The Rotation Angle

I am trying to create custom components in Android using Surfaceview and canvas drawing. The components are re-sizable and rotatable by touching. Consider creating an image view its Top,Right,Bottom, and Left edges are scalable by touching and…
MobDev
  • 1,489
  • 1
  • 17
  • 26
7
votes
2 answers

P versus NP Clarification

Quoted from wikipedia, the P vs NP problem, regarding the time complexity of algorithms "... asks whether every problem whose solution can be quickly verified by a computer can also be quickly solved by a computer." I am hoping that somebody can…
kjh
  • 3,407
  • 8
  • 42
  • 79
7
votes
3 answers

Complexity of a double for loop

I am trying to figure out the complexity of a for loop using Big O notation. I have done this before in my other classes, but this one is more rigorous than the others because it is on the actual algorithm. The code is as follows: for(cnt = 0,…
7
votes
1 answer

Complexity for converting any propositional formula to CNF format

What is the complexity for converting any propositional formula to CNF format? Is it an NP-complete problem?
william007
  • 17,375
  • 25
  • 118
  • 194
6
votes
4 answers

How to find a 2 unpaired elements in array?

You have an array with n=2k+2 elements where 2 elements haven't pair. Example for 8 elemets array: 1 2 3 47 3 1 2 0. "47" and "0" haven't pair in array. If I have array where only 1 element has't pair, I solve this problem with XOR. But I have 2…
rodart
  • 77
  • 4
6
votes
4 answers

algorithm to trace border in 2D array

I have a 2D array of integers that represent groupings (crystal grains) on a 2D surface. something like this: (each pixel of that image is assigned an integer depending on the group it belongs to, so every red pixel is assigned 1 for example, every…
Markus Hütter
  • 7,796
  • 1
  • 36
  • 63
6
votes
2 answers

How many different possible ways can persons be seated in a round table?

I am developing an algorithm and am looking at a possibility of the maximum number of iterations before arriving at a conclusion. In real world, it is similar to the Classical Round Table seating problem. Can you please tell me the maximum number of…
Kiran
  • 8,034
  • 36
  • 110
  • 176
6
votes
4 answers

Equations Equality test (in C++ or with Unix tools) (algebra functions isomorphism)

I am looking for C++ open-source library (or just open-source Unix tool) to do: Equality test on Equations . Equations can be build during runtime as AST Trees, string or other format. Equations will mostly be simple algebra ones, with some…
6
votes
5 answers

Expanding Programming Capabilities with Better Math

I have come to the realization that sooner or later I'm going to want to build more complex applications that will make better decisions rather just simple if/else statements. My math background right now is at basic trigonometry, I would like to…
6
votes
4 answers

Implementing probability distribution function in Java

I'm trying to implement a probability distribution function in java where it returns the ith entry in the array with probability: Fi = 6i(n-i) / (n3 - n) where n is the array length i.e. for an array length 4: P1 = 3/10, P2 = 4/10, P3 = 3/10, P4 =…
user528676
  • 197
  • 1
  • 3
  • 12
6
votes
3 answers

How to plot tan(x) with pyplot and numpy

Code: import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10000) plt.plot(x, np.tan(x)) plt.show() Expected result: The result I get:
snzm
  • 139
  • 1
  • 1
  • 10