theory

Why are interval comparisons (e.g: x < variable < y) not supported in most “mainstream” languages?

强颜欢笑 提交于 2019-12-24 20:36:42
问题 This might be a very simple question, or perhaps have been asked before but I couldn't really find an answer after a brief search here and via google. So taking the risk of having missed something similar to this, here goes my question. Why is it so that conditional statements checking for intervals are often not supported as they are, but instead implemented as block if s or using the && operator to bind together the two separate conditions? Admitted that it's not the whole world if I have

How many threads should I create?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 17:39:05
问题 Based on this question, I have a class, where its constructor does only some assignments and then there is a build() member function which actually does the job. I know that the number of objects I will have to build is in the range of [2, 16]. The actual number is a user parameter. I create my objects in a for loop like this for (int i = 0; i < n; ++i) { roots.push_back(RKD<DivisionSpace>(...)); } and then in another for loop I create the threads. Every thread calls build() in a chunk of

Addition operation versus multiplication operation

亡梦爱人 提交于 2019-12-24 16:46:29
问题 I know, that addition operation is more trivial than multiplication operation. But will there be any difference in execution time of 123456 * 3 and 123456 + 123456 + 123456 ? How exactly works multiplication? Do multiplication algorithms vary in different programming languages? How multiplication looks on low-level (i.e. Assembler code)? 回答1: In x86 assembly language the addition and multiplication operations look like this: ADD [operand1], [operand2] where operand1 can be register, operand 2

Grundy's game extended to more than two heaps

倾然丶 夕夏残阳落幕 提交于 2019-12-24 08:27:08
问题 How can In break a heap into two heaps in the Grundy's game? What about breaking a heap into any number of heaps (no two of them being equal)? 回答1: Games of this type are analyzed in great detail in the book series "Winning Ways for your Mathematical Plays". Most of the things you are looking for are probably in volume 1. You can also take a look at these links: Nimbers (Wikipedia), Sprague-Grundy theorem (Wikipedia) or do a search for "combinatorial game theory". My knowledge on this is

机器学习经典书籍

橙三吉。 提交于 2019-12-24 05:26:49
算法组 注册 登录 机器学习经典书籍 机器学习 machine-learning 书单 1 / 7 sys 14年12月 6 前面有一篇 机器学习经典论文/survey合集 784 。本文总结了 机器学习 100 的经典书籍,包括数学基础和算法理论的书籍。本文会保持更新,欢迎推荐。 入门书单 《数学之美》 PDF 2.2K 作者吴军大家都很熟悉。以极为通俗的语言讲述了数学在机器学习和自然语言处理等领域的应用。 《Programming Collective Intelligence》(《集体智慧编程》) PDF 1.2K 作者Toby Segaran也是《BeautifulData : The Stories Behind Elegant Data Solutions》(《数据之美:解密优雅数据解决方案背后的故事》)的作者。这本书最大的优势就是里面没有理论推导和复杂的数学公式,是很不错的入门书。目前中文版已经脱销,对于有志于这个领域的人来说,英文的pdf是个不错的选择,因为后面有很多经典书的翻译都较差,只能看英文版,不如从这个入手。还有,这本书适合于快速看完,因为据评论,看完一些经典的带有数学推导的书后会发现这本书什么都没讲,只是举了很多例子而已。 《Algorithms of the Intelligent Web》(《智能web算法》) PDF 459 作者Haralambos

Is performance of “less/greater than than” better than “less/greater than or equal to”

旧街凉风 提交于 2019-12-24 04:25:09
问题 Is it computationally more performant to compare less/greater than over less/greater than or equal to ? Intuitively one could think that less/greater than is marginally better. Can a compiler use some trick to make the comparisons seem the same? A compiler could eliminate e.g. less than or equal to with less than by incrementing the bound by one but if the bound is "alive" then this cannot be done. 回答1: On virtually every modern CPU, there are compare/jumpless and compare/jumplessequal

Combining two regular expressions A and B into C = (A and not B)

强颜欢笑 提交于 2019-12-24 04:24:09
问题 Let's say I have one regular expression A and another regular expression B as input. I want to create a new regular expression C which matches a line if and only if A matches the line and B does not match the line. I am able to manually create C for very simple cases of A and B : Let's say A is x and B is y , then C = ^[^y]*x[^y]*$ would be a valid solution. Obviously, the problem gets harder as A and B get more complex. Is there a generic algorithm for creating such a regular expression C

Understanding how these floating point numbers work?

老子叫甜甜 提交于 2019-12-24 02:14:17
问题 I'm having a little difficulty understanding how floating point numbers work. Specifically in the following representations below (correct my mistakes): Representing 0: this is represented by a full 0 bits in the exponent bits (8 in single precision and 11 in double precision). If I have all zeros in the exponent bits, will I still be able to represent zero even if my mantissa is not all zero? Wikipedia shows that zero is represented by (−1)signbit×2^{−126}× 0.significandbits Why is it 2^{

Generating Fixtures from a list of n

浪子不回头ぞ 提交于 2019-12-23 21:55:25
问题 Suppose I have N teams and what to generate a fixture list, where every team plays every other team, what is the best practice for this. Is there a known algorithm that does this nicely? Efficiency isn't really a necessity as this only needs to be generated once a season. To be more specific, I'll start with some definitions: I have N teams... T_1, T_2, ... , T_n. If N is odd, include a 'ghost' team to make the amount of teams even. A set of fixtures for a week is a set of N/2 pairs, with no

What is the best way to sort 30gb of strings with a computer with 4gb of RAM using Ruby as scripting language?

点点圈 提交于 2019-12-23 09:07:42
问题 Hi I saw that as an interview question and thought it was an interesting question that I am not sure about the answer. What would be the best way ? 回答1: Assuming *nix: system("sort <input_file >output_file") "sort" can use temporary files to work with input files larger than memory. It has switches to tune the amount of main memory and the number of temporary files it will use, if needed. If not *nix, or the interviewer frowns because of the sideways answer, then I'll code an external merge