instruction stringlengths 0 29.8k ⌀ |
|---|
|algorithms|numerical-analysis| |
Consider the following two observations (left as an exercise to the reader):
1. The even powers of two are 1 modulo 3.
2. The odd powers of two are -1 modulo 3.
We conclude that that a number (in binary) is divisible by three if and only if the sum of the bits in the even positions equals the sum of the bits in ... |
You didn't define what 'connecting all parts' is. Do you need to arrange them in an array? Or just connect them?
The way I understood the problem, you can use Prim's algorithm to find the minimum spanning tree, and that's the result. O(n^2)
In case you want them arranged in an array, I think the sorted array is a... |
We have a broken stick. For every part, we know it's length. Our task is to connect all parts (glue them), that we will use as small amount of glue as possible.
The amount of glue need to connect two parts equal the maximum from their sizes. We can only glue two parts at one time.Can we solve this problem in the ti... |
Broken stick problem |
|complexity-theory|algorithms|dynamic-programming| |
Homework?
See the problem "Cutting Wood", which involves cutting rather than glueing, but is otherwise equivalent. Provided the orders matters (as noted by Marzio).
> Your favorite sawmill charges by length to cut each board of lumber.
> For example, to make one cut anywhere on an 8 ft. board of lumber costs \$... |
While not binary-specific, when in doubt, repeated subtraction is always a surefire way to compute division with remainder (and thus if a number is a multiple of 3). |
I need to design a Turing Machine that accepts the (context-free) language: $L(M)=\{0^{n}1^{n+1}: n\ge1$}.
$$Q=\{q_0,q_1,q_2,q_3,q_4\} ,Σ = \{0,1\}, Γ =\{0,1,X,Y,B\}, F=\{q_4\}$$
So far I've succeeded to create a table for languages $\{0^n1^n\}$(without the red entry) and $\{0^n1^k:k\ge n\}$.
!["P" means the ... |
|automata|turing-machines| |
null |
null |
In binary, numbers 1, 100, 10000 (=100×100), 1000000 (=100×100×100) etc. all give the same remainder after dividing by 11 (three). Therefore if we split a binary number to parts of *even length*, the sum of the parts gives the same remainder as the original number.
(When splitting the number, we add as many zeroes a... |
Consider we have a $k$D array filled with $0$ and $1$'s. The dimension of the array is $d_1\times\ldots\times d_k$. Let $N = \prod_{i=1}^k d_i$. We want to query a $k$D box and return
1. If there exist a $1$ in the box in $O(1)$ time.
2. Position of a $1$ in the box if there is one in $O(1)$ time.
We want to u... |
You can save a lot more on memory if you just allow logarithmic time complexity. You can implement a kD segment tree that will need N * 2^k bits memory, and runs in logarithmic time complexity for both subtasks, and logarithmic time complexity for building the tree.
If you strictly want O(1), precompute everything. |
Consider we have a $k$D array filled with $0$ and $1$'s. $k$ is a constant. The dimension of the array is $d_1\times\ldots\times d_k$. Let $N = \prod_{i=1}^k d_i$. We want to query a $k$D box and return
1. If there exist a $1$ in the box in $O(1)$ time.
2. Position of a $1$ in the box if there is one in $O(1)$ ti... |
Consider we have a $k$D array filled with $0$ and $1$'s. $k$ is a constant. The dimension of the array is $d_1\times\ldots\times d_k$. Let $N = \prod_{i=1}^k d_i$. We want to query a $k$D box and return
1. If there exist a $1$ in the box in $O(1)$ time.
2. Position of a $1$ in the box if there is one in $O(1)$ ti... |
{"Voters":[{"Id":867,"DisplayName":"AJed"}]} |
Your algorithm will work. The information you will be looking for can be found in the prefix tree (trie) will hold the information you are looking for.
Despite similarity in names, the set cover and this problem are not similar. The first is NP-Hard. This one is not.
However (in relation to Point 3 of your algo... |
{"Voters":[{"Id":867,"DisplayName":"AJed"}]} |
I need to design a Turing Machine that accepts the (context-free) language: $L(M)=\{0^{n}1^{n+1}: n\ge1$}.
$$Q=\{q_0,q_1,q_2,q_3,q_4\} ,Σ = \{0,1\}, Γ =\{0,1,X,Y,B\}, F=\{q_4\}$$
So far I've succeeded to create a table for languages $\{0^n1^n\}$(without the red entry) and $\{0^n1^k:k\ge n\}$.
!["P" means the ... |
I need to design a Turing Machine that accepts the (context-free) language: $L(M)=\{0^{n}1^{n+1}: n\ge1$}.
$$Q=\{q_0,q_1,q_2,q_3,q_4\} ,Σ = \{0,1\}, Γ =\{0,1,X,Y,B\}, F=\{q_4\}$$
X- processed 0<br>
Y- processed 1<br>
B- blank<br>
P-move right<br>
L-move left<br>
So far I've succeeded to create a table for la... |
I need to design a Turing Machine that accepts the (context-free) language: $L(M)=\{0^{n}1^{n+1}: n\ge1$}.
$$Q=\{q_0,q_1,q_2,q_3,q_4\} ,Σ = \{0,1\}, Γ =\{0,1,X,Y,B\}, F=\{q_4\}$$
X- processed 0<br>
Y- processed 1<br>
B- blank<br>
P-move right<br>
L-move left<br>
So far I've succeeded to create a table for la... |
null |
What about a finite state automaton for the job?
![enter image description here][1]
[1]: https://i.stack.imgur.com/0dAZC.jpg |
What about a finite state automaton for the job?
![enter image description here][1]
[1]: https://i.stack.imgur.com/oKpNt.jpg |
null |
null |
What's wrong with making your partial ordering complete?
> But rather than arbitrarily completing the order, I would prefer if the queue was stable in a sense that if there is more than one minimal element, it should return the oldest first.
If you prefer 'oldest first', then your order is effectively complete; '... |
My use of terminology may be incorrect. Please edit my answer directly to fix any problems you find.
----
First, mutually incomparable sets need to be detected from the inputs.
For example, there may be 5 objects, `a, b, c, d, e`, but their partial ordering form two disconnected graphs:
* `a ≤ b ≤ c`
* `... |
I have a some objects with priority that is compound type and is only [partially ordered](http://en.wikipedia.org/wiki/Partial_ordering). I need to select the objects in order of this priority (i.e. yield _minimal_ item each time). But rather than arbitrarily completing the order, I would prefer if the queue was stable... |
Priority queue for partially ordered priorities |
|data-structures| |
I have a some objects with priority that is compound type and is only [partially ordered](http://en.wikipedia.org/wiki/Partial_ordering). I need to select the objects in order of this priority (i.e. yield _minimal_ item each time). But rather than arbitrarily completing the order, I would prefer if the queue was stable... |
|data-structures|priority-queues| |
I need help figuring the potential function for a max heap so that extract max is completed in O(1) (amortised). I should add that I do not have a good understanding of the potential method.
I know that the insert function should "pay" more in order to reduce the cost of the extraction, and this has to be in regard... |
Potential function binary heap extract max O(1) |
|heaps|amortized-analysis| |
null |
In peer-to-peer (P2P) networks nodes are interconnected with each other. In client/server (C/S) networks clients talks to the server. If in a C/S network clients also want to talk with each other (such as in a multiplayer online game), then clients would have to communicate through the server.
Given these, is it pos... |
P2P and C/S, is it possible to determine which one is more bandwidth consuming? |
|computer-networks|network-topology| |
Your data structure (that you want do) when it _fetch_ an element it starts by picking the _maximal_ (minimal) elements (with respect to some partial order). From this set you want to have the _oldest_ element. Here you have two orders. One of them is total (time), the other is partial (call it $P$). [right ?]
For e... |
One would say that P2P is better. But in reality, you cannot tell by the information you provided.
For instance, the bandwidth depends on queuing delays. Therefore, assume that one of the nodes in the P2P network has a very small queue (or overloaded), while our server is super powerful and its queue is hugly big ! ... |
You can do all of these if $O(1)$ expected amortized time.
The essential trick is that we don't need the full power of a priority queue, since key frequency only changes by 1 during each insert or delete.
Maintain a doubly-linked list of Buckets, where each Bucket has a non-empty hash set of keys (that I'll call a ... |
Suppose there are $n$ tasks, which need to be scheduled by a pre-emptive scheduler. Each task $i$ has a deadline $d_i$ and a total processing time $t_i$ associated with it. Now, all $n$ tasks are given a priory to the scheduler. The scheduler can run a task for 1 unit of time in one go. After each unit of time, it can ... |
Scheduling algorithm to minimize maximum deadline overshoot |
|algorithms|optimization|scheduling| |
null |
null |
I need help figuring the potential function for a max heap so that extract max is completed in $O(1)$ amortised time. I should add that I do not have a good understanding of the potential method.
I know that the insert function should "pay" more in order to reduce the cost of the extraction, and this has to be in r... |
|data-structures|heaps|amortized-analysis| |
Try the following:
The weight $w_i$ of an element $i$ in the heap $H$ is its depth in the corresponding binary tree. So the element in the root has weight zero, its two children have weight 1 and so on. The you define as potential function
$$\Phi(H)=\sum_{i\in H}2 w_i.$$
Let us now analyze the heap operations... |
The symbol $\leq_m$ means [many-one reducible][1], contrast to reductions such as turing reducible (denoted by $\leq_T$) and one-one reducible (denoted $\leq_1$).
A many-one reduction from $L$ to $L′$ (given an alphabet $\Sigma$) is a (computable) function $f:\Sigma^* \to \Sigma^*$ such that for every $w \in \Sigma^... |
Yesterday I've done some research how to optimize genetic algorithm and I've encountered a very interesting theory that we can use lamarckian theory (adaptive theory) to optimize the neural network. But I still didn't understand how can it be done? what I've read from some source to optimize the genetic algorithm we mu... |
Lamarckian and Genetic algorithm |
|algorithms|algorithm-analysis|artificial-intelligence| |
null |
I'm working exercises on solving recurrences, just using subsitution, master theorem is after this chapter. I'm sort of stuck on one of the exercises. It states that:
The solution of $T(n) = 2T(\lfloor n/2 \rfloor) + n$ is $O(n \lg n)$. Show that it's also $\Omega(n \lg n)$ and conclude that the solution is $\Theta(... |
Showing bounds of a recurrence |
|time-complexity|algorithm-analysis| |
The problem *minimizing maximal lateness* is discussed in the algorithm book by Kleinberg and Tardos under *greedy algorithms*. The solution is like yours, ordering the tasks by their deadline. Indeed the length of the tasks is not relevant.
The main ingredient of the proof is that any optimal solution $O$ can be tr... |
The problem *minimizing maximal lateness* is discussed in the algorithm book by Kleinberg and Tardos under *greedy algorithms*. The solution is like yours, ordering the tasks by their deadline. Indeed the length of the tasks is not relevant.
The main ingredient of the proof is that any optimal solution $O$ can be tr... |
null |
|asymptotics|recurrence-relation| |
|algorithms|asymptotics|landau-notation| |
|formal-languages|context-free|closure-properties| |
null |
|complexity-theory|complexity-classes|p-vs-np| |
Suppose there are $n$ tasks, which need to be scheduled by a *pre-emptive* scheduler. Each task $i$ has a deadline $d_i$ and a total processing time $t_i$ associated with it. Now, all $n$ tasks are given a priory to the scheduler. The scheduler can run a task for 1 unit of time in one go. After each unit of time, it ca... |
Scheduling algorithm to minimize maximum deadline overshoot in pre-emptive scheduler |
The subset-sum problem is a classic NP-complete problem:
> Given a list of numbers $L$ and a target $k$, is there a subset of numbers from $L$ that sums to $k$?
A student asked me if this variant of the problem called the "subset product" problem is NP-complete:
> Given a list of numbers $L$ and a target $k$, ... |
Is the "subset product" problem NP-complete? |
|np-complete| |
Suppose there are $n$ tasks, which need to be scheduled by a *pre-emptive* scheduler. Each task $T_i$ has a deadline $d_i$ and a total processing time $t_i$ associated with it. Now, all $n$ tasks are given a priory to the scheduler. The scheduler can run a task for 1 unit of time in one go. After each unit of time, it ... |
null |
Suppose there are $n$ tasks, which need to be scheduled by a *pre-emptive* scheduler. Each task $T_i$ has a deadline $d_i$ and a total processing time $t_i$ associated with it. Now, all $n$ tasks are given a priory to the scheduler. The scheduler can run a task for 1 unit of time in one go. After each unit of time, it ... |
null |
Yesterday I've done some research how to optimize genetic algorithm and I've encountered a very interesting theory that we can use Lamarckian theory (adaptive theory) to optimize the neural network. But I still didn't understand how can it be done? What I've read from some source to optimize the genetic algorithm we mu... |
|algorithms|artificial-intelligence|genetic-algorithms| |
First, I would like to modify your statement slightly to remove any chance of confusion. When you say, "... $T(n) \le cn\log n$ for any appropriate $c > 0$ and $n \ge n_0$", it actually means $T(n) \le cn\log n$ for *some* appropriate $c > 0$ for *all* $n \ge n_0$.
Next, these constants for proving the lower bound c... |
null |
Yes it is. Have a look at: [[1]]
I also cite the same reference:
Comments: There is a subtle technical distinction between this and Problem 42: the former case has a pseudo-efficient algorithm obtained by allowing numbers to be represented in unary; unless all NP-complete problems can be solved by fast algorithms,... |
According to [[1]]: Yes it is
I also cite the same reference:
Comments: There is a subtle technical distinction between this and Problem 42: the former case has a pseudo-efficient algorithm obtained by allowing numbers to be represented in unary; unless all NP-complete problems can be solved by fast algorithms, h... |
null |
According to [[1]]: Yes it is
I also cite the same reference:
Comments: There is a subtle technical distinction between this and Problem 42: the former case has a pseudo-efficient algorithm obtained by allowing numbers to be represented in unary; unless all NP-complete problems can be solved by fast algorithms, h... |
According to [[1]]: Yes it is
I also cite the same reference:
Comments: There is a subtle technical distinction between this and Problem 42: the former case has a pseudo-efficient algorithm obtained by allowing numbers to be represented in unary; unless all NP-complete problems can be solved by fast algorithms, h... |
I am new to discrete mathematics and the theory of computation I am trying to learn and understand the terminology.
I am having a difficult time understanding the difference between a set and a sequence. I understand that unlike a set, in a sequence order and repetition does matter and sequences contain objects rat... |
The difference between a sequence and a set |
|logic|computability| |
I am new to discrete mathematics and the theory of computation I am trying to learn and understand the terminology.
I am having a difficult time understanding the difference between a set and a sequence. I understand that unlike a set, in a sequence order and repetition does matter and sequences contain objects rat... |
|computability|terminology|logic| |
|neural-networks| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.