theory

Graph Theory

假装没事ソ 提交于 2019-11-26 13:57:32
Shortest Path - Tree Description: ​ Directed edge \((u,v)\) in tree if \(u\) last relax \(v\) , the root is \(S\) or \(T\) . The classic problem : ​ forall edge \(i\) in the Graph , query the shortest path \((S, T)\) without edge \(i\) . Solution : ​ If edge \(i\) not in the shortest path, the answer is distance \((S, T)\) . ​ Otherwise , build the shortest path-tree (the root is S). we can prove the shortest path must have only one non-tree-edge, assume edge \(i= (u,v)\) , we can find an optimal non-tree-edge \((x, y)\) that the Graph have least one path \((S, x)\) and path \((y, T)\) without

How are hash functions like MD5 unique?

强颜欢笑 提交于 2019-11-26 12:38:25
问题 I\'m aware that MD5 has had some collisions but this is more of a high-level question about hashing functions. If MD5 hashes any arbitrary string into a 32-digit hex value, then according to the Pigeonhole Principle surely this can not be unique, as there are more unique arbitrary strings than there are unique 32-digit hex values. 回答1: You're correct that it cannot guarantee uniqueness, however there are approximately 3.402823669209387e+38 different values in a 32 digit hex value (16^32).

Are there any O(1/n) algorithms?

百般思念 提交于 2019-11-26 12:34:16
Are there any O(1/n) algorithms? Or anything else which is less than O(1)? Konrad Rudolph This question isn't as stupid as it might seem. At least theoretically, something such as O (1/ n ) is completely sensible when we take the mathematical definition of the Big O notation : Now you can easily substitute g ( x ) for 1/ x … it's obvious that the above definition still holds for some f . For the purpose of estimating asymptotic run-time growth, this is less viable … a meaningful algorithm cannot get faster as the input grows. Sure, you can construct an arbitrary algorithm to fulfill this, e.g.

Is finding the equivalence of two functions undecidable?

岁酱吖の 提交于 2019-11-26 12:25:51
问题 Is it impossible to know if two functions are equivalent? For example, a compiler writer wants to determine if two functions that the developer has written perform the same operation, what methods can he use to figure that one out? Or can what can we do to find out that two TMs are identical? Is there a way to normalize the machines? Edit: If the general case is undecidable, how much information do you need to have before you can correctly say that two functions are equivalent? 回答1: Given an

What is a scalar Object in C++?

这一生的挚爱 提交于 2019-11-26 12:04:06
问题 As far as I understand it fundamental types are Scalar and Arrays are aggregate but what about user defined types? By what criteria would I divide them into the two categories? struct S { int i; int j }; class C { public: S s1_; S s2_ }; std::vector<int> V; std::vector<int> *pV = &v; 回答1: Short version: Types in C++ are: Object types: scalars, arrays, classes, unions Reference types Function types (Member types) [see below] void Long version Object types Scalars arithmetic (integral, float)

Why do I need “OR NULL” in MySQL when counting rows with a condition

元气小坏坏 提交于 2019-11-26 11:35:49
问题 There is a question about MySQL\'s COUNT() aggregate function that keeps popping into my head time to time. I would like to get some explanation to why it is working the way it is. When I started working with MySQL I quickly learned that its COUNT(condition) seems only to work properly if condition also contains an OR NULL in the end. In case of more complicated COUNT conditions it was an empirical process to find out where to put it exactly. In MSSQL you do not need this OR NULL to get

Why are C++ inline functions in the header?

筅森魡賤 提交于 2019-11-26 11:31:05
NB This is not a question about how to use inline functions or how they work, more why they are done the way they are. The declaration of a class member function does not need to define a function as inline , it is only the actual implementation of the function. For example, in the header file: struct foo{ void bar(); // no need to define this as inline } So why does the inline implementation of a classes function have to be in the header file? Why can't I put the inline function the .cpp file? If I where to try to put the inline definition in the .cpp file I would get an error along the lines

What is a Y-combinator? [closed]

梦想与她 提交于 2019-11-26 11:27:16
A Y-combinator is a computer science concept from the “functional” side of things. Most programmers don't know much at all about combinators, if they've even heard about them. What is a Y-combinator? How do combinators work? What are they good for? Are they useful in procedural languages? Nicholas Mancuso If you're ready for a long read, Mike Vanier has a great explanation . Long story short, it allows you to implement recursion in a language that doesn't necessarily support it natively. Chris Ammerman A Y-combinator is a "functional" (a function that operates on other functions) that enables

What is a database transaction?

拈花ヽ惹草 提交于 2019-11-26 10:08:16
问题 Can someone provide a straightforward (but not simpler than possible) explanation of a transaction as applied to computing (even if copied from Wikipedia)? 回答1: A transaction is a unit of work that you want to treat as "a whole." It has to either happen in full or not at all. A classical example is transferring money from one bank account to another. To do that you have first to withdraw the amount from the source account, and then deposit it to the destination account. The operation has to

Calling base class overridden function from base class method

被刻印的时光 ゝ 提交于 2019-11-26 09:39:06
问题 public class A { public void f1(String str) { System.out.println(\"A.f1(String)\"); this.f1(1, str); } public void f1(int i, String str) { System.out.println(\"A.f1(int, String)\"); } } public class B extends A { @Override public void f1(String str) { System.out.println(\"B.f1(String)\"); super.f1(str); } @Override public void f1(int i, String str) { System.out.println(\"B.f1(int, String)\"); super.f1(i, str); } } public class Main { public static void main(String[] args) { B b = new B(); b