2022 Developer Survey is open! Take survey.

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
0 votes
0 answers
28 views

Algorithm to remove null transitions from an NFA?

I have an NFA represented as a vector<set<transition> > in C++. (Indices correspond to states, each index keeping a set of all transitions from the ...
user avatar
  • 1
0 votes
0 answers
21 views

Best way to sort two arrays in correspondence in a manner that coordination between them does not change

Let me put it this way. I have two arrays A and B. Array A contains manufacturing dates of cars, and Array B contains corresponding car model names. A and B are in correspondence. Now I want to sort ...
user avatar
1 vote
1 answer
69 views

Looking for a proof on why my algorithm in codeforces works

I'm trying prove the correctness of my algorithm. This is the problem in codeforces: https://codeforces.com/contest/1428/problem/C Here's my code in C++ which was accepted: ...
user avatar
1 vote
1 answer
64 views

Algorithmn for SIMD matrix multiplication

I've been trying to implement a program for matrix multiplication of multiple of 4 (ex: 4x4, 8x8, 16x16, etc.) and while I my program works for 4x4 matrix, it only fills the first 4 row of every ...
user avatar
1 vote
1 answer
35 views

How are pointers interpreted differently to variables in a control flow graph (CFG)?

I have been working with control flow graphs and believe I understand how they function when describing dependencies between variables. For example, given the operations: ...
user avatar
1 vote
0 answers
57 views

Completely clueless on computer science assignments [closed]

This question isn't very technical, but I'm in desperate need of help and I thought this would be the best place to post this question. I'm in an computer science course, data structures and ...
user avatar
1 vote
0 answers
55 views

finding max element in a min-max heap structure

I am trying to implement min-max heap structure A min-max heap is a data structure that is identical to a binary heap, but the heap-order property is that for any node, X, at even depth, the element ...
user avatar
0 votes
0 answers
19 views

Which GOP's (M and N) values can be used in the video encoded with any MPEG?

I faced the problem with defining either GOP is right or not after parsing the MXF container. I checked the actual GOP value using FFProbe and MediaInfo and these values differ (E.g. M3N15) from which ...
user avatar
2 votes
3 answers
59 views

Why doesn't the compiler typecast the pointer and remove the error? (C++ Programming)

int *numPtr; double num; numPtr = &num; This code shows an error as pointer points to data of different datatype. But why does it show the error? Why doesn't ...
user avatar
  • 21
0 votes
0 answers
37 views

Solving course scheduling with prerequisite problem

How should one go about this kind of problems? I'm supposed to use a graph structure for this. Say I have a file containing a couple of courses with their prerequisites. I have to organize the ...
user avatar
0 votes
0 answers
68 views

Bin packing problem using bit masking

We have n box and an array of weights, where weight of ith box is given by arr[i]. We have a container which can carry a maximum weight of w. Now we have to find minimum number of containers required ...
user avatar
  • 31
1 vote
0 answers
798 views

Minimum no of swaps to be done in an array such that, no two adjacent elements are same

Given an array of size n, find minimum number of swaps required, so that no two adjacent elements are equal. For ex- n = 6, a[] = {1, 1, 5, 2, 5, 5}, answer = 1, ( swap a[0] with a[4] or a[5] ) n = 8,...
user avatar
  • 31
6 votes
1 answer
914 views

How are extremely large integers stored and implemented in programming languages?

We have data types like int and long etc. which can store just a few bytes of integers. But when we are implementing ...
user avatar
3 votes
0 answers
27 views

Subtype Check with Type DAG

Trying to understand how compiler/static-type-checker checks for subtyping, I run into 2 problems. 1. Reachability in DAG Since both Python/C++ support multiple inheriatnce, the types can be ...
user avatar
  • 131
1 vote
1 answer
115 views

Find non common numbers in two arrays

Given two arrays of integers, please write a function that returns all elements present in one of the two arrays but not both. E.g. f([ 1, 3, 5 ], [ 1, 2, 4, 5 ]) -> [ 2, 3, 4 ] I know I can do ...
user avatar
  • 11
1 vote
2 answers
155 views

Fast computing of a matrix power for large integer values in C++

I'm working with squared matrices that can be quite large, for instance, a M = 50 x 50 matrix. My objective is to compute the power of the squared matrix ...
user avatar
3 votes
0 answers
73 views

How to detect when to use radix sort in runtime

I'm implementing a stable integer sorting algorithm, I've chosen radix sort. I've tested LSD vs MSD implementation, wrote MSD/LSD hybrid implementation to reduce bandwidth pressure. The repo is here: ...
user avatar
1 vote
1 answer
67 views

virtual machine based programming languages vs low level

I took programming lecture it was about C/java and how to build compilers, so I wanted to know. As far I see, languages like Java/C# are developing their virtual machine CLR/JVM with good base and are ...
user avatar
  • 199
0 votes
1 answer
273 views

In C++ how does "sizeof(array)/sizeof(array[0])" give the number of elements in an array? Why isn't it affected by the length of each element?

I'm playing around with C++ and was looking at how to loop through an array of unknown length. The following code was suggested and works perfectly from the little testing I've done: ...
user avatar
1 vote
2 answers
584 views

Which goes first stl or data structures and algorithms?

So I'm a newbie to c++. I know the basic concepts of c++ as I have already learnt c language. For competitive programming DSA is very important. But I don't know any STL functions. Is it possible to ...
user avatar
0 votes
1 answer
61 views

Combinations (repetition not allowed & order not important)

How to compute a table of numbers (all possibilities), where repetition is not allowed and order is not important. Example: I have a set of prime numbers. In this example I have four: {3,5,7,11}, but ...
user avatar
3 votes
1 answer
64 views

Why is the address-of operator in C/C++ represented with the "&" symbol?

I've started learning C++, and I know a little bit of C. Something that always struck me as somewhat off was that the address-of operator is represented with the seemingly random ampersand (&) ...
user avatar
  • 31
1 vote
1 answer
57 views

Is the Jacobian matrix calculation process correctly on this energy function?

When I implemented the paper Dynamic Fusion published in 2015 CVPR, I came into the trouble with how to solve the energy function: $$E(W_t, V, D_t, \mathcal{E}) = \text{Data}(W_t, V, D_t) + λ\text{Reg}...
user avatar
1 vote
2 answers
44 views

Practice of setting parallelism as the default behaviour

This is a soft, and probably also an opinion based question. Suppose I am writing a library in C++ for the purposes of working with financial data. My goals are: Since I work with big data, I want to ...
user avatar
1 vote
1 answer
54 views

Reason behind declaring iteration variables on a method level

Lately, I have been in touch with some C++ snippets, and I have a very strange observation on the tiny detail: Most of the times, I see, that people declare iteration variables outside of the for/...
user avatar
1 vote
1 answer
56 views

How to remove an ordering requirement from a board game simulation?

The Problem: I'm trying to simulate part of the game tantrix which is a board game played with hexagonal tiles. Each tile has 3 lines of different colors that each start at one side of the hexagon ...
user avatar
  • 123
-1 votes
1 answer
57 views

Time complexity of similar-looking functions

What is the time complexity of the following functions, and why? ...
user avatar
  • 15
1 vote
1 answer
153 views

What is the minimum number of parts required to split the sequence S to in order to obtain sequence T?

Suppose a person has a sequence (S) consisting of integer numbers and would like to split the sequence into a number (possibly one) of continuous parts. For each part independently, I then choose any ...
user avatar
0 votes
1 answer
51 views

The probability that a person succeeds to pick the longest stick from a randomly ordered n sticks of distinct lengths following the optimal strategy?

To begin with, consider two persons(Px and Py) are playing a game. Px is the organiser of the game who has n sticks of distinct lengths and displaying them one by one to Py in a random order, with ...
user avatar
2 votes
1 answer
42 views

printf("%d",~5); prints out -6 why is that?

I was reading the book "Computer systems: A programmer's perspective" and saw that the operator, "~", is a NOT operator. When I use it to NOT positive integers, it returns the ...
user avatar
1 vote
1 answer
201 views

Time complexity of the travelling salesman problem (Recursive formulation)

According to this recursion formula for dynamic programming (Held–Karp algorithm), the minimum cost can be found. I entered this code in C ++ and this was achieved (...
user avatar
  • 21
0 votes
1 answer
83 views

Calculate the sum of all sub-arrays with given indices

I am new to Algorithms and Competitive Coding. I have a problem as follow: For this problem, the time limit is 1 second so brute force is not a good way to solve. The only way I think must be Dynamic ...
user avatar
  • 111
1 vote
0 answers
308 views

Unordered data structure with fast insertion, deletion, and iteration

So, I need a data structure that would support the following operations: Add an element to the structure and get some "handle" for that element Retrieve an element by a handle Remove an ...
user avatar
  • 121
0 votes
0 answers
29 views

What is meant by the statement "Data is inactive but information is active"?

I came across the statement "data is inactive but information is active" while reading differences between data and information. What is meant by this statement?
user avatar
1 vote
1 answer
159 views

Is C++ considered a language with high or low orthogonality?

I'm looking to make a comparison of regularity in languages - specifically orthogonality. If I were to say Java is weak in terms of orthogonality and Haskell stronger, where would C++ sit and why?
user avatar
  • 113
-1 votes
1 answer
49 views

doubts on cin and scanf [closed]

i spent literally 5hrs trying to figure out, why the value of n is 1 for my second test case ( which begins at line 12 ) , but i am unable to, could you help me with that? ...
user avatar
0 votes
2 answers
214 views

Intuition behind the Reversal Algorithm [ Rotation of Array ]

I know that the below program uses Reversal algorithm to rotate an array's elements to k positions to the right. But how does the Reversal algorithm works? It seems kinda magic to see. Can somebody ...
user avatar
  • 1
0 votes
1 answer
187 views

How to Sort 2D array with out 1D array

Hello I am a new Computer Science student Ok, so I am trying to sort the 2D array I know you can actually sort a 2D array by copying it into a 1D array sort it using any Algorithm, and then place ...
user avatar
1 vote
1 answer
78 views

Cancellation in C++

I am trying to figure out what the problem with the following expression in C++ is: y=std::log(std::cosh(x)); My first intention was that there might occure a ...
user avatar
2 votes
1 answer
98 views

Math behind leetcode problem 47 permutations II

Please tell me why the expression i>0 && nums[i] == nums[i-1] && !used[i-1] works on getting unique permutations. And what is the math behind it? ...
user avatar
2 votes
4 answers
106 views

How do compilers assure stability?

Suppose you need a c compiler. It would be preferable to write that compiler in a c-like language, given the complexity of a compiler of that degree. At best, the c compiler would be written in c, but ...
user avatar
  • 123
0 votes
1 answer
1k views

What is the difference between python list and c++ vector?

I read about the similarities between the python list and c++ vector and it looks as if the only difference is python list is heterogeneous. Are there any other differences? How are they both ...
user avatar
0 votes
2 answers
473 views

Analyzing space complexity of passing data to function by reference

I have some difficulties with understanding the space complexity of the following algorithm. I've solved this problem subsets on leetcode. I understand why solutions' space complexity would be O(N * 2^...
user avatar
3 votes
1 answer
846 views

C++ STL: How does the distance() method work for a set/ multiset (stored internally as a self balancing tree)?

I'm working on the problem: Count smaller elements on right side using Set in C++ STL The solution is to add each element to the set and then to count the elements on the left, the distance function ...
user avatar
2 votes
2 answers
166 views

Efficient way to reduce a binomial coefficient as a fraction

Here is the full problem. You need to calculate Euler's totient function of a binomial coefficient $C_n^k$. Input The first line contains two integers: $n$ and $k$ $(0 \le k \le n \le 500000)$. ...
user avatar
0 votes
2 answers
93 views

Understanding memory leaks in C/C++ [closed]

I was looking at an example here: https://blog.parasoft.com/finding-memory-leaks-in-c ...
user avatar
  • 167
0 votes
0 answers
12 views

parallelized data structure

I'm searching a data structure that supports O(1) concurrent insertions (thread number is known in advance) and iteration over its elements (insertion order doesn't need to be preserved). While one ...
user avatar
0 votes
3 answers
194 views

Why do we need value-returning functions?

I'm just a beginner at C++ programming. I am currently having hard time grasping the usage of value returning function and non-value returning function. Void functions are called non-value returning ...
user avatar
0 votes
1 answer
52 views

How will I calculate the time and space complexity for this pyramid algo? [duplicate]

This is an algo. programmed for displaying a letter pyramid if the buildPyramids() method is passed argument str, i.e. "12345": ...
user avatar
0 votes
0 answers
27 views

How to Tokenize a String and Save Each Substring Separately (Independent Names for Each Substring)

I am given two files one with the name of person and the location that they are from (Evan Lloyd|Brownsville) and one with the name and salary (Evan Lloyd|58697) (the line number that you find the ...
user avatar