discrete-mathematics

Custom permutation, Equal distribution of pairs

柔情痞子 提交于 2019-12-04 10:29:04
I've been playing with a strange problem for a few weeks and can't seem to get the results I want. I'd like to take a permutation of a list of objects to get unique pairs. Then order them in a particular way to maximize equal distribution of the objects at any point in the list. This also means that if an object is at the beginning of a pair if should also be at the end of a pair soon after. No pairs can repeat. To clarify, here is an example. list (A,B,C,D) might result in the following: (A,B) (C,D) (B,A) (D,C) (A,C) (B,D) (C,A) (D,B) (A,D) (B,C) (D,A) (C,B) Notice, every letter is used every

Optimization problem - finding a maximum

核能气质少年 提交于 2019-12-04 09:38:21
I have a problem at hand which can be reduced to something like this : Assume a bunch of random points in a two-dimension plane X-Y where for each Y, there could be multiple points on X and for each X, there could be multiple points on Y. Whenever a point (Xi,Yi) is chosen, no other point with X = Xi OR Y = Yi can be chosen. We have to choose the maximum number of points. This can be reduced to simple maximum flow problem. If you have a point (xi, yi), in graph it should be represented with path from source S to point xi, from xi to yi and from yi to the last node (sink) T. Note, if we have

Theory of Object Oriented databases [closed]

与世无争的帅哥 提交于 2019-12-04 09:20:41
Please recommend some material about implementing Object-Oriented Databases for dynamic languages (interested in Ruby). I realise that OODBs do not have a good mathematical foundation, but still the information I could find is absolutely insufficient for me to start working on a new OODB. Thanks. Have a look at Won Kim's "Introduction to Object-Oriented Databases" . It's considered an authoritative source on the matter. EDIT: An alternative reference is "Object-Relational Database Development" by Paul Brown . It takes an object/relational approach, which may be interesting given the prevalence

Difference between Discrete Structures and Discrete Mathematics

非 Y 不嫁゛ 提交于 2019-12-04 09:19:10
问题 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 department. Many colleges offer a discrete structures course. There are also many DS textbooks. But when I look at the course syllabi and the textbook introductions, the term "discrete structures" is never used; they use "discrete mathematics" instead. DS only

Count of squarefree numbers in range

隐身守侯 提交于 2019-12-04 07:43:11
Given two numbers x and y , find count of numbers that are squarefree where squarefree number is one divisible by no perfect square, except 1 . For example, 10 is square-free but 18 is not, as it is divisible by 9 = 32 . Few positive square-free numbers are : 1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15 ... limits 1 <= X,Y <= 10^9 0 <= |X-Y| <= 10^6 x=10 , Y=15 gives ans=5 My approach is to generate all prime till squareroot(10^9) (sieve of eratosthenes), and check whether each number in given range divisible by square of prime . Count of such numbers is substracted from length of range to give square

What number in binary can only be represented as an approximation?

对着背影说爱祢 提交于 2019-12-04 02:11:39
问题 In decimal (base 10), 1/3 can only be approximated to 0.33333 repeating. What number is the equivalent in binary that can only be represented as an approximation? 回答1: 0.1 is one such example, as well as 0.2 This question is also similar to this other SO question, which already has very good answers. 回答2: A better question is to ask what numbers can be represented exactly in binary. Everything else can only be approximated or not represented at all. See What every computer scientist should

Uses of Ackermann function?

可紊 提交于 2019-12-03 11:53:17
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 any real uses ? Yes. The (inverse) Ackermann function appears in complexity analysis of algorithms. When it does, it means you can almost ignore that term since it grows so slowly (a lot like log(log ... log(n)...)) i.e. lg*(n). For example: Minimum Spanning Trees (also here ) and Disjoint Set forest construction. Also: Davenport-Scinzel sequences

Looking for C/C++ library calculating max of Gaussian curve using discrete values

假如想象 提交于 2019-12-03 10:08:14
I have some discrete values and assumption, that these values lie on a Gaussian curve. There should be an algorithm for max-calculation using only 3 discrete values. Do you know any library or code in C/C++ implementing this calculation? Thank you! P.S.: The original task is auto-focus implementation. I move a (microscope) camera and capture the pictures in different positions. The position having most different colors should have best focus. EDIT This was long time ago :-( I'just wanted to remove this question, but left it respecting the good answer. Matteo Italia You have three points that

How do I write a recursive function for a combination

不想你离开。 提交于 2019-12-03 10:01:19
I am going over recursive functions and i understand how to write basic ones, but I have a question on my study guide that I dont understand. . Write code for a recursive function named Combinations that computes nCr. Assume that nCr can be computed as follows: nCr = 1 if r = 0 or if r = n and nCr = (n-1)C(r-1) + (n-1)Cr Can someone please help me through this or explain in layman's terms? Thank you! The question really has all the information. It tells you how to compute nCr - and that a lot of the time, you compute it by computing another nCr (with smaller arguments). So your functions might

Allocate an array of integers proportionally compensating for rounding errors

最后都变了- 提交于 2019-12-03 08:12:29
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 for any rounding error. For example, the array input = [400, 400, 0, 0, 100, 50, 50] would yield output = [8, 8, 0, 0, 2, 1, 1] sum(output) = 20 However, most cases are going to have a lot of rounding errors, like input = [3, 3, 3, 3, 3, 3, 18] naively yields output = [1, 1, 1, 1, 1, 1, 10] sum(output) = 16 (ouch) Is there a good way to apportion