language-agnostic

Determine non-convex hull of collection of line segments

寵の児 提交于 2019-12-20 08:40:58
问题 I have a computational geometry problem that I feel should have a relatively simple solution, but I can't quite figure it out. I need to determine the non-convex outline of a region defined by several line segments. I'm aware of various non-convex hull algorithms (e.g. alpha shapes), but I don't need a fully general algorithm, as the line segments define a unique solution in most cases. As @Jean-FrançoisCorbett has pointed out, there are cases where there are multiple solutions. I clearly

How to write an algorithm to check if the sum of any two numbers in an array/list matches a given number?

二次信任 提交于 2019-12-20 08:39:48
问题 How can I write an algorithm to check if the sum of any two numbers in an array/list matches a given number with a complexity of nlogn ? 回答1: I'm sure there's a better way, but here's an idea: Sort array For every element e in the array, binary search for the complement (sum - e) Both these operations are O(n log n) . 回答2: This can be done in O(n) using a hash table. Initialize the table with all numbers in the array, with number as the key, and frequency as the value. Walk through each

Is there a good and easy way to visualize high dimensional data?

南笙酒味 提交于 2019-12-20 08:39:40
问题 Can someone please tell me if there is a good (easy) way to visualize high dimensional data? My data is currently 21 dimensions but I would like to see how whether it is dense or sparse. Are there techniques to achieve this? 回答1: Principal component analysis could be helpful if the dimensions are correlated. 回答2: Parallel coordinates are a popular method for visualizing high-dimensional data. What kind of visualization is best for your data in particular will depend on its characteristics--

Hash string into RGB color

╄→гoц情女王★ 提交于 2019-12-20 08:24:33
问题 Is there a best practice on how to hash an arbitrary string into a RGB color value? Or to be more general: to 3 bytes. You're asking: When will I ever need this? It doesn't matter to me, but imagine those tube graphs on any GitHub network page. There you can see something like this: Where every colored line means a distinct git branch. The low tech approach to color these branches would be a CLUT (color lookup table). The more sophisticated version would be: $branchColor = hashStringToColor

Choose the closest k points from given n points

匆匆过客 提交于 2019-12-20 08:23:05
问题 You are given a set U of n points on the plane and you can compute distance between any pair of points in constant time. Choose a subset of U called C such that C has exactly k points in it and the distance between the farthest 2 points in C is as small as possible for given k. 1 < k <= n What's the fastest way to do this besides the obvious n-choose-k solution? 回答1: A solution is shown in Finding k points with minimum diameter and related problems - Aggarwal, 1991. The algorithm described

Choose the closest k points from given n points

三世轮回 提交于 2019-12-20 08:23:04
问题 You are given a set U of n points on the plane and you can compute distance between any pair of points in constant time. Choose a subset of U called C such that C has exactly k points in it and the distance between the farthest 2 points in C is as small as possible for given k. 1 < k <= n What's the fastest way to do this besides the obvious n-choose-k solution? 回答1: A solution is shown in Finding k points with minimum diameter and related problems - Aggarwal, 1991. The algorithm described

Given a string of numbers and a number of multiplication operators, what is the highest number one can calculate?

戏子无情 提交于 2019-12-20 08:21:22
问题 This was an interview question I had and I was embarrassingly pretty stumped by it. Wanted to know if anyone could think up an answer to it and provide the big O notation for it. Question: Given a string of numbers and a number of multiplication operators, what is the highest number one can calculate? You must use all operators You cannot rearrange the string. You can only use the multiplication operators to calculate a number. E.g. String = "312" , 1 multiplication operator You can do 3*12 =

Position N circles of different radii inside a larger circle without overlapping

ぃ、小莉子 提交于 2019-12-20 08:18:11
问题 Given n circles with radii r1 ... rn, position them in such a way that no circles are overlapping and the bounding circle is of "small" radius. The program takes a list [r1, r2, ... rn] as input and outputs the centers of the circles. I ask for "small" because "minimum" radius converts it into a much more difficult problem (minimum version has already been proved to be NP hard/complete - see footnote near end of question). We don't need the minimum. If the shape made by the circles seems to

What are some good resources for learning threaded programming? [closed]

浪尽此生 提交于 2019-12-20 08:11:45
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . With the rise of multicore CPUs on the desktop, multithreading skills will become a valuable asset for programmers. Can you recommend some good resources (books, tutorials, websites, etc.) for a programmer who is looking to learn about threaded programming? 回答1: Take a look at Herb Sutter's "The Free Lunch Is

What are some good resources for learning threaded programming? [closed]

爱⌒轻易说出口 提交于 2019-12-20 08:10:21
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . With the rise of multicore CPUs on the desktop, multithreading skills will become a valuable asset for programmers. Can you recommend some good resources (books, tutorials, websites, etc.) for a programmer who is looking to learn about threaded programming? 回答1: Take a look at Herb Sutter's "The Free Lunch Is