Questions tagged [c++]

Programming questions are off-topic here. Do not ask questions about how to write code in C++. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.

Filter by
Sorted by
Tagged with
5
votes
1answer
608 views

Where are C++ templates inside of the lambda cube?

C++ templates have type variables and can express lambdas, so they must have System F embedded. But is that exactly where they are located in the lambda cube? Can C++ templates produce new types or ...
5
votes
4answers
127 views

How do you find a hash function that respects a custom equality function?

I've been tasked with hashing arbitrary types in C++, with the caveat that A == B implies hash(A) == hash(B) even if equality of ...
4
votes
1answer
134 views

Why are struct and class essentially the same in C++?

struct and class in C++ are nearly identical (as covered for example here). But why is this so? What did happen when C++ was ...
4
votes
1answer
104 views

Linked list: advantages of preventing movement of nodes and invalidating iterators on add/remove

C++ and Java include native classes for linked lists, C++ std::list and Java LinkedList For C++ std::list, nodes can be "moved" within a list, or from list to list (if the lists are compatible), via ...
3
votes
1answer
119 views

What type of function is main()?

As the functions are of 2 type:1.Pre-defined/library functions,2.User defined functions. What type of function is main() function? This doubt comes in my mind while writing a program we define the ...
2
votes
1answer
55 views

numerically stable log1pexp calculation

What are good approximations for computing log1pexp for single precision and double precision floating point numbers? Note: ...
2
votes
0answers
67 views

Implementing a linear programming feasibility test in 3D

I have a little problem which requires determining if a system of linear inequalities in 3D is infeasible. The constraints (or oriented planes) are added one by one, so there is an opportunity to stop ...
1
vote
2answers
104 views

How do compilers implement symbolic (rather than textual) insertion?

From a programming language designer's point of view, how is "symbolic" insertion implemented as opposed to "textual" insertion using pre-processor macros? I understand the basics of how "textual" ...
1
vote
1answer
131 views

Complete the following table by specifying the scope of each declaration

I'm having a hard time understanding this question. Can each declaration have more than one scope or can a declaration have more than one scope? If it's the later it would be: Declaration ...
1
vote
1answer
147 views

Why isn't deque implemented as a dynamic array?

We know that std::vector in C++ is implemented as a dynamic array with specific pattern of reallocation (multiplying capacity by a constant), which allows it to ...
1
vote
2answers
53 views

Compare each array $i$ member to all array $j$ member where $(i > j)$ , in time less than $O(n^2)$

I am new to algorithms so sorry to ask simple question I am working on a problem which is about array of integers, my solution is right but not good enough, because I have time exceeded exception on ...
1
vote
1answer
310 views

Find maximum non contiguous subarray that respect a specific rule [closed]

Given these two arrays: [5, 3, 4, 1, 2] [1, 3, 2, 4, 5] Find the maximum subsequence in both arrays that the index of the elements are in a crescent order: ...
1
vote
0answers
29 views

How to justify using available code (in different language) for comparing algorithms [closed]

I have proposed an algorithm for a scheduling problem in a submitting paper. In the revision, the reviewer asked us to compare with another algorithm in the literature. Our algorithm is in MATLAB, and ...
1
vote
0answers
36 views

How does C++'s type checking work when passing overloaded or templated functions as parameter

As I understand, C++ in general features 'one-way' type checking. That is checking the sub-expressions and get their types, and see if the types so far satisfy the constraints imposed by the current ...
1
vote
0answers
29 views

Summary of types of equivalence and equality in type theory, with notations and examples

Coming from non-computer science background, I am trying to understand the different types of equivalence and equality usually used in type theory. Ideally, I am looking for clear definitions and ...
1
vote
0answers
63 views

Generate an AST from an indefinite grammar and logic

As said in the title, I have to generate an AST from a grammar and logic (or a"syntax" if you prefer). This grammar and syntax are both indefinite in the program, meaning that it is the user (a ...
1
vote
0answers
1k views

To find median of k sorted arrays of n elements each in less than O(n*k*log(k))

How to find median of k sorted arrays each of length n? Note that total elements would be n*k. I know it can be done in O(n*k*log(k)) using merge technique. I am looking for a better time efficient ...
1
vote
1answer
79 views

Print maximum frequency number in an array(with slight modification)

There is an integer array and 2 variables Q and M.The output required is the number which has the maximum frequency in the array, but the catch is that each number in the array can be increased/...
0
votes
1answer
245 views

Bytes from integer using bitwise operators

So I am extremely confused with using bitwise shifts used to extract the bytes from an integer. I find that if I do something like this... ...
0
votes
1answer
119 views

How to count number of 1s of the first k positions in a bitset (bitmap)?

Input: Given a bitset $b$, which is is an array of 0s and 1s, of length $L$, and a positive integer $k$. Output: the total number of 1s in the first $k$ position of $b$. Obviously it can be done in $...
0
votes
1answer
419 views

Find Length of longest substring with all 1's in a binary string with k queries

Given a string of size n consisting of 0s and/or 1s.you have to perform k queries and there are two types of queries possible. "1"(without quotes): Print length of the longest substring with all '1'. ...
0
votes
1answer
17 views

Recursive Call Inside Argument List (C++) [closed]

So, my professor asked me to implement recursion in different ways to compute $a^n$ (a and n being integers) and rank them according to their space efficiency. Now, here is one of the methods I came ...
0
votes
0answers
71 views

Given n strings, how to output their order after k phases of the radix sort (huge constraints)?

Disclaimer This is not from an ongoing contest, this is from my course of ITMO on edx.org, which is a paid code so I cannot give you a direct link to the course. Problem You are given $\...
0
votes
1answer
46 views

What operation is the algorithm performing? [closed]

...
-1
votes
2answers
41 views

Find first occurence of multiple tokens using C++ [closed]

I am using C++03. I have a stream of chars and I need to find the first token from a group of tokens. That is, I need to find the lowest indexed match. Specifically, the stream is just an char array, ...
-1
votes
1answer
41 views

How is ReLU used in machine learning functions

I've seen how sigmoid would be used in machine learning sigmoid(dot(activations, weights)-bias) like this ^ but sigmoid makes sure your values are between 0 and ...
-1
votes
0answers
11 views

Design and implement a data structure that can be used to keep track of and manipulate “ranges” [closed]

A “range” is defined by a starting point (inclusive) and an ending point (exclusive), for example the range (1, 4) contains the values 1, 2, and 3. You may assume the ranges can only be defined with ...
-2
votes
1answer
67 views

Halting problem in C++

The halting problem relies on the fluidity of Turing machines. That is, a string can represent a machine. Can you do the same for C++ on a modern computer? Let's see my first attempt. Let ...