algorithm – Find all of the paths that lead to the minimum sum

“Find minimum path sum” in a 2D grid, is a very popular question which is solved by dynamic programming. But what if instead of the minimum sum value, we return all the actual paths that lead to the minimum sum path? This was an interview question which has been puzzling me.

The original problem is :

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.


Input: grid = 

output: 7
Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.

But instead of 7 I want to return (1,3,1,1,1) and all other paths that lead to sum of sum (in this case there is only one path). My current solution has exponential time complexity which is not good. Does anyone has a good solution to this problem?

algorithms – Finding the minimum value of all subsets in a 2D array

Imagine a N by M 2D array of random positive integers and two coordinates (i1,j1), (i2,j2), which represent the upper-left bound and bottom-right bound of a subarray, respectively. Is there a efficient algorithm to calculate all the minimum values of each subarray?

((4, 10, 9, 7),
 (9, 8,  1, 2),
 (1, 21, 3, 1))

In this example of a 3 by 4 grid, if the two coordinates were (0,1) and (2,2), the minimum in this case would be 1, out of the values 10,9,8,1,21,3.

Other than the naive solution of finding all subsets and calculating the minimum in this subarray, which would be well beyond O(n^4), I have also considered using a method similar to prefix sum by creating a separate 2D array and storing the minimum from (0,0) to (i,j) at the value (i,j), but this issue here is you can’t account for the overlap like you do in prefix sums.

Is there a way to account for overlap or another, more efficient algorithm?

Thank you!

co.combinatorics – A minimum string contain all the “n-combination”of n different elements(like the Haruhi Problem)

This string is not like the De Brujin sequence,010is equal to 100.
and there is a example. Just like the Haruhi Problem.
As a DoTa2 player, I like Carl very much. He is a great magician.Carl has three balls, which are Q ice, W thunder and E fire.If you press Q,there will be a ice ball around his head.But the number of the balls are always less than 3.Balls are saved in a queue.if you press QQWWWE,the last situation is WWE.Karl can use these balls to release tricks. For example, QQQ is a trick and QWE is another trick,which also equals to WEQ or EQW.Different combinations can produce different tricks, and there are 10 tricks in total.If you want to release the trick,you just need to press the R keyboard. When I first played Carl, I pressed wwqRwwwR. Later, I found that qwwRwR was better, which saved a lot of operation. So I thought, well, how many keystrokes does Carl have to press to finish all his skills in least steps?? Except for trick shortcut keys, press weqqqwwweeeq, and you can make up all tricks with 12 keys. If Carl has n balls, there are C (n-1, 2n-1) situations in the N-element combination. How many keystrokes need to press to remove the element fusion in the least steps?And how many possible permutations are there with at least keystrokes? I think this problem is simpler than the minimum super permutation problem, but it is still too hard for me.

summation – least squares minimum

it’s the age old least-squares problem:

Find the value of b for which the following sum has the minimum value (assuming that x and y are one-dimensional vectors of the same length):

$$ sum_{i=0}^n (y_i – bx_i)^2 = min $$

This must have been asked before but I can’t find it, would appreciate a redirect from somebody thanks

Is there any connection between the minimum vertex cover and the size of longest path in a graph?

If we know the size of the minimum vertex cover for a graph $G$ is $tau(G)$, can we define any connectivity between $tau(G)$ and its longest path?

calculus – For what x values does the integral have a minimum

I was given this problem:

And I’m really confused because I flipped the function to solve it (turned the integral negative and made lower value upper value…) and I got -2 as the answer, but when I checked it, it was wrong. I know it can’t be 0 either. So it’s -2? Or can there be multiple minimum points? Because -2 is a minimum when we don’t flip the function. But 2 is the minimum when we flip it. I’m really confused.

sorting – Finding the size of a subset of top $N$ elements, where the minimum element is at least $N$, in linear time

I am looking for a solution for the following problem:

Find the size of a subset of top $N$ elements, where the minimum element is at least $N$, in linear time.

Consider the following sequence:
3, 1, 6, 1, 5

The answer here is $3$, with $6, 5, 3$ being in the set found. The value of $N$ is not a given – we’re looking for the largest $N$.

So far, I came up with three solutions:

  1. Sort the sequence and go from the top.
  2. Use a modified version of quickselect.
  3. Use a modified version of BST where elements bigger than the current $n$ are inserted, and elements smaller than the new $N$ are removed.

1 and 3 are more or less $nlog n$ (though I’d expect 3 to be faster), 2 is best case $n$, worst case $n^2$.

Our teacher told us it’s possible to do it in a reliable $n$ time. What is the algorithm for the linear solution, if there’s one?

minimum spanning tree – Find MST on grid graph with only weight of 1 and 2 in $O(|V|+|E|)$

Given a grid graph $G=(V,E)$ which has only two different integer costs/weights of 1 and. Find Minimum Spanning Tree in $O(|V|+|E|)$.

I tried the following:

  • Changing Kruskal using a counting Sort in $O(|E|)$. But can I say that this results in O(|E|+|V|)? Since Kruskal would normally be ${displaystyle O(T_{sort}(|E|)+|E|cdot alpha (|V|))} =O(|E|)$ when $alpha (|V|) in O(1)$ Can this be stated for this case? I lack detailed understanding of inverse ackerman behaviour.
  • Other possibility changing Prim so that I use a priority queue which support del_min, decreaseKey and insert in $O(1)$. I thought about using two simple stacks or queues and only del_min from the one, which holds the 1 integers, but descreaseKey seems not efficient since I have to loop through the lists to find the elements. So maybe combine this with some kind so hash mapping to directly access each element in $O(1)$ for decreaseKey?

Both seem really close to the actual result, though I am struggling to see the right solution for this case.

ssl – Only require a minimum version of TLS (1.2) when a specific backend is used in HaProxy

I have a single frontend, but multiple backends. I’m upgrading security on some backends, and as a part of that, i want to only allow TLS1.2 or higher, when getting requests to those specific backends. There’s still customers using the other backends, so I don’t want to disrupt them, right now.

I have a config, similar to the one below. I’ve tried to set “ssl-min-ver” in the backend, I’ve also tried to add “no-ssl3 no-tls10 no-tls11” options to the backend, but that is apparently invalid.

So my question is, how do i make it so, that when backend “api-test” is used, a minium version of TLS of 1.2 is required, while the two other backends are unaffected?

Here is the config I’m referring to:

frontend frontend_ssl
    bind *:443 ssl crt /certificate.(somename).com.pem crt /etc/haproxy/certificates/

    acl is_api_(somename)_com hdr(host) -i api.(somename).com
    acl is_api_(somename)_test hdr(host) -i test-api.(somename).com

    use_backend api_prod if is_api_(somename)_com
    use_backend api_test if is_api_(somename)_test
    default_backend app_iis_http_4430

backend app_iis_http_4430
    server dk1h1iis check port 4430
    server dk1h2iis check port 4430

backend api_prod
    server dk1h1docker_prod check port 855
    server dk1h2docker_prod check port 855

backend api_test
    server dk1h1docker_test check port 856
    server dk1h2docker_test check port 856

Is the minimum bottleneck spanning tree also a minimum spanning tree for an undirected graph with unique edge weights?

Thanks for contributing an answer to Computer Science Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.

To learn more, see our tips on writing great answers.