Interesting challenge, but way beyond my mathematical skills. So, here is a brute force implementation in plain C :P I don't have a mathematical proof and so cannot prove this will always find a solution, but it works for your input. Adding the 'fruit' "clinton" and 'vegetable' "mccaine" make it...

The question is indeed very broad, or, focussing on the "best practices" part, possibly opinion based - but not primarily opinion based, since there is a valid argument for a pattern like this. Often you have a method that obtains data somewhere, and is supposed to put it into a...

Imagine you have a program and you know basically nothing about how it works. It's supposed to have a bunch of properties (say, X, Y, and Z), but you're not really sure whether it does. What can you do to figure this out? One option would be to try to...

All compression methods are like that: the output is a set of parameters for a set algorithms that renders the input, or something similar to the input. For example MP3 audio codec breaks the input into blocks of 576 samples and converts each block into frequency-amplitude space, and prunes what...

There is no problem generating multiple keys and authentication hashes from the same password. You shouldn't be sending the real password to the server in any case. You want to send it through PBKDF2 first. My usual recommendation for authentication looks like this: salt = static-per-app-token + username key =...

They do not do exactly the same thing. In test, the result of doMore is ephemeral; once it is printed, it is gone. But in test2, that value is part of the object, and stays part of it. So if you don't need the value after it is printed, go...

Garbage collection can be a problem because garbage collectors take some time to run, and this happens at unpredictable moments. A bad thing in real-time software. Automatic memory allocation by itself isn't strictly a problem, but: In Go and similar languages it is closely tied to garbage collection. Many...

save yourself loads of trouble, use a vector std::vector<double> data; data.reserve(SIZE_OF_ARRAY); // not totally required, but will speed up filling the values vector will give you better debug messages and you won't have to deal with memory yourself....

In my opinion the versionKey you mention cannot be considered a vector clock. You could consider it a Lamport timestamp (or Lamport Clock) though. Let's have a global look at what we are managing: Both Lamport timestamps and vector clocks are algorithms used to define a causality order on different...

I finished a postgraduate degree in AI without the need of Compiler Theory. From an academic perspective, I believe that the subjects that helped prepare me for AI were, as you stated, Statistical Methods, Mathematics and Programming (I believe Object-Oriented and Data Structures helped most for this area). In addition...

Sounds a bit slow with the whole graph rewriting. You'd have to check if Boost counts a single-connected vertex as an articulation point. (If not, this slightly complicates things). Now it is fairly obvious that a bridge must be an edge between two articulation points, but not all edges between...

It sounds to me like you should be thinking in terms of sets for teams and matches: teams are sets of players (with 1 to 2 players based on your description) a match is a set of teams where each team fights the others in the set. Since matches are...

Just pick a thread pool of hardware_concurrency threads and queue the items on a first come, first served basis. If other processes in the system somehow get priority from the OS, so be it. This simply means that fewer than the allocated pool size (e.g. P - 1) can run...

There are different logic's to handle these things.It depends on what application you are using. Are you doing real time video streaming? stringent requirements? As you said you have a buffer, you can actually maintain a buffer for the packets and then send an acknowledgement for the lost packets (if...

Specifically addressing your (general) questions Is it true that threads are not necessary faster than using no thread? If yes what is the explanation for this? The efficiency of using multiple threads to accomplish a task is limited, primarily, by the number of CPU cores (including hyper-threading where available). For...

To be honest, I haven't done too much with dynamic trees myself (mostly static). But I believe the Bkd-tree paper (early 2000s?) is good source to start. I believe it has been referenced many times since then. You can use sources like acm/citeseer to track newer papers that reference it....

Convergence and idempotence are not Chef-specific. They're generally attributed to configuration management theory, though have use in other fields, notably mathematics. Let's start with the more basic, idempotent. We're going to ignore the mathematic use of idempotent, and focus instead on what configuration management people mean when they talk about...

You can do this after: $qualityDefinitions["dominant 7"] = & $qualityDefinitions["mixolydian"]; This makes the "dominant 7" key reference (or be a synonym of) the "mixolydian" key. If you want to easily have several of these made you can do so like this: $synonyms = array( "mixolydian" => array("dominant 7", "dom7", "7"),...

"First-in, last-out" is not always as descriptive for a new programmer as it might be for someone who has more programming experience. The concept of a stack - not, here, specifically referring to the C++ (or other-language) object - is a concept that permeates programming, at-large (a concept which is...

The time complexity of an algorithm is heavily tied to the specific way in which it's implemented. For example, Dijkstra's algorithm will run in time O(m + n log n) if you use a Fibonacci heap, takes time O(m log n) if you use a binary heap, and takes time...

I would actually use a flag on each email record in the database: Your worker (or multiples) update the oldest record with their unique worker ID (e.g. a PID or IP/PID combination). Example for Oracle SQL: update email set workerid = 'my-unqiue-worker-id' where emailid in ( select emailid from email...

Writing code using 2nd way is fast. But the problem is you have to cast the general Activity to the more specific SplashActivity in which the value variable exists. If you want to use the Fragment with another Activity, or you want a Fragment to be a general purpose UI...

I'm not sure if this is the best way to go about it, but I ended up creating a model that consisted of lists of each of the tables I needed to draw data from. So public class MasterModel { public List Names { get; set; } public List Emails...

Following the links you already provided, this is the part which seems to me, answers your question pretty closely.. Source The CLR and tail calls When you're dealing with languages managed by the CLR, there are two kinds of compilers in play. There's the compiler that goes from your language's...

In C#, the built-in integers are represented by a sequence of bit values of a predefined length. For the basic int datatype that length is 32 bits. Since 32 bits can only represent 4,294,967,296 different possible values (since that is 2^32), Since int can hold both positive and negative numbers,...

Your assumption is correct. Array created via new Y[3] can hold only objects of type Y or its subclasses. It can't store instances of superclasses like X because there is risk that X will not have all methods available in Y, so even if vetx [0] = new X(); compiles...

"validate this understanding" is gross corporate-speak. What the question is asking is "what do each of these users care about?" You're on the right track with separating out the concerns of each party. I would answer the question by explaining how the current security infrastructure does or does not address...

As per the MongoDB documentation, there is generally no need to routinely rebuild indexes. NOTE: Any advice on storage becomes more interesting with MongoDB 3.0+, which introduced a pluggable storage engine API. My comments below are specifically in reference to the default MMAP storage engine in MongoDB 3.0 and earlier....

No, this won't be safe, because right now nothing stops a user from writing: Car car = new Corvette(); car.myBodyType = new TwoWheels(); And now downcasting myBodyType in car to be of type FourWheels can lead to problematic behavior. The only way that you can rely on myBodyType never being...

I do it all the time. I copy and past those lines routinely. the only drawback is if you need an additional query while looping through the results of the first, in which case, things will get ugly. In those cases, you will need a unique name for the second...

I believe it always tries to find the middle by (0+n)/2 = (0+9)/2 = 4(Integer) In your case. So in case you want to search 25 itself, as per the algorithm you will find in the lower bound group, position 4 first as a match....

Basically, a self-executing anonymous function (more technically referred to as an IIFE or immediately invoked function expression) is the same as declaring a named function and then immediately calling it. The only difference with an IIFE is that is has no name so it can only be executed in place...

I wouldn't call this an issue, because it works as expected :-) For the reason, I can only guess (maybe there are some comments in the compiler). It is most likely that they needed to cast all of these expressions to boolean values - they want it to work like...

Here's a hint: if you consider any power of two greater than k (say, 2k), then 2k + k is not a power of two, since 2k + k < 2k + 2k = 2k+1 See if that can guide you to choose the right string and find your choice...

Is it possible that you did not set the replication factor on your keyspace with a value greater than 1? For example: CREATE KEYSPACE "Excalibur" WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'dc1' : 2, 'dc2' : 2}; Will configure your keyspace such that data is replicated to 2 nodes in...

To make it short: Introsort and Timsort are the most commonly used sorting algorithms in real world. They have both an O(nlogn) complexity in average and on worst cases which makes them better than QuickSort in the particular cases where Quicksort is in O(n^2). Introsort is used in C and...

Short answer: Think about the top of the mountains, each of them is a maximal solution, there is not place nearby that is higher than them, but only the top of the Everest mountain has the maximum height and is therefore the maximum solution. Longer answer: Let me explain it...

This started out as a comment but ended up being too big. Just to make sure you're familiar with the terminology... Differentiation takes a function f(t) and spits out a new function f'(t) that tells you how f(t) changes with time (i.e. f'(t) gives the slope of f(t) at time...

This is an NP-hard optimization problem. For example, the Partition problem can be reduced into this easily (the planarity property does not cause a problem). So an algorithm that calculates an optimal solution (and you seem to ask for an optimal solution in your comment) is unlikely to be practical...

I get the impression from papers like http://research.microsoft.com/pubs/144985/todsfinal.pdf that there is no algorithm that does better than O(VE) or O(V^3) in the general case. For sparse graphs and other special graphs there are faster algorithms. It seems, however, that you can still make improvements by separating "index construction" from "query",...

Repeat is definitely going to work, although I would probably use iterate or maybe recurrent; if it could be confused with a loop. Ad hoc is not a good choice in my opinion. I would go for onetime or simply put a non- in front of the other word (non-iterating,...

The choice of sequential vs parallel is simply one of execution strategy. The option for parallelism exists so that, if the specifics of the problem (problem size, choice of stream operations, computational work per element, available processors, memory bandwidth, etc) permit, then a performance benefit may be gained by going...

You currently test the pitch (i.e. the index in the scale) to see if you need to change octave. But a single scale can contain more than one octave index, and that depends on the index of the note itself relative to C. I'm not using the terminology of that...

By performance you mean processor-performance? The difference between the two cases will not be within measurement error, considering various Javascript engine JIT techniques, processor branch prediction, etc. Option B naively has more branches, but this does not necessarily impact performance. Design your code for human readability, and don't worry about...

Your logic from the comment is fairly sound. Quality hash functions will not generate a duplicate/previously generated output until the input length is nearly (or has exceeded) the hash digest length. But, the key factor in collision risk is the size of the input set to the size of the...

In my opinion you should open a connection at the moment you need it, and close it right after it. This will prevent a lot of connections on the server to be kept alive. In my experience, opening a connection doesn't take that much time (a few milliseconds, usually a...

Definitions in one sentence: A specification is an explicit set of rules that define how to implement a use case. A framework facilitates and structures the actual implementation of a use case. Cake analogy: If a cake recipe is a specification, a cake mix is a framework. Examples: Spring is...

An easy way to check is just to print it using for example Ideone. Check this link to see a demonstration. That said, the expression evaluates to a boolean. Since < and > have higher precedence than &&, the expression is equivalent to (n > k) && (k < 0),...

It doesn't look that different from standard regex... the only change you would have to make is to swap + with | (change (0+1) to (0|1)). Apart from that, you would just have to make the resulting regex match the entire line, either by prepending ^ and suffixing $ or...