instruction
stringlengths
0
29.8k
⌀
As not mentioned there are 2 possibilities, Case 1: when $j,k \in N$ $L = $ {$a^{n}$ | $n=3j+4k>=0$} We have to find possible solutions of $3j+4k>=0$, for $j,k >=0$ this equation holds true, we can rewrite $a^{n}$ as follow $a^{n} = a^{3j+4k}$ $=a^{3j}.a^{4k}$ $=(a^{3})^{j}.(a^{4})^{k}$ from here the l...
As nothing is mentioned about $j,k$ I can think of 2 possible cases, **Case 1**: when $j,k \in N$ $L = $ {$a^{n}$ | $n=3j+4k>=0$} We have to find possible solutions of $3j+4k>=0$, for $j,k >=0$ this equation holds true, we can rewrite $a^{n}$ as follow $a^{n} = a^{3j+4k}$ $=a^{3j}.a^{4k}$ $=(a^{3})^{j}.(...
null
#### Two modulo opertions There are two modulo operations for a modulus $0\not=q\in\Bbb N$. $\newcommand{\q}{\!\!\pmod q}$ $\newcommand{\Q}{\text{mod}_q}$. - Let $\text{mod}_q:\Bbb Z\to\Bbb Z/q\Bbb Z$, $\text{mod}_q(x)=\{\cdots, x-2q,x-q, x, x+q, x+2q, \cdots,\}$. We also write the last set as $\bar x_q$ or $x\q$...
I am writing a new answer because I can't comment yet. I'm new to graph problems, but I think it is possible to optimise a bit Jonh L.'s answer by finding the cycle in a way that is O(logn) instead of O(n). Of course, the complexity of the whole algorithm itself remains the same (logn + n is still O(n)), but it's...
I am writing a new answer because I can't comment yet. I'm new to graph problems, but I think it is possible to optimise a bit Jonh L.'s answer by finding the cycle in a way that is O(logn) instead of O(n). Of course, the complexity of the whole algorithm itself remains the same ((c + 1)logn + n is still O(n)), b...
#### Two modulo operations There are two modulo operations for a modulus $0\not=q\in\Bbb N$. $\newcommand{\q}{\!\!\pmod q}$ $\newcommand{\Q}{\text{mod}_q}$. - Let $\text{mod}_q:\Bbb Z\to\Bbb Z/q\Bbb Z$, $\text{mod}_q(x)=\{\cdots, x-2q,x-q, x, x+q, x+2q, \cdots,\}$. We also write the last set as $\bar x_q$ or $x\q...
|search-algorithms|modular-arithmetic|string-matching|rolling-hash|
To my knowledge, in block-structured programming languages, there are 2, maybe 3 main ways of delimiting a block. 1. Using start and end tokens, this can be brackets or reserved words etc 2. Using indentation, like python, which uses the offside rule to delimit blocks 3. Using prefix notation for control struct...
what are all the ways of delimiting blocks
|programming-languages|strings|parsers|syntax|
In the factory function that generates MC definition, each state has the probability of transitioning to other states that're uniformly random, I guess that this is the biggest problem. Suggestion for improvement: Make the probability more sparse and skewed for each state for starters. (I've made a [new commit](h...
For what example would [Maekawa's algorithm][1] allow out of timestamp order access to the critical section. It is mentioned that ordering is not satisfied in Maekawa's algorithm. But in what scenario would this be true? From my understanding, we will always have the queue at each process that follows FIFO and will ...
null
null
If we think of the algorithmic problem of doing a convolution of two arrays, it turns out that converting them to the frequency domain first and then doing an element-wise product is equivalent. And this leads to an efficient algorithm where we invoke the FFT to go to the frequency domain efficiently (in $O(n \log(n))$...
I'm working on the implementation of a cantor set on a 2-dimensional plane. It looks like this. Honestly, There is the obvious algorithm for the cantor set, but it includes a recursive method call. Unfortunately, My environment(Houdini vex) does not support recursive function calls, so I have to design the algorithm wi...
Implementation of cantor set without recursion
|recursion|
I have the following problem: > Given a context-free grammar $\mathcal{G}$ and a finite state automaton $\mathcal{A}$, where both are over the alphabet $\Sigma=\{0, 1\}$. Is it decidable whether $L(\mathcal{G})=L(\mathcal{A})$? I assume this is *undecidable*, since I already know the following fact: > It is undeci...
Is the equivalence problem of a CFG and a FSM decidable?
|regular-languages|finite-automata|context-free|undecidability|
I have the following problem: > Given a context-free grammar $\mathcal{G}$ and a finite state automaton $\mathcal{A}$, where both are over the alphabet $\Sigma=\{0, 1\}$. Is it decidable whether $L(\mathcal{G})=L(\mathcal{A})$? I assume this is *undecidable*, since I already know the following fact: > It is undeci...
Yes. It can be expressed without recursion, as long as you have loops and data structures. Any recursive algorithm can be converted to a non-recursive iterative algorithm, by introducing an explicit stack. See, e.g., https://cs.stackexchange.com/q/67897/755, https://cs.stackexchange.com/q/13139/755, https://cs.stacke...
null
Yes, your assumption is right regularity of context-free languages is undecidable. You can look at the problem like this, If $L(G) = L(A)$ then we can say $L(G) \subseteq L(A)$ and $L(A) \subseteq L(G)$ which can also be written as $L(G) \cap L(A)^{c} = \phi$ and $L(A) \cap L(G)^{c} = \phi$ Now for the first...
Try to find simple functions $x=x(n)$ and $y=y(n)$ such that $a_{n+1} = x\cdot a_n + y\cdot a_{n-1}$. Thus $(n+1)! + 2^{n+1} = x n! + x 2^n + y\cdot (n-1)! + y\cdot 2^{n-1}$. Then, hoping for good luck, separate the factorial and 2-power parts. $(n+1)! = x\cdot n! + y\cdot (n-1)! $ and $2^{n+1} = ...
null
Yes, your assumption is right regularity of context-free languages is undecidable. You can look at the problem like this, If $L(G) = L(A)$ then we can say $L(G) \subseteq L(A)$ and $L(A) \subseteq L(G)$ which can also be written as $L(G) \cap L(A)^{c} = \emptyset$ and $L(A) \cap L(G)^{c} = \emptyset$ Now for...
null
|programming-languages|strings|parsers|category-theory|syntax|
**Problem** A time based followship is defined as a person changing to a new job, and there is an existing employee there in the new company whom he used to work together. In this case, the old guy gets 1 ***follow***. **Challenge** I wrote some simulation code, but the complexity is quadratic and already tak...
Efficient Way to Calculate Timebased Followership
|time-complexity|time-series-analysis|
{"Voters":[{"Id":755,"DisplayName":"D.W."}]}
I have 2 arrays, **A** and **B**, which each contain **N** of the same elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one eleme...
Generating a series of sequential moves to permute array
|arrays|permutations|
|time-complexity|arrays|permutations|
|algorithms|time-complexity|arrays|permutations|
Producing "moves" to permute one array to another
**Problem** A time based followship is defined as a person changing to a new job, and there is an existing employee there in the new company whom he used to work together. In this case, the old guy gets 1 ***follow***. **Challenge** I wrote some simulation code, but the complexity is quadratic and already tak...
**Problem** A time based followship is defined as a person changing to a new job, and there is an existing employee there in the new company whom he used to work together. In this case, the old guy gets 1 ***follow***. **Challenge** I wrote some simulation code, but the complexity is quadratic and already tak...
I am studying theoretical computer science using Ayala's book "Fundamentos da Programação Lógica e Funcional" (the book is written in Portuguese), but the part I am studying right now is based on Lloyd's book "Foundations of Logic Programming". I am currently in the part about definite programs, trying to solve the...
Logic Programming - A definite program for the theory of groups
|group-theory|logic-programming|
I am not sure it's the most elegant approach, but you can use a predicate symbol for equality. Let's denote this predicate symbol by $eq$. A definite program for the task would contain the following 3 definite program clauses for the 3 axioms: > $eq(x \cdot (y \cdot z), (x \cdot y) \cdot z) \leftarrow $ > > $eq(x...
null
I have 2 arrays, **A** and **B**, which each contain **N** of the same elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one eleme...
{"Voters":[{"Id":755,"DisplayName":"D.W."}]}
I have 2 arrays, **A** and **B**, which each contain **N** of the same elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one eleme...
I have 2 arrays, **A** and **B**, which each contain **N** of the same elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one eleme...
I have 2 arrays, **A** and **B**, which each contain **N** of the same elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one eleme...
I have 2 arrays, **A** and **B**, which each contain **N** of the same elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one eleme...
I have 2 arrays, **A** and **B**, which each contain **N** of the same elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one eleme...
Here is a pragmatic approach that is quadratic in principle but might be good enough in practice, depending patterns of employee movement from company to company. For each employee, enumerate all pairs of two companies that this employee has worked for. Build up a dict that maps from a pair of companies to the list...
- Build a map between each value and its index for list B. - Repeat until finished. - Find index of value of first element of list A. - Swap position 1 and the indexed position within list A. - If A[1] = B[1], work with 2 instead of 1 (etc. for 3, 4, …).
I have 2 arrays, **A** and **B**, which each contain **N** of the same elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one eleme...
Consider a special case of the [knapsack problem][1] in which all weights are integers, and the number of different weights is fixed. For example, the weight of every item is either 1k or 2k or 4k. There is one unit of each item. If there are $n$ items, and the number of different weights is $d$, then the problem ca...
[This](https://cs.stackexchange.com/questions/86813) question deals with how to find the maximum matching in a tree. I understood the answers, but for one part. >Choose a root arbitrarily. For each subtree, calculate the maximum matching within the subtree, as well the maximum matching within the subtree that doesn't ...
Choosing root for maximum matching in tree
|graphs|trees|matching|
I apologize in advance for asking this, since I'm sure this site is flooded by amateurs like me asking about P and NP. If there's a better platform to ask this on, please let me know, but this question has always bothered me. Suppose you have a perfect binary tree of depth $d$. Each node contains a boolean. Of the $...
Why is this a flawed counterexample to P=NP?
|p-vs-np|
null
The problem is that representing the tree takes exponential space, so the input length is $2^d$. Therefore a running time of $O(2^d)$ is actually polynomial in the length of the input: we care about whether the algorithm's running time is polynomial in the length of the input, in bits, not some other parameter. In ot...
You can prove this by a case analysis. Consider any optimal solution. Either the root is matched to another vertex, or it is unmatched. If it is matched to some other vertex, consider all possible cases for what the root might be matched to. Make sure that your dynamic programming algorithm handles all of those cas...
null
I have 2 arrays, **A** and **B**, which each contain **N** of the same elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one eleme...
I have 2 arrays, **A** and **B**, which each contain **N** of the same elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one eleme...
I have 2 arrays, **A** and **B**, which each contain the same **N** elements, but in a different order. (A different permutation) There are also no duplicates in **A** and **B**. I'm trying to devise an algorithm which generates a series of moves, which changes **A** into **B**. A move means to move one element ...
I have had a somewhat hard time trying to understand how ChatGPT can "solve" some tasks that cannot be entirely cast as language-model-based rephrasing of textual subsets of the internet directed by a textual query. For example, ChatGPT seems to be able to do calculations, even if not always appropriately used, exec...
Does ChatGPT use specific sub-programs
|machine-learning|neural-networks|natural-language-processing|computer-vs-human|
Interesting question. Claim: A finite recursively-enumerable set is decidable. Proof: In fact, a finite set is decidable. Claim: It is computable to find $|A\cap B|$ given two finite sets $A$ and $B$. Proof: List all elements in $A$. For each one of them, check whether it is in $B$. Return the number of a...
null
In a directed graph $G=(V,E)$ we denote a vertex $s\in V$ to be a 'source' if there exists in $G$ a path from $s$ to all other vertices $u \in V$. The problem asks for an efficient algorithm to return the 'source', in case there isnt any, return false. I've been able to come up with a naive approach to his proble...
Checking if there exists a 'source' vertex
|graphs|depth-first-search|topological-ordering|
Can someone help with an example of a function such that $f(m ,n)$: 1. $f(m ,n)$ takes 2 parameters $(m, n); \ m, n \in \mathbb{Z^+}$ 2. The optimal running time to compute is $C(|m|^{|n|})$ in the worst case, where $|n|$ and $|m|$ are the size of $n$ and $m$ respectively. 3. The value of $f(m, n)$ is dependent o...
Example of a function with specified running time
|algorithms|
null
Can someone help with an example of a function such that $f(m ,n)$: 1. $f(m ,n)$ takes 2 parameters $(m, n); \ m, n \in \mathbb{Z^+}$ 2. The optimal running time to compute is $C(|m|^{|n|})$ in the worst case, where $|n|$ and $|m|$ is the size (number of bits) of $n$ and $m$ respectively. 3. The value of $f(m, n)...
[![sfsfswdqwdqwdqwd][1]][1] [1]: https://i.stack.imgur.com/ygmNC.jpg first say: from the start state where I can go with epsilon transitions (include start state itself)? from q1 using epsilon, we can go to 0, 1, 2, 4, 6 after that draw a combined state, next: give it an input, and consider each state alone, e...
Can someone help with an example of a function such that $f(m ,n)$: 1. $f(m ,n)$ takes 2 parameters $(m, n); \ m, n \in \mathbb{Z^+}$ 2. The optimal running time to compute is $C(|m|^{|n|})$ in the worst case, where $|n|$ and $|m|$ is the size (number of bits) of $n$ and $m$ respectively. 3. The value of $f(m, n)...
[![sfsfswdqwdqwdqwd][1]][1] [1]: https://i.stack.imgur.com/ygmNC.jpg first say: from the start state where I can go with epsilon transitions (include start state itself)? from q1 using epsilon, we can go to 0, 1, 2, 4, 6 after that draw a combined state, next: give it an input, and consider each state alone, e...
[![sfsfswdqwdqwdqwd][1]][1] [1]: https://i.stack.imgur.com/ygmNC.jpg to start, ask yourself: from the start state where I can go with epsilon transitions (including start state itself)? from q1 using epsilon, we can go to 0, 1, 2, 4, 6 after that draw a combined state. next: give it an input, and consider each...
Hint: if you find all the _strongly connected components_ in the graph, the _quotient graph_ of the SCCs is a DAG. In this DAG, if there is a meta-node that can reach all the other meta-nodes, you have your answer. Check out the Wikipedia article on [strongly connected components](https://en.wikipedia.org/wiki/Stro...
{"Voters":[{"Id":-1,"DisplayName":"Community"}]}
*(Diestel, Graph Theory)* **Corollary 1.5.2:** Every tree has an enumeration of the vertices $\{v_1, v_2\ldots v_n\}$ such that each vertex $v_i$, with $i\geq 2$, has a unique neighbour in $\{v_1, v_2\ldots v_{i-1}\}$. I am wondering if there is an efficient algorithm that could produce such an enumeration in $O...
Enumeration of tree vertices such that each vertex has unique neighbor appearing before it
|algorithms|graphs|trees|
null
Pick an arbitrary root. Do a preorder traversal. Now, each vertex has a unique neighbour prior to it in the ordering, namely its parent.
None of the above, I am afraid. There is nothing that distinguishes a PDA for $\Sigma^*$, except that it has an accepting computation for every string. Of course a PDA may have all those properties, just build a deterministic finite state automaton and convert it to a PDA by ignoring the stack. But we can avoid all...
This is known as the [betweenness problem](https://en.wikipedia.org/wiki/Betweenness). It is in NP (you can easily check the correctness of any proposed solution in polynomial time), and is NP-hard.
A plausible candidate is $$f(m,n)=(m,n,H(m,|m|^{|n|}),H(n,|m|^{|n|})),$$ where $H(t,k)=1$ if the Turing machine denoted by $t$ halts in at most $k$ steps, or $H(t,k)=0$ otherwise. I have no proof that the optimal running time is as claimed, but I suspect that it does, and all other criteria are met.
No, your interpretation is not correct. One way to think of GPT-3 is as a predictor: given some words, it tries to predict what words come next. Another way to think of GPT-3 is as a "bullshitter": it tries to predict some words that will superficially sound plausible. It has no deep knowledge or ability to do addit...