algorithm

How to find Strongly Connected Components in a Graph?

心不动则不痛 提交于 2021-02-05 20:11:00
问题 I am trying self-study Graph Theory, and now trying to understand how to find SCC in a graph. I have read several different questions/answers on SO (e.g., 1,2,3,4,5,6,7,8), but I cant find one with a complete step-by-step example I could follow. According to CORMEN (Introduction to Algorithms), one method is: Call DFS(G) to compute finishing times f[u] for each vertex u Compute Transpose(G) Call DFS(Transpose(G)), but in the main loop of DFS, consider the vertices in order of decreasing f[u]

Perceptual similarity between two audio sequences

不羁岁月 提交于 2021-02-05 20:04:49
问题 I would like to get some sort of distance measure between two pieces of audio. For example, I want to compare the sound of an animal to the sound of a human mimicking that animal, and then return a score of how similar the sounds were. It seems like a difficult problem. What would be the best way to approach it? I was thinking to extract a couple of features from the audio signals and then do a Euclidian distance or cosine similarity (or something like that) on those features. What kind of

Graphs: find a sink in less than O(|V|) - or show it can't be done

耗尽温柔 提交于 2021-02-05 18:57:44
问题 I have a graph with n nodes as an adjacency matrix . Is it possible to detect a sink in less than O(n) time? If yes, how? If no, how do we prove it? Sink vertex is a vertex that has incoming edges from other nodes and no outgoing edges. 回答1: Suppose to the contrary that there exists an algorithm that queries fewer than (n-2)/2 edges, and let the adversary answer these queries arbitrarily. By the Pigeonhole Principle, there exist (at least) two nodes v, w that are not an endpoint of any edge

Graphs: find a sink in less than O(|V|) - or show it can't be done

限于喜欢 提交于 2021-02-05 18:56:42
问题 I have a graph with n nodes as an adjacency matrix . Is it possible to detect a sink in less than O(n) time? If yes, how? If no, how do we prove it? Sink vertex is a vertex that has incoming edges from other nodes and no outgoing edges. 回答1: Suppose to the contrary that there exists an algorithm that queries fewer than (n-2)/2 edges, and let the adversary answer these queries arbitrarily. By the Pigeonhole Principle, there exist (at least) two nodes v, w that are not an endpoint of any edge

Minimum number of rectangles in shape made from rectangles?

浪尽此生 提交于 2021-02-05 18:54:51
问题 I'm not sure if there's an algorithm that can solve this. A given number of rectangles are placed side by side horizontally from left to right to form a shape. You are given the width and height of each. How would you determine the minimum number of rectangles needed to cover the whole shape? i.e How would you redraw this shape using as few rectangles as possible? I've can only think about trying to squeeze as many big rectangles as i can but that seems inefficient. Any ideas? Edit: You are

Minimum number of rectangles in shape made from rectangles?

穿精又带淫゛_ 提交于 2021-02-05 18:54:46
问题 I'm not sure if there's an algorithm that can solve this. A given number of rectangles are placed side by side horizontally from left to right to form a shape. You are given the width and height of each. How would you determine the minimum number of rectangles needed to cover the whole shape? i.e How would you redraw this shape using as few rectangles as possible? I've can only think about trying to squeeze as many big rectangles as i can but that seems inefficient. Any ideas? Edit: You are

Finding the shortest path in a graph without any negative prefixes

时光毁灭记忆、已成空白 提交于 2021-02-05 13:52:21
问题 Find the shortest path from source to destination in a directed graph with positive and negative edges, such that at no point in the path the sum of edges coming before it is negative. If no such path exists report that too. I tried to use modified Bellman Ford, but could not find the correct solution. I would like to clarify a few points : yes there can be negative weight cycles. n is the number of edges. Assume that a O(n) length path exists if the problem has a solution. +1/-1 edge weights

Justify string algorithm [closed]

跟風遠走 提交于 2021-02-05 13:42:02
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Just tanked a job interview where I was asked to implement a function with this signature: function justify($str_in, $desired_length)

Justify string algorithm [closed]

自古美人都是妖i 提交于 2021-02-05 13:39:01
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Just tanked a job interview where I was asked to implement a function with this signature: function justify($str_in, $desired_length)

Google Interview: Find all contiguous subsequence in a given array of integers, whose sum falls in the given range. Can we do better than O(n^2)?

馋奶兔 提交于 2021-02-05 12:42:31
问题 Given an array of Integers, and a range (low, high), find all contiguous subsequence in the array which have sum in the range. Is there a solution better than O(n^2)? I tried a lot but couldn't find a solution that does better than O(n^2). Please help me find a better solution or confirm that this is the best we can do. This is what I have right now, I'm assuming the range to be defined as [lo, hi] . public static int numOfCombinations(final int[] data, final int lo, final int hi, int beg,