instruction
stringlengths
0
29.8k
⌀
Suppose we have a 6 vertices graph. We also have 6 gates. Each gate is attributed a path. For example, Gate 'A' will have to go to 'B'- 'C' - 'D' and 'E' Gate 'B' will have to go to 'D' Gate 'C' will have to go to 'A' and 'B' Gate 'D' will have to go to 'E' - 'A' and 'B' Gate 'E' will have to go to '...
Suppose we have a 6 vertices graph. We also have 6 gates. Each gate is attributed a path. For example, Gate 'A' will have to go to 'B'- 'C' - 'D' and 'E' Gate 'B' will have to go to 'D' Gate 'C' will have to go to 'A' and 'B' Gate 'D' will have to go to 'E' - 'A' and 'B' Gate 'E' will have to go to '...
Suppose we have a 6 vertices graph. We also have 6 gates. Each gate is attributed a path. For example, Gate 'A' will have to go to 'B'- 'C' - 'D' and 'E' Gate 'B' will have to go to 'D' Gate 'C' will have to go to 'A' and 'B' Gate 'D' will have to go to 'E' - 'A' and 'B' Gate 'E' will have to go to '...
Find the placement of gates on 2D points that minimizes the total distance of all paths to be made
|algorithms|graphs|optimization|euclidean-distance|
null
Yes, most CPUs(*) have an [accumulator-based architecture](https://en.wikipedia.org/wiki/Accumulator_(computing)#Accumulator_machines). In fact, most CPUs have the very simplest kind of accumulator-based architecture, the kind used in the "Hack CPU", with an accumulator that can only be loaded from the ALU, and whose ...
The concept of reducibility in computability theory is very confusing for me. For example, as described in Micheal Sipser's Introduction to the theory of computation, I understand that if language A is reducible to B, then solving A cannot be harder than solving B, or in other words, solving B gives a solution to A. ...
If A is reducible to B, assuming A is hard, why can't "B is easy" update our belief to A is easy?
|complexity-theory|computability|computation-models|
null
A [linear-feedback shift register][1] (LFSR) is a terrible PRNG(*), but (with correct selection of feedback taps) it seems to meet all your qualifications. A LFSR can run extremely fast -- faster than standard natural binary counters. > Is there one that, before it cycles, will generate each possible > number i...
The concept of reducibility in computability theory is very confusing for me. For example, as described in Micheal Sipser's Introduction to the theory of computation, I understand that if language A is reducible to B, then solving A cannot be harder than solving B, or in other words, solving B gives a solution to A. ...
Based on [the reformulation of your problem from Bernardo Subercaseaux](https://cs.stackexchange.com/questions/153209/find-the-placement-of-gates-on-2d-points-that-minimizes-the-total-distance-of-al#comment322379_153209), your problem is NP-hard (as [John L explains](https://cs.stackexchange.com/questions/153209/find-t...
Discovering that $B$ is decidable may mean one of two things: 1. There is an error somewhere: either in the proof of decidability of $B$, or in the proof of undecidability of $A$, or in the reduction from $A$ to $B$. 2. The algorithm used to decide $B$ does not conform to the usual definition of “algorithm” (i.e....
Discovering that $B$ is decidable may mean one of two things: 1. There is an error somewhere: either in the proof of decidability of $B$, or in the proof of undecidability of $A$, or in the reduction from $A$ to $B$. 2. The algorithm used to decide $B$ does not conform to the usual notion of “algorithm” (i.e., it...
null
Discovering that $B$ is decidable may mean one of two things: 1. There is an error somewhere: either in the proof of decidability of $B$, or in the proof of undecidability of $A$, or in the reduction from $A$ to $B$ (or, in an extreme case, in [the very foundations of mathematics](https://math.stackexchange.com/q/2...
By using this algorithm the expected time complexity would not be `O(V+E)` as we have to visit an edge multiple times. `queue.add(s) while(the queue is not empty) for every adjacent vertex v of u if( dist[v] > dist[u] + weight(u,v) ) dist[v] = dist[u] + weight(u,v) add v to the queue ` But...
Pigeonhole principle: if there were more than $D(n) + 1$ roots, some roots would have the same degree and should have been merged.
null
The lowest time complexity of search algorithms for sorted lists is $$O(n)=logn$$. The lowest time complexity of sorting algorithms is $$O(n) = nlogn$$ So in order to be able to use a search algorithm for sorted lists we first must sort the list which takes min of $$nlogn$$ time complexity.Since the brute force ...
Existence of some search algorithms
|algorithms|time-complexity|sorting|search-algorithms|
Naturally, if you want to check _once_ whether an element is in an unsorted list, the O(n) brute force approach is the way to go, right as you say in the question. The effect of pre-sorting the list occurs when there are _many_ queries. For example, when there is an unsorted list of length $n$, and then $q$ members...
null
null
I would like to generate helpful parser errors, telling the user how to fix their program. Specifically I have a deterministic context-free language $L$, given in the form of an $LR(1)$ grammar. I have a syntactically invalid string $w$ (i.e. $w \not\in L$). I would like to find some $w^* \in L$ which minimizes the ...
Edit distance into a DCFL
|parsers|search-problem|edit-distance|lr-k|
null
I believe that something like the [KITTI dataset][1] is what you are looking for. It is a large dataset made for Autonomous Vehicle Research. You can download after providing your email. You can also try looking at the raw [KITTI data][2]. [1]: http://www.cvlibs.net/datasets/kitti/ [2]: http://www.cvlibs....
Yes, there are minimalistic programming languages where many of the things considered "primitives" in other programming languages are built up from even simpler things. For example, most programming languages have if-then-else, repeat-until, etc. built in. However, assembly language, as well as a few minimalistic...
null
As others have data to show correctness in computers, I wanted to add something about computer errors. In short, a filed bug can be designated as expected behavior for several reasons, and then adopted as part of the process. This was an actual postmortem to code that managed account creation for credit report data....
null
In general, constant-dimension LP can be solved in a strongly polynomial time. The easiest way is just trying all vertices. A vertex is determined by $3$ half-planes (inequalities including the non-negativity constraints). Running a Gaussian elimination on a candidate set of half-planes will give a point if the half...
null
This is about memory, not files or filesystems. So in a typical process, imagine you have a string "Hello world" that later gets changed to "Hello". Or a list of 100 objects later gets reduced to 50. Or a dynamic array, or other datastructures. This produces wasted space in memory. It's not solved with virtual me...
Are there any "fast" algorithms for defragmenting memory?
|big-o-notation|memory-management|
Most memory allocators don't do memory defragmentation at the level of individual objects. Instead, when the process next allocates new objects that are the same size or smaller, the allocator will reuse the space from some previously deallocated object. (If all objects placed a single page have been deallocated, the...
I think a direct reduction can be done by the following process: setup a enable gate $e_i$ for each integer $x_i$ (then we can represent each bit of $x_i$ using $e_i$ and $0$), add all integers (with enable gate) up using adder circuits, then compare the overall sum with goal $t$. Here we obtained a circuit with $n$ i...
I needed to implement a priority queue for a project I'm working on and had this idea. In a priority queue BST implementation wouldn't it be more efficient if the poll node pointed to its parent since it's guaranteed to not have a left child? This would make polling faster since we don't have to traverse the tree to fi...
Did I invent a new data structure?
|data-structures|binary-search-trees|priority-queues|
I needed to implement a priority queue for a project I'm working on and had this idea. In a priority queue BST implementation wouldn't it be more efficient if the poll node pointed to its parent since it's guaranteed to not have a left child? This would make polling faster since we don't have to traverse the tree to fi...
null
null
It is the converse. $$X^*X=X^+.$$ (This can be taken as a definition of the Kleene plus.)
Your reasoning is relevant: sorting a list to perform a single search would be foolish. The general idea of search algorithms is that you spend some time preprocessing the data structure, in such a way that the cost of the subsequent searches is lowered. But of course, the total cost after the desired number of quer...
What is the difference between this two pseudocode and which one should i implement? function A*(start,goal) closedset := the empty set % The set of nodes already evaluated. openset := set containing the initial node % The set of tentative nodes to be evaluated. g_score[st...
A* pseudocode problem
|algorithms|pseudocode|a-star-search|
null
There is only 1 real difference between them, the first explicitly excludes nodes from the neighbors that have been explored already, but that is easy enough to add in the second implementation however you can guarantee that `tentative_gScore < gScore[neighbor]` will be false if `neighbor` has already been explored. Fl...
it's a small optimization for the purpose of puling out the left most node not enough to call it a new data structure IMO. There are is another time when this optimization is a pessimization; If the left-most node you remove doesn't have any children then it's parent must now point to its own parent. This requires ...
null
Usually pages that are used by the kernel are marked as "forced resident" or "swappable" or "cache". Let's say the kernel uses some memory to cache the contents of a file or directory. The purpose is to avoid reading the file or directory again. Swapping this memory would be absolutely pointless. Just remember that...
When we use a set for doing Dijkstra's Algorithm, we use a pair of {distance,node} which we insert in a set. Most of the articles say that the first element of pair should be the distance , else we need to use a custom comparator, but why in the case of set if we use pair of {node, distance} the code still works. Anoth...
Does order of elements in a set matter in Dijkstra's Algorithm?
|graphs|shortest-path|sets|priority-queues|dijkstras-algorithm|
It cannot be true simultaneously that A is undecidable, A can be reduced to B, and B is decidable. Assume there are three "proofs" for each of these three facts, then at least one of the proofs is wrong. Actually, at least one of the three "facts" must be wrong. At this point we don't know which one. So we would probab...
When we use a set for doing **Dijkstra's Algorithm**, we use a pair of **{distance,node}** which we insert in a set. Most of the articles say that the first element of pair should be the distance , else we need to use a custom comparator, but why in the case of set if we use pair of **{node, distance}** the code still ...
When we use a set for doing **Dijkstra's Algorithm**, we use a pair of **{distance,node}** which we insert in a set. Most of the articles say that the first element of pair should be the distance , else we need to use a custom comparator, but why in the case of set if we use pair of **{node, distance}** the code still ...
null
The answer depends on the details of the STL library, so I'm sure it's suited for this website. That said, `std::set` is a *sorted* collection of elements and the default comparator for `std::set<T>` is `std::less<T>`. In your case `T` is `std::pair<int, int>` and `std::pair`s are compared lexicographically. T...
The answer depends on the details of the STL library, so I'm sure it's suited for this website. That said, `std::set` is a *sorted* collection of elements and the default comparator for `std::set<T>` is `std::less<T>`. In your case `T` is `std::pair<int, int>` and `std::pair`s are compared lexicographically. T...
In general: yes. The correctness of Dijkstra's algorithm does depend on the order in which elements are extracted from the priority queue. You do need to extract them in non-decreasing order of their tentative distance (at extraction time). Your particular question depends on the details of the STL library, so I'm s...
In general: yes. The correctness of Dijkstra's algorithm does depend on the order in which elements are extracted from the priority queue. You do need to extract them in non-decreasing order of their tentative distance (at extraction time). Your particular question depends on the details of the STL library, so I'm s...
null
Note: I had [posted](https://stackoverflow.com/questions/73122384/use-of-break-statement-in-this-solution) this question on Stack Overflow, and got a suggestion to post it to CS Stack Exchange. <hr> [The original question](https://www.hackerearth.com/practice/algorithms/dynamic-programming/bit-masking/practice-pr...
Use of break statement in this solution, and time complexity
|time-complexity|dynamic-programming|
null
null
Unless your functions have very special properties known beforehand, $O(\log n)$ is optimal. Because in a comparison-based model, you need to find which interval contains the argument, and this takes the computation of at least $\lg n$ bits of information. Faster can only be achieved by *computing* the interval ...
Unless your functions have very special properties known beforehand, $O(\log n)$ is optimal (assuming sorted bounds). Because in a comparison-based model, you need to find which interval contains the argument, and this takes the computation of at least $\lg n$ bits of information. Faster can only be achieved by ...
Unless your functions have very special properties known beforehand, $O(\log n)$ is optimal and achieved by dichotomic search (assuming sorted bounds). Because in a comparison-based model, you need to find which interval contains the argument, and this takes the computation of at least $\lg n$ bits of information. ...
I have been reading AIMA by Russell and Norvig, where they talk about different types of environments an agent may encounter. Here, they have described stochastic and non-deterministic environments being different types of environments. > One final note: our use of the word "stochastic" generally implies that uncert...
Difference between a stochastic environment and non-deterministic environment
|artificial-intelligence|
A stochastic situation is like when you throw a fair coin. You know the probabilities of the outcomes. You may often assume that the distribution remains constant. A non-deterministic situation is when you sit in front of a black box that may turn on a green or red light and you have no idea what will happen, but yo...
A stochastic situation is like when you throw a fair coin. You know the probabilities of the outcomes. You may often assume that the distribution remains constant, let alone is known. A non-deterministic situation is when you sit in front of a black box that may turn on a green or red light and you have no idea what...
I've seen a lot of mechanical computers based on gears and rigid rods, but none so far that consequently use belts (not chains) for transmission of information. Belts allow for easy negation (by crossed belts), simple logic gates (using different contact pressures of the belt on the green wheel or shaft), and even o...
Belt-based mechanical computers
|computer-architecture|computation-models|
Look into tools like [Frama-C][1], [SPARK][2], [Astrée][3], etc... They have their use in very specific cases, notably software verification of small to medium sized embedded safety critical software (e.g. inside aircrafts, per [DO-178C][4], or nuclear power plants, etc...). Such software have a few dozen thousands ...
null
In general: yes. The correctness of Dijkstra's algorithm does depend on the order in which elements are extracted from the priority queue. You do need to extract them in non-decreasing order of their tentative distance (at extraction time). Your particular question depends on the details of the STL library, so I'm n...
It would appear the language edit distance problem for the class of deterministic context-free languages requires cubic time. In _Language Edit Distance Approximation via Amnesic Dynamic Programming_ (Jayaram and Saha, https://rajeshjayaram.com/mainb-3.pdf), it is shown that cubic time is required for the ultraline...
The problem with the idea of a modular or a-la-carte programming language (if I understand the question correctly) is that the main challenge of designing programming languages in the first place is *integrating* a wide variety of features and requirements without undue verbosity or a wild proliferation of syntactical ...
It would appear the language edit distance problem for the class of deterministic context-free languages requires cubic time. In _Language Edit Distance Approximation via Amnesic Dynamic Programming_ (Jayaram and Saha, https://rajeshjayaram.com/mainb-3.pdf), it is shown that cubic time is required for the ultraline...
Is it true that simulating classical physical systems is in P, i.e. can be done efficiently on Turing machines or are there known exceptions? I'm thinking of chaotic systems but I'm also curious more generally whether there are theorems or counterexamples.
Can all non-quantum physical systems be efficiently simulated on a classical computer?
|complexity-theory|complexity-classes|simulation|physics|
null
I have been studying the Branch and Bound paradigm. I came accross an approach to solve the Travelling Salesman Problem using branch and bound where a specific kind of bounding function was used. I've been wondering why this bounding function (which performs a kind of reduction on the adjacency matrix of the graph unde...
Bounding function for Travelling Salesman Problem
|traveling-salesman|branch-and-bound|