pseudocode

Find path between two nodes in graph, according to given criteria - optimization task

不羁岁月 提交于 2019-12-08 07:59:37
问题 I have the following problem. I have cyclic, undirected, weighted graph G=(V,E). I need to find the simple path (without cycles) between two given nodes according to these rules: Finding minimal weight value in edges set of each possible path Select this path, which has maximal min value among selected minimal values from found paths E.g we have graph presented below: We can try to find simple path from node 1 to node 8. There are two possible pathes, listed below: 1 -> 3 -> 5 -> 8, minimal

Custom vsync Algorithm

十年热恋 提交于 2019-12-08 03:49:44
问题 When creating a game with any programming language (that can), it is important to have a fixed target frame rate the game will redraw the screen at, however some languages either do not have a sync function or timers are unreliable so is there any method of keeping the frame rate steady manually with only math and/or by sleeping the thread? Maybe using a frame delta? So far I have only tried 'sleep(targetframerate - (targetframerate-delta))' This is supposed to realise that the previous frame

Parallel power set generation in Erlang?

痴心易碎 提交于 2019-12-08 02:15:44
问题 There is a lot of example implementations of generating a powerset of a set in Java, Python and others, but I still can not understand how the actual algorithm works. What are the steps taken by an algorithm to generate a power set P(S) of a set S? (For example, the power set of {1,2,3,4} is {{}, {1}, {2}, {1,2}, {3}, {1,3}, {2,3}, {1,2,3}, {4}, {1,4}, {2,4}, {1,2,4}, {3,4}, {1,3,4}, {2,3,4}, {1,2,3,4}}.) UPD: I have found this explanation, but still I don't get it. I am trying to understand

How can I improve the performance of my flood-fill routine?

社会主义新天地 提交于 2019-12-08 02:15:41
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 8 years ago . I'm implementing the four way flood fill in my application, pseudo code given below Flood-fill (node, target-color, replacement-color): 1. If the color of node is not equal to target-color, return. 2. Set the color of node to replacement-color. 3. Perform Flood-fill (one step to the west of node, target-color, replacement-color). Perform Flood-fill (one step

How to find the Longest Common Subsequence in Exponential time?

坚强是说给别人听的谎言 提交于 2019-12-07 10:52:27
问题 I can do this the proper way using dynamic programming but I can't figure out how to do it in exponential time. I'm looking to find the largest common sub-sequence between two strings. Note: I mean subsequences and not sub-strings the symbols that make up a sequence need not be consecutive. 回答1: Just replace the lookups in the table in your dynamic programming code with recursive calls. In other words, just implement the recursive formulation of the LCS problem: EDIT In pseudocode (almost

Using BFS or DFS to determine the connectivity in a non connected graph?

半腔热情 提交于 2019-12-07 03:42:03
问题 How can i design an algorithm using BFS or DFS algorithms in order to determine the connected components of a non connected graph , the algorithm must be able to denote the set of vertices of each connected component . This is my aproach: 1) Initialize all vertices as not visited. 2) Do a DFS traversal of graph starting from any arbitrary vertex v. If DFS traversal doesn’t visit all vertices, then return false. 3) Reverse all arcs (or find transpose or reverse of graph) 4) Mark all vertices

Difference among approximatelyEqual and essentiallyEqual in The art of computer programming

人走茶凉 提交于 2019-12-06 19:27:20
问题 I get this code snippet from some where else. According to the webmaster, the code is picked from The art of computer programming by Knuth Since I do not have a copy of that book, may I know what is the difference among the two functions? bool approximatelyEqual(float a, float b, float epsilon) { return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon); } bool essentiallyEqual(float a, float b, float epsilon) { return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a))

Algorithm for Filling bag maximally (this is not the knapsack 0/1)

拟墨画扇 提交于 2019-12-06 13:57:26
I am working on some task which requires from me to solve the following algorithmic problem: - You Have collection of items (their weights): [w1, w2, ..., wn] - And You have a bag which weight is: W - It is Needed to fill the bag maximally (fill as much as possible) with the subset of given items. So this is not "Knapsack 0/1" problem, as we deal only with weights (we have only one parameter for item). Therefore I assume that it might have a solution (Knapsack is NP-complete) or some kind of algorithm which gives approximately correct result. Please don't suggest me "greedy algorithms",

Parallel power set generation in Erlang?

。_饼干妹妹 提交于 2019-12-06 05:13:46
There is a lot of example implementations of generating a powerset of a set in Java, Python and others, but I still can not understand how the actual algorithm works. What are the steps taken by an algorithm to generate a power set P(S) of a set S? (For example, the power set of {1,2,3,4} is {{}, {1}, {2}, {1,2}, {3}, {1,3}, {2,3}, {1,2,3}, {4}, {1,4}, {2,4}, {1,2,4}, {3,4}, {1,3,4}, {2,3,4}, {1,2,3,4}}.) UPD: I have found this explanation, but still I don't get it. I am trying to understand the algorithm of generating a power set, because I would like to write a parallel implementation of it

How can i get the next highest multiple of 5 or 10

天大地大妈咪最大 提交于 2019-12-06 03:51:40
From a given double I want to get the next highest number according to some rules which, since I have some difficulty describing them, I will illustrate by examples: Input Desired output ------- -------------- 0.08 0.1 0.2 0.5 5 10 7 10 99 100 100 500 2345 5000 The output should be in some sense the 'next highest multiple of 5 or 10'. I hope this is understandable; if not, let me know. The implementation will be in java and input will be positive double s. function top5_10 (x) { var ten = Math.pow(10, Math.ceiling(Math.ln(x)/Math.LN10))); if (ten > 10 * x) { ten = ten / 10; } else if (ten <= x