instruction
stringlengths
0
29.8k
βŒ€
There are obvious analogs (pardon the pun) in Boolean algebra and regular algebra. They have similar rules, operators and properties. I can't figure out why Karnaugh Maps, which are used to derive a Boolean function from a truth table, doesn't have an equivalent in standard algebra. Obviously, if you could do it then y...
Why can't we use Karnaugh Maps in non-boolean algebra?
|algorithms|computability|logic|
null
null
There are obvious analogs (pardon the pun) between Boolean algebra and algebra. They have similar rules, operators and properties. I can't figure out why Karnaugh Maps, which are used to derive a Boolean function from a truth table, doesn't have an equivalent in algebra. If you could do it then you could theoretica...
null
Let $P = p_1\dots p_n$ to sorted list of points. --- Following your recurrence for one path, the first thing to note is that you have to keep track of which points have been visited by the paths; otherwise you can not count correctly. The second thing is that you have now *four* possibilities for every point: nei...
The general case is indeed a bit complicated. However, in the case of **4 disks** you can simplify it a lot; you do not really need to know any fancy math. You only need to know how to store **4 bits** redundantly, and then you already know everything; just repeat the same scheme for each group of 4 bits that you ne...
The general case is indeed a bit complicated. However, in the case of **4 disks** you can simplify it a lot; you do not really need to know any fancy math. You only need to know how to store **4 bits** redundantly, and then you already know everything; just repeat the same scheme for each group of 4 bits that you ne...
The general case is indeed a bit complicated. However, in the case of **4 disks** you can simplify it a lot; you do not really need to know any fancy math. You only need to know how to store **4 bits** redundantly, and then you already know everything; just repeat the same scheme for each group of 4 bits that you ne...
I am having trouble finding good resources that give a worst case $O(n \ln n)$ [in place](http://en.wikipedia.org/wiki/In-place_algorithm) [stable](http://www.algorithmist.com/index.php/Stable_Sort) sorting algorithm. Does anyone know of any good resources? Just a reminder, in place means it uses the array passed i...
Worst case $O(n \ln n)$ in place stable sort?
|algorithms|reference-request|sorting|
You can write an in-place, stable mergesort. See [this][1] for details. In the author's own words: > A beautiful in place - merge algorithm. Test it on inverted arrays to understand how rotations work. Fastest known in place stable sort. No risk of exploding a stack. Cost: a relatively high number of moves. Stack ca...
null
I have a run-time implementation question regarding the 3-dimensional approximation algorithm: How can I construct the maximum matching M_r in S_r in linear time in line 8? Input: a set S of triples Output: a matching M in S 1) construct maximal matching M in S; 2) change = TRUE; 3) w...
3-dimensional matching approximation algorithm (implementation details)
|algorithms|graph-theory|graphs|approximation|packing|
I have a run-time implementation question regarding the 3-dimensional (unweighted 2-)approximation algorithm below: How can I construct the maximum matching M_r in S_r in linear time in line 8? Algorithm: unweighted 3-dimensional matching (2-approximation) [1] Input: a set S of triples Output: a match...
I have a run-time implementation question regarding the 3-dimensional (unweighted 2-)approximation algorithm below: How can I construct the maximum matching M_r in S_r in linear time in line 8? $X, Y, Z $ are disjoint sets; a matching $M$ is a subset of $S$ s.t. no two triples in $M$ have the same coordinate at any...
If you had an oracle from Graph Isomorphism, then for constant $t$ you can check whether a graph is $t$-transitive. For example, to check if a graph is $1$-transitive, for every vertex $i$ create a variant $G_i$ of your original graph by attaching an "appendage" at vertex $i$, say a very long path or a very large star....
There are obvious analogs (pardon the pun) between Boolean algebra and algebra. They have similar rules, operators and properties. I can't figure out why Karnaugh Maps, which are used to derive a Boolean function from a truth table, doesn't have an equivalent in algebra. If you could do it then you could theoretica...
There are obvious analogs (pardon the pun) between Boolean algebra and algebra. They have similar laws, operators and properties. I can't figure out why Karnaugh Maps, which are used to derive a Boolean function from a truth table, doesn't have an equivalent in algebra. Perhaps it does, but I haven't seen it. My o...
I know that graph contractability is $NP$-complete. To be specific given $G=(V_1,E_1)$ and $H=(V_2,E_2)$, can a graph isomorphic to H be obtained from G by a sequence of edge contractions ? However my problem is a little bit different from the traditional graph contractability. In the traditional graph contractabili...
$NP$-completeness proof
|graphs|np-complete|
There are obvious analogs (pardon the pun) between Boolean algebra and algebra. They have similar laws, operators and properties. I can't figure out why Karnaugh Maps and sum of products, which are used to derive a Boolean function from a truth table, doesn't have an equivalent in algebra. Perhaps it does, but I haven...
Can truth tables be used in non-boolean algebra to derive functions?
We don't need the maximum matching, just one of cardinality $2$ if it exists. Scan $S_r$ looking for a triple $T$ such that $\lvert T \cap \{a, b, c\}\rvert = 1$. If no such $T$ exists, then the maximum cardinality of a matching is clearly $1$. Otherwise, assume without loss of generality that $T = \{a, x, y\}$. ...
I was solving the problem on a segment tree,But I am not able to make a little modification to the query function of segment tree . Actually What I want is my query function should return the (int)(TotalArrayLength/3) th maximum element between index Qa and Qb. The Query Function that I wrote Returns the Maximum ...
Kth Maximum Querying Segment Tree
|algorithms|
null
We are given a random number generator **RandNum50()** which generates numbers in the range 1-50. We need to use only this random number generator to print 1-00 in any order, but every number should come only once. And probability of any number occurring at any place is equal. **What should be most efficient algo f...
Most efficient algorithm to print 1-100 using a given random number generator
|random-number-generator|
We are given a random number generator **RandNum50()** which generates numbers in the range 1-50. We need to use only this random number generator to generate and print 1-00 in any order, but every number should come only once. And probability of any number occurring at any place is equal. **What should be most eff...
I thought (so it can be wrong :-) of this $O(N^2)$ solution that uses the [Fisher-Yates shuffle][1]. In order to keep uniform distribution, at every iteration you can use this trick to produce a value $krand$ between $0$ and $k-1$: // return a random number in [0..k-1] with uniform distribution // using ...
We are given a random number generator `RandNum50` which generates numbers in the range 1-50. We need to use only this random number generator to generate and print 1-00 in any order, but every number should come only once. And probability of any number occurring at any place is equal. What should be most efficient...
|algorithms|randomness|random-number-generator|
Basically, the problem I am solving is this. Initially, the array $A$ is empty. Then I am given data to fill the array and at any time I have to make a query to print the $|A|/3$-th largest element inserted so far. I was solving the problem with segment trees, but I am not able to make a little modification to the q...
Finding the $k$th largest element in an evolving query data structure
|algorithms|data-structures|
Have a look at the [Wikipedia page for segment trees](https://en.wikipedia.org/wiki/Segment_tree): > It is, in principle, a static structure; that is, its content cannot be modified once the structure is built. So it does not seem to be a good data structure for your scenario at all. Note that the kind of quer...
null
Let $x_i,\ i=1\ldots,n$, be the list of nutritional values of the $n$ fruits, which I assume are nonnegative integers. You want to partition $\{1,\ldots,n\}$ into three sets $A,B,C$ to maximize the minimum of $x_A = \sum_{i\in A} x_i$, $x_B = \sum_{i \in B} x_i$, $x_C = \sum_{i \in C} x_i$. This is a variant of the s...
I'm having a very hard time trying to figure out how to solve this problem efficiently. Let me describe how it goes: "A hard working mom bought several fruits with different nutritional values for her 3 kids, Amelia, Jessica and Bruno. Both girls are overweight, and they are very vicious and always leave poor Bruno ...
Share Fruits Fairly Subset Problem
null
Let's say we have number 1 to 3, and now we push into a stack one by one in order, but we can choose to pop (print it out) one or many from stack before we push the next value into stack. Every time we pop a value from the stack, we will print it out. for example, **123** is corresponding to **push pop push pop p...
How to detect stack order?
|stacks|
|algorithms|
I'm having a very hard time trying to figure out how to solve this problem efficiently. Let me describe how it goes: "A hard working mom bought several fruits with different nutritional values for her 3 kids, Amelia, Jessica and Bruno. Both girls are overweight, and they are very vicious and always leave poor Bruno ...
Share Fruit Fairly
We have number **1 to n**, and now we push into a stack one by one in order, but we can choose to pop (print it out) one or many from stack before we push the next value into stack. Every time we pop a value from the stack, we will print it out. for example, **123** is corresponding to **push pop push pop push po...
The problem, restated and generalized: given a finite set $S$ equipped with a [partial order](http://en.wikipedia.org/wiki/Partial_order) $\le$, find chains $C_1, C_2 \subseteq S$ maximizing $\lvert C_1 \cup C_2 \rvert$. The question is about the case where $S \subseteq \mathbb R_+^2$ and $(x, y) \le (z, w) \Longleftri...
Suppose we are given an array of positive integers $P = [p_1, p_2 \dots p_N]$ where each $p_i$ represents the price of a product on a different day $i = 1 \dots N$. I would like to design an algorithm to find the maximum profit that you can given this array of prices. Profit is made by buying at a given date $i$ an...
Finding the Largest "Ordered" Difference in Elements of an Array
|sorting|
The problem, restated and generalized: given a finite set $S$ equipped with a [partial order](http://en.wikipedia.org/wiki/Partial_order) $\le$, find chains $C_1, C_2 \subseteq S$ maximizing $\lvert C_1 \cup C_2 \rvert$. The question is about the case where $S \subseteq \mathbb R_+^2$ and $(x, y) \le (z, w) \Longleftri...
The first observation is that the strategy of buying at the lowest price or selling at the highest price does not always maximize the profit. As you also note, the simple brute-force method works by trying every possible pair of buy and sell dates in which the buy date precedes the sell date. A period of $n$ days has $...
However shouldn't the trace $s1^w$ be more instructive for your reasons? in this trace $(GFp)$ holds always however $(GFq)$ doesn't, therefore $(GFp -> GFq)$ becomes false.
There are thousands of NP-complete problems in the literature, and most pairs do not have explicit reductions. Since polynomial-time many-one reductions compose, it suffices for researchers to stop when the graph of published reductions is strongly connected, making research into NP-completeness a much more scalable ac...
There are thousands of NP-complete problems in the literature, and most pairs do not have explicit reductions. Since polynomial-time many-one reductions compose, it suffices for researchers to stop when the graph of published reductions is strongly connected, making research into NP-completeness a much more scalable ac...
There's a [lot of debate](http://plato.stanford.edu/entries/church-turing/#Bloopers) about what exactly the Church-Turing thesis is, but roughly it's the argument that "undecidable" should be considered equivalent to "undecidable by a universal turing machine." I'm wondering if there's an analogous statement for tim...
Time complexity version of the Church-Turing Thesis
|terminology|turing-machines|
Are you familiar with the randomized contraction algorithm also known as [Karger's algorithm](http://en.wikipedia.org/wiki/Karger's_algorithm)? The algorithm basically works by selecting edges uniformly at random and contracting them with self-loops removed. The process halts when there are two nodes remaining, and the...
I think I figured out an $O(N)$ algorithm that works for this case. The algorithm is similar to mergesort except that no sorting is done, and merging two sub-arrays together involves tracking the minimum buy price and the maximum sell price within the combined array. The tricky part involves making sure that you cannot...
I don't actually have a solution, but here are a few ideas that came up. If you look at the results of XORing all of the numbers in the sequence, that gives an upper bound on the number of additions you need to do. For example, in your example of 10, 4, 5, 1 10^4^5^1 yields 10, so you know you don't have to add ...
Given a sequence of natural numbers, you can add any natural number to any number in the sequence such that their xor becomes zero. My goal is to minimize the sum of added numbers. e.g. Consider the following examples : 1. sequence : 1, 3 answer : 2, adding 2 to 1 we get 3^3=0. 2. sequence : 10, 4, 5, 1 an...
How can I find minimum number required to add to sequence such that their xor becomes zero
|untagged|
|algorithms|arrays|integers|xor|
We take the sequence of integers from $1$ to $n$, and we push them onto a stack one by one in order. Between each push, we can choose to pop any number of items from the stack (from 0 to the current stack size). Every time we pop a value from the stack, we will print it out. For example, $1,2,3$ is printed out wh...
|algorithms|stacks|
null
I'm having a very hard time trying to figure out how to solve this problem efficiently. Let me describe how it goes: "A hard working mom bought several fruits with different nutritional values for her 3 kids, Amelia, Jessica and Bruno. Both girls are overweight, and they are very vicious and always leave poor Bruno ...
Partition of a set of integer into 3 subsets of approximately equal sum
|algorithms|integers|approximation|linear-programming|
We are given a random number generator `RandNum50` which generates a random integer uniformly in the range 1–50. We may use only this random number generator to generate and print all integers from 1 to 100 in a random order. Every number must come exactly once, and the probability of any number occurring at any place...
|algorithms|integers|randomness|random-number-generator|
If you just need approximate equality, you can use the naive solution to dividing fruit: 1. Sort the fruit according to nutritional value. 2. Put the fruit with the most nutrition in basket #1. 3. Put the fruit with the next highest nutrition in basket #2. 4. Put the fruit with the next highest nutrition in baske...
I couldn't understand your approach exactly (Seems it's correct), but there is a simple rule for impossible orders: The order is impossible $iff$ there is $a_i,a_j,a_k$ such that $a_i > a_k > a_j$ and $i<j<k$. To such a $a_i,a_j,a_k$ we say bad triple. Why? First you should prove that if there is bad triple then the...
null
I have a problem with the application of the [shannon expansion](http://en.wikipedia.org/wiki/Shannon_expansion) for to obtain the negation of a formula boolean,than will need for implement the negation operator on OBDD([Order Binary Decision Diagram](http://en.wikipedia.org/wiki/Binary_decision_diagram) that is, dem...
Operations on OBDD :negation through Shannon's expansion
|logic|information-theory|
I couldn't understand your approach exactly (Seems it's correct), but there is a simple rule for impossible orders: The order is impossible $iff$ there is $a_i,a_j,a_k$ such that $a_i > a_k > a_j$ and $i<j<k$. To such a $a_i,a_j,a_k$ we say bad triple. Why? First you should prove that if there is bad triple then the...
|graph-theory|logic|information-theory|
null
I have a problem with the application of the [Shannon expansion](http://en.wikipedia.org/wiki/Shannon_expansion) for to obtain the negation of a formula boolean, than will need for implement the negation operator on OBDD ([Order Binary Decision Diagram](http://en.wikipedia.org/wiki/Binary_decision_diagram) that is, dem...
Operations on OBDD: negation through Shannon's expansion