Hot answers tagged

11

But is that exactly where they are located in the lambda cube? The lambda cube is not a giant spectrum on which all programming languages can be classified. It is precisely eight languages, which combine a lambda calculus (values abstracted over values) with all possible combinations of three features: Values abstracted over types (parametric polymorphism) ...


9

Bjarne Stroustrup writes in his The Design and Evolution of C++ book (item 3.5.1): At this point, the object model becomes real in the sense that an object is more than the simple aggregation of the data members of a class. An object of a C++ class with a virtual function is a fundamentally different beast from a simple C struct. Then why did I not ...


4

I think this is due to the differences in the philosophy underlying the design of both programming languages. The C++ philosophy allows data structures to cause undefined behavior as soon as the user violates an invariant, while Java wants to avoid that in all cases. Java aims to raise exceptions when invariants are broken, or, when that can not be detected, ...


3

If you want to prove that the halting problem for C++ programs can't be decided by a C++ program, just copy the proof of the Halting problem but replace every use of a universal Turing machine with a C++ interpreter/compiler that's written in C++.


3

Let $0 < \varepsilon \lll 1$ be the relative error bound of the floating-point system—$2^{-53}$ in IEEE 754 binary64 arithmetic. First, the naive formula log1p(exp(x)) always gives a good approximation unless exp(x) overflows: If exp(x) computes $(1 + \delta_1) e^x$, and if log1p(y) computes $(1 + \delta_2) \log(1 + y)$, where $|\delta_1|, |\delta_2| \...


3

Your first answer is good (assuming the scope to assign is in order as declarations go). Each declaration is in the scope, where it is declared. In inner scope (say B2) variable $b$ is declared shadowing previous declaration. Now you cannot use outer scope variable (read, write) as is by name without scope resolution operator. Your second table suggests ...


3

The reason why std::deque is implemented as a sequence of non-contiguous blocks is to guarantee different complexity bounds (and different concrete performance) for operations with regards to std::vector. You already partially said it: changing the capacity of an std::vector requires reallocating the memory and copying the entire content to the new memory. ...


2

Observation: Type 2 query can only make the longest substring of 1 longer. Let's call a substring of 1's a component. For example, there are 3 components in this string 1 1 1 0 0 1 0 1 1 1 1 0 When a 0 is changed to 1, only the components to its immediate left and right will be affected. The length of the other components remains the same. string: 1 1 1 ...


2

I can't wrap my head around how the compiler accomplishes this. The compiler processes the source files in multiple passes. In the first pass, it gathers information about types and their members, effectively producing the information that would be contained in a header file in C++. In the second pass, it looks at method bodies and uses information from ...


2

The Java compiler reads the files you listed with the import statements to see the definitions. For historical reasons C compiler doesn't do this and prefers to get everything in one file, hence the preprocessor. In the end, there is no magic. If you want to make sure at compiletime that the functions that you're calling exist, then the compiler has to see ...


2

Contrary to what you think, extracing bytes by shifting and masking is completely unrelated to the storage order (both little-endian and big-endian storage schemes exist and don't influence the results). An int variable is represented by 32 bits. The least significant byte is made of the eight least significant bits and you obtain them by i & 0xFF 0b ...


2

Popcount is going to be your best option here. As j_random_hacker mentions in a comment, popcount on a single word can be done in $O(\log W)$ time if implemented by hand, or $O(1)$ if the machine provides a dedicated opcode for it (which should take a constant number of clock cycles—but then again, $W$ should also be a constant for any given machine). (Note:...


1

You can turn that search into a DFA,and you can then pass the input through the DFA until an accepting state is reached (or the end of the string is encountered). Each pattern is turned into an NFA by adding a start state which self-loops on any input and transitions to the next state on a match of the first character. Each subsequent state transitions ...


1

A basic approach would be as follows. Given input $a_1,a_2,\ldots$ we build an array of pairs $A=(1,a_1),(2,a_2),\ldots$. Now, in $O(n\log n)$ time, we can sort it according to the second component of each pair. When $A$ is sorted in such way, it's easy to compute the score and modify $A$ so that it becomes of the form $A=(i,{\sf score}_i),(j,{\sf score}...


1

Create a binary tree containing the points, either each node also containing the number of elements in each sub tree . For each candidate, determine the number of candidates arriving earlier, and having same or higher score using the tree, then add the candidates score to the tree. Should work in O(n log n). I doubt O(n) is possible. PS chi’s answer is a ...


1

ReLU is used in all layers except at the very end. Normally softmax is used at the final output, to normalize the outputs to be in the range [0,1] and to ensure the outputs sum to 1.


1

I will move my comment to an answer, since you seemed to indicate that the comment solved your problem. Your problem is normally called the Longest Common Subsequence problem. It does not require the common subsequence to be contiguous. It can be solved efficiently with dynamic programming, and it is an early example of dynamic programming in many textbooks....


Only top voted, non community-wiki answers of a minimum length are eligible