instruction
stringlengths
35
29.1k
I was solving some exercises about CFL from past years' homework and faced this question. Question: Given the language $L=\{w \# x^R \ | \ x\ is\ a\ substring\ of\ w\}$, prove/refute if it's regular language. If you proved it's regular then provide NFA and a regular expression that describes it. Otherwise, provide CFG ...
I have an undirected graph where each edge $e=\{u,v\}$ has a positive weight $w_{uv}$ and each vertex $v$ has a positive capacity $c_v$. There are two special vertices: a source vertex $s$ and a destination vertex $d$. A vehicle has $n$ items where item $i$ has a load $\ell_{iv}$ when placed on vertex $v\notin\{s,d\}$....
The question was to construct a DFA which accepts the language $$\{ x \in \{0,1\}^* \mid x\text{ starts with a }0\text{ and has at most one }1\}$$ So I first constructed DFA for '$x$ starts with a $0$' and a DFA for 'has at most one $1$' then I tried getting the product automaton of these, but the quiz says the automat...
Reading through https://developer.apple.com/documentation/swift/array/1688499-sort, it states "Complexity: O(n log n), where n is the length of the collection," but I don't have an intuition for why this exactly this is.
I've faced a question in my homework, I was able to solve it but not as desired. Question: Given the language $L=\{0^n1^{n+1}\ |\ \exists k\in \mathbb{N} :\ 4n+2=6k \}$, Prove that it's a CFL (Note: it can be solved without using CFG or PDA). My Answer: I provided the CFG: $$S\rightarrow 0T11\\T\rightarrow 000T111\ |\ ...
I saw the word "redex" in the context of proramming language theory/semantics in 2018 and now when I was reading a neurosymbolic research paper (machine learning with neural nets + symbolic algorithms). The research paper said: Constructing $I\beta'$ (operator that inverts one step of beta-reductions/function applicat...
I'm looking for simple examples of nondeterministic log-space completeness reductions. In particular I seem unable to construct any nontrivial widget using 2-SAT clauses, which is known to be NL-complete.
I believe that if P = NP, then that would imply EXP = NEXP (because of the padding argument), and then EXP^P = NEXP^NP (we could replace EXP with NEXP since they are equal, and replace P with NP, since they are equal). Is there any error in this affirmation? I am not sure if there is anything that I am not considering ...
So I am doing an exercise in which there are $n$ people who are either knight or rogue, more than $\frac{n}{2}$ are knights. You are a princess and would like to marry a knight and do not want to accidentally marry a rogue. You can select any pair of the $n$ people to make them point out each other's identity. The knig...
I’ve read the Wikipedia article and know it’s basic function but I don’t understand what it physically is. Like, is an api a text file that the main program reads from and you are just putting your text in that file to be read or is it an other program that just puts what you type directly into the main program? I don’...
Let $G=(V,E)$ be a directed graph with possibly negative edge weights. Given a destination $t$. Suppose that we have already known $d_v$, the shortest path weight from $v$ to $t$. If I'd like to compute the shortest path weight from $v$ to another destination $t'$ instead (call it $d'_v$), how to use $d_v$ to calculate...
I was reading a book and there is a part in which they use this grammar $$ X \rightarrow xY $$ $$ Y \rightarrow yZ $$ $$ Z \rightarrow z$$ $$ Z \rightarrow \lambda $$ and other times they use this other one $$ X \rightarrow xyz $$ $$ X \rightarrow x $$ It mentions that both are equivalent but I don't understand why it ...
If A is in the class P, B is NP-complete, and C is not in the class NP. And A reduces to B and B reduces to C. Which statements are true? A is in the class NP. A reduces to C. If S is a candidate solution to an instance I for problem A, we can check in polynomial time if S is indeed a solution. C is NP-hard. I think ...
I'm studying Algorithms by Jeff Erickson. Consider this exercise from that textbook: Prove that the following algorithm, modeled after quicksort, uniformly permutes its input array, meaning each of the $n!$ possible output permutations is equally likely. [Hint: $ \binom{n}{k} =\frac{n!}{k!(n-k)!} $] $\quad\text{Quic...
I have 2 sets of atmost 25000 4-tuples. Currently, I am storing them as 2 lists of 4-tuples A and B. I have to perform the following computation for each of the combinations of A and B. min(B[j][0], B[j][2])<=A[i][0] and max(B[j][0], B[j][2])>=A[i][0] and B[j][1]>=min(A[i][1], A[i][3]) and B[j][1]<=max(A[i][1],A[i][3])...
I have a fully connected neural network that consists of 3 inputs + bias, 4 neuron hidden layer, and 2 layer output, I am using the sigmoid activation function on the hidden layer only and use the backpropagation algorithm. I am using the following training data: [ 0.50, 1.00, 0.75, 1], [ 1.00, 0.50, 0.75, 1], [ 1.00...
i have the following question which I'm having some hard time to solve: prove: if every two Languages $A$ and $B$ that have a polynomial reduction ($A$ to $B$) also have a log space reduction ($A$ to $B$), then $\mathsf{P}=\mathsf{L}$.
If every 2 languages $A,B$ that have Polynomial reduction $A<_pB$ have LOG SPACE reduction $A<_LB$, does $\mathsf{L}=\mathsf{P}$?
I recently thought of this problem, and I think it's very interesting. We are given an array of $N$ numbers, but we don't know the numbers themselves, only a possible integer range for each number. For instance, if $N = 3$, we could know that the first number is in the range $[1, 1000]$, the second number is in the ran...
From the point of view of writing pseudocode, I have never seen any algorithm making use of pointers except when writing algorithms about data-structure (like writing algorithms for linked list involve moving arrows which in essentially a pointers operation). So my hypothesis is that any use of pointers in pseudocode i...
I believe using big o notation that Bellman-Ford is to be expected to be faster on sparse graphs and dijkstra's should be expected to be faster on dense graphs, but in practice dijkstra's is always faster and Bellman-Ford is only used when negative weight cycles are present. Is that the case?
I am studying system design for distributed systems and in this page (https://github.com/donnemartin/system-design-primer), one of the following advantages was mentioned for federation for databases was: Smaller databases result in more data that can fit in memory, which in turn results in more cache hits due to impro...
Is there a way to compute the number of partitions such that each set in the partition has a cardinality lower or equal to two? If yes, is there also an efficient algorithm to compute these partitions?
I am wondering about the difference between an abstract data type (ADT) and a computation model. As I understand them: A computation model defines the basic unit of computation, that is, what can be done in a unit of time. The RAM model, for example, defines the basic data unit (the integer), their organization (the m...
I am interested in the complexity theoretic equivalences of prime number factorization. My interest stems from prime number factorization being one of the few candidates for NPI. I am especially interested to learn wether there are some not initially obvious reductions. Any possible reduction type (Karp, Turing, ...) w...
I am currently reading through the paper "Computer-Generated Residential Building Layouts" by Paul Merrell, Eric Schkufza and Vladlen Koltun. In this paper, they create and optimize floorplans by exploring the space of possible floorplans through a set of modifying operations. One of these operations is the sliding of ...
Let A and B be two sets of unordered 3D points. Set B is obtained by applying the same transformation to every point in set A. How do I match points from A to points of B? Is there a standard algorithm? To make things worse, the actual sets might have slightly different sizes, and the positions might be slightly shifte...
I'm trying to prove that L = {$0^n1^m0^n | m,n >= 1$} in NOT regular but I am struggling with the demostration process. I know the conditions are that: $|y| > 0$; $'y'$ can't be empty $|xy| <= p$(word/string length) for all $i$ > 0, $xy^iz$ must be in L Lets choose the string $s = 0^p10^p$. The first condition states...
What are the six mistakes that were made in the configuration of the following network? I could only find 3. Since the subnet on the left has 192.168.10.33 as HostMin and 192.168.10.38 as HostMax, Host A4 and Host A5 cannot be in this subnet. Subnet A should also have the IP 292.168.10.0 because it's a network addre...
Recently, I've written a draft article on the computational power of Petri-nets. An understanding of Petri-nets isn't really essential to answering this question, but I'll still note that the conclusions were that if Petri-nets were allowed to be infinitely large, then it is possible to simulate any Turing machine with...
Boolean satisfiability problem (SAT) is NP-complete by Cook–Levin theorem. (wiki) Horn-satisfiability – given a set of Horn clauses, is there a variable assignment which satisfies them? This is P's version of the boolean satisfiability problem. It is also P-complete. P-complete problems lie outside NC and so cannot be ...
S is a the set of binary strings in Shortlex order: [0,1,00,01,10,11,...] I want to encode / decode natural numbers with the following scheme: Encoding N: For natural number N return the binary string with index N in S: Code(N)=S[N] Decoding Code: Return the index of the binary string Code in S: Decode(11)=5 Can you pl...
This is a question by my professor Z. Luria in my Computability course. My first approach was to try and prove it by contradiction, assuming that EXIST is decidable and using the algorithm that decides EXIST to decide HALT which leads to contradiction - but I didn't managed to do so. Then I tried to prove by Reduction ...
I was going through some texts and shared PPT of my university and I found the term "traffic controller" in the Process management section under the functions of an Operating System. The PPT says, "OS maintains the track of the processor and the status of the process; the software that does this is called the traffic c...
model: gambler ruin theorem. A gambler has $i$ coins initially, in every step, he wins a coin with probability $p$, and loses a coin with probability $1-p$. The expected time that he loses all his coins or wins $n-i$ coins (thus he has $n$ coins totally) is as following: $$E(i)=-\frac{n}{1-2p}\frac{(\frac{1-p}{p})^i-1}...
I was re-reviewing a somewhat upvoted answer of mine where I attempt to explain the differences between pure, impure, deterministic, non-deterministic, and idempotent functions. In my answer I use .NET's or Java's List<T>.Add( T ) as an example of an impure deterministic function. I also use Random.Next() as an example...
I want to generate 2 sets from N elements. Sets must be unique in the combination of sets Numbers must not repeat across the 2 sets Sets can have any amount of numbers, but must not be empty Ordering doesn't matter Examples for 3, 4 and 5 for 1 2 3 (1) (2 3) (2) (1 3) (3) (1 2) for 1 2 3 4 (1) (2 3 4) (2) (1 3 4...
In CLRS' Introduction to Algorithms: (1) In 22.1 Representations of graphs The adjacency-list representation of a graph G = (V, E) consists of an array Adj of |V| lists, one for each vertex in V. For each u in V , the adjacency list Adj[u] contains all the vertices v such that there is an edge (u,v) in E. That is, Adj...
Intuitively, it seems that if a programming language is Turing-complete, then it must contain a program that's an infinite loop. I have formalized this below: Conjecture. There does not exist a set $S$ of Turing machines such that all three of these properties hold: $S$ is decidable. (That is, there exists a Turing m...
Context-Sensitive Grammar is defined as a 4 tuple G = (V, Σ, R, S) where: V is a finite set of elements known as variables. Σ is a finite set of elements known as terminals V ∩ Σ = Null (empty set) S is an element of V and is known as the start variable. R is a fine set of elements known as Production Rules. Each rule ...
I prepare for entrance exam and try to practice some hard problems. The following nice problem is problem 1(c) of this problem set. Suppose we are given a two-dimensional array $A[1...m][1...n]$ in which every row $A[i][]$ is sorted, and an integer $k$. Describe an algorithm to find the $k$-th smallest element in $A$ ...
I have n number of files on a ScrollView. Every time a file is added, x/y coordinates are stored in an array. The user is able to drag and drop the files anywhere they like. Overlapping files (e.g. distance between center less than 100 points) will form a stack, see screenshot. At the moment, my implementation is not g...
I am reading Introduction to the Theory of Computation by Michael Sipser and I am in chapter 5. It says here that the Post Correspondence Problem is undecidable, but thinking about it, given a collection, if someone permutes using the algorithm: try every single permutation of the collection: if it is a match retur...
On my backend I use a 3rd party service which provides currency exchange rates. I use this rate for the funds conversion within the customer’s accounts. As far as this rate affects customers’ money, I have to be sure that it’s legit. Let’s pretend a 3rd party service is experiencing a glitch and returns 100x times bigg...
I've stumbled across this problem on CSES https://cses.fi/345/task/E/ and was wondering is it somehow reducible to 2-SAT with given constraints? So, the problem states that you need to solve a 3-SAT given in a CNF form, albeit a special case, where: Each clause has exactly 3 distinct variables Each variable occurs at ...
I stumbled on the following computing issue and would like some help to solve it. Given a vector of size n and filled with 1's, give all the elements obtained by the sum of them. Ignore combinatorial options like [m, n] and [n, m] Example: n = 5, v = [1,1,1,1,1]: The possibilities are below: [2, 1, 1, 1], [2, 2, 1] [3,...
I'm trying to calculate the complexity of the saxpy method, which aims to solve the equation $y=\alpha*x+y$, where $x$ and $y$, are vectors and $\alpha$ is a scalar. There two versions of the algorithm, with loop unrolling and without, the version without (as seeing below), I've manage to find the complexity, been $2n$...
I'm trying to construct an unrestricted grammar for strings of the form XWX, where W is the reverse of X, over the alphabet {a, b}. I think I can apply similar logic to the a^nb^nc^n solution (below), but am running into issues. S -> S -> aSBC CB -> BC aB -> ab bB -> bb bC -> bc cC -> cc I've thought about it a lot, ...
Let's say I have a semantic segmentation model that distinguishes between 100 classes of objects, and the speed of running the model is 1 image per second. Now let's say I take the same model architecture (with untrained parameters), and train it to distinguish between just 2 classes of objects. Is there any theoretic...
The problem goes like this: Write a function, nonAdjacentSum, that takes in an array of numbers as an argument. The function should return the maximum sum of non-adjacent elements in the array. There is no limit on how many elements can be taken into the sum as long as they are not adjacent. I am struggling to unders...
Suppose we have an NP-complete problem A, an NP-hard problem B, and a polynomial time reduction from A to B exists. Do we have a polynomial time reduction from B to A as a result?
I'm trying to solve a recurrence problem using substitution method: Given the following recurrence equation: $ T(n) = \begin{cases} 3 &n = 0 \\ 3T(\frac{n}{5}) + T(\frac{n}{6}) + n&n > 0 \end{cases} $ provide a tight asymptotic bound for the solution I've been trying to understand how the recursion tree is m...
I am reading Sipser's Introduction to the Theory of Computation, and encountered two propositions: $A = \{0^k1^k \mid k ≥ 0\}$ is nonregular language (pumping lemma). Any language that can be decided in $o(n\log n)$ time on a single-tape Turing machine is regular. The author shows how to construct a Turing machine th...
Given the following code: int p = 5 , q=2; int f( int b, int c){ b = 2 * c; c = 3 + p; return b + c ;} print f(p,q); print p; print q; I have found that the output values using call by value are: f(p,q)=12 p=5 q=2 And as far as i know also the output using call by reference in this example ,gives the same values.Am I r...
Consider the following example problem. Given a graph with edge weights, find a matching that maximizes the number of matched vertices, and subject to this, maximizes the total weight. This problem can be reduced to simple maximum-weight matching as follows: Construct a graph in which the weight of each edge $e$ is $(...
I apologize if this question is a duplicate as i cannot find a similar question in this community forum, please comment the post in which this may be a duplicate of so i can update this post :) Im a computer science student currently taking on Introduction to computer science, we recently learned about Big O and its fo...
Prove or refute. Let $ L = \{ w \in \Sigma ^* :\ |w| \geq 1000 \} $. Let $ P $ be a non-regular language. Then $ L \cup P $ is regular necessarily. I think it is true, but I don't have any idea about how to prove is formally. It is just that when the word becomes greater than 1000 it will be inside the language. Can ...
I am now learning about automation and I am wondering if personal computers use NFAs or DFAs. I believe it uses a DFA since when we are clicking on something it is in a way determined what will happen. Any thoughts? :)
I am envisioning a priority queue that is a bit strange. It represents wanting to do a depth-first left-to-right walk of a tree, but allowing for parallel workers where there can be time between assigning a node to a worker and getting new child nodes back to explore, leaving the depth-first left-to-right property as a...
Yet another question from an exe. in the Computability class taught by Z. Luria - I'm not really sure how to prove the undecidability, moreover, didn't a finite language always decidable? I mean we can build a machine $M$ that checks all the possibilities (In this case ${0, 1, 00, 01, 10, 11}$), That was my approach fo...
This question is part of the undecidable lecture by Jeff Erickson. $$\{\langle M\rangle\mid M \text{ accepts at least one string }w\text{ in space }|w|^2\}$$ We should prove that this language is undecidable. So what i tried is to create a new TM $M'$ where $M'$ moves $|w|^2$ steps to the right and than tries to accept...
I am working on a project for my CS subject and the topic is Video compression. After theoretical aspect, I want to implement and describe one algorithm that does video compression. I am not sure if these type of questions are allowed here but: what would be the best (the easiest) algorithm to implement for an entry le...
The naive approach, which is the first thing that came to my mind, is to use some sort of backtracking to generate all subsets of the given set of strings and then to find the subset with the maximum number of strings that satisfies the condition. But I don`t believe it is ok, because for large numbers of strings the e...
Given a directed graph $G=(V,E)$ with positive weight function $w$, source $s$, destination $t$ and a nonnegative integer $\ell$, we want to find shortest path $\pi$ from $s$ to $t$ such that $\pi$ contains at most $\ell$ edges. Let $d_{u,v}^\ell$ be the length of the shortest path between $u$ and $v$ with at most $\e...
Below is a problem I made up and my solution to it. Problem: Given the following recurrence relationship, find $\Theta(T(n))$. $$ T(n) = T\left( \dfrac{n}{2}\right) + n^2 $$ Answer: To solve this problem, I use the Master's Theorem. I am using this link as reference: Wikipedia Article \begin{align*} a &= 1 \\ b &= 2 ...
The problem that I currently went through is kind of text justification problem. The problem is given that there is a paragraph and a some blank lines. We want to print this paragraph neatly on the number of lines that hold a maximum of M characters each. So, if the paragraph is "Roses are red and sky is blue" and we w...
I'm trying to figure out what is a straightforward algorithm. The following pseudocode comes from section 4.2 of "Introduction to Algorithms, 3rd Edition By Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein" Is it a straightforward algorithm? Does a straightforward algorithm refer to the algo...
I know that the pumping lemma is not powerful enough to prove a language is not context-free, but I don't understand how to show it. I have the same question as this one Show that the Pumping Lemma for CFLs is not powerful enough to prove that the language L = {aibjck |i ≠j ≠ k ≠ i } is not context free, but I couldn't...
https://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees says A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes at the last level h.[18] An alternative defi...
Define $$\text{SQE}=\{S\ |\ S\ \text{is a system of quadratic equations with real solutions}\}$$ and $$\text{VC}=\{G\ |\ G\ \text{is a simple undirected graph with a vertex cover}\ \leq k\}$$ I am trying to prove that SQE is NP-hard via the reduction $VC\leq_P SQE$. My attempt: Given a $G=(V,E)$, we want to construct s...
Initial collection A = [1,2,3] should provide such combinations: {(1, 2), (1, 3), (2, 3)} I want to pop the first combination (1, 2), so after this I can pop only from {(1, 3), (2, 3)} Collection A can grow in size. How example: A = [1,2,3] : {(1, 2), (1, 3), (2, 3)} pop (1, 2) from A combinations -> A = [1,2,3] : {(1...
Recently I've stumbled upon a strange graph problem. Here is a brief description. Given $n\times m$ matrix with $2n + 1$ rows such that each row contains $2m + 1$ characters "+", "-", "|", "." First, last row, and first, last column are the borders of the maze. Even coordinates, e.g. (0, 0), (0, 2), are filled with "...
I am currently storing a $d$-dimensional polytope as a list of $d$-dimensional points. In order to implement an algorithm, I need to find intersections between my polytope and $d$ equations, of the form: \begin{align} x_1 &= c_1 \\ x_2 &= c_2 \\ &\dots \\ x_d &= c_d \\ \end{align} where $x_i$ is a coord...
In section 1.2.11.2 of Donald Knuth's first volume of TAOCP, he gives an exercise at the end to prove that $g(n) = \Omega (f(n)) \iff f(n) = O(g(n))$ (exercise 13). His solution is simply: "we may take $L = \frac{1}{M}$ in the definitions of $O$ and $\Omega$." However, earlier in the book he states, "Every appearance o...
I'm trying to make a Turing machine which accepts $ww^R$, for example $w = aababbabaa$ and I'm unsure as to how to make this work. Below is an attempt for such Turing machine, but it gets stuck when the second to last b becomes B and the very last a becomes A.
Suppose a computer solves a coupled differential equations (with given boundary conditions) of which each equation deals with $2^n \times 2^n$ size of matrices as solutions. My question is Does time-scaling for typical algorithm we use in Python packages (e.g. Scipy) grow exponentially with $n$? This sounds pretty obv...
I'm looking at [1] that describes a GPU parallel radix sort algorithm. They describe multiple optimizations but in section 3 where the whole algorithm is described some things elude me. First, the counting step is done for $n$ bits by $m$ work groups using as many work items (SIMD lanes) as possible for each work group...
While studying I've encountered this question written above. I am familiar to the closure properties of CFL, and even know that $$L=\{a^{j^2}|j\geqslant 0\}$$ ($a$ to the power of ($j$ to the power of $2$))is one that answers the question, but I don't know how to prove that. If anyone could explain it to me, it would b...
Prove that the following predicate is not computable: $P_e(n) = \begin{cases} 1 & \textrm{if } \phi_n(n) = e \\ 0 & \textrm{otherwise} \end{cases}$ Could someone explain how to approach this problem and what theorems could be useful here?
I've tried to use the step counting method to get the worst-case time complexity for binary search. But I seem to mess it up, as my final result would be O(n) and not O(log(n)). My implementation: fn binarySearch(array:[i32;20],target:i32) -> isize{ let mut min = 0; //c let mut max = array.len(); //c let mu...
If we have only one submitted process and we are using RR CPU scheduling algorithm. Assume that the CPU burst time for this process is 10 ms and the time quantum is 2 , then there will be multiple context switches ? OR the process will continue running on the CPU ? The book "Operating system concepts" 9th edition , p...
I have been given the following problem and was wondering if my solution is correct: Say that a variable $A$ in CFG $G$ is necessary if it appears in every derivation of some string $w$ where $w$ is in $G$. Let $$\text{NECESSARY}_{\text{CFG}} =\{\langle G,A\rangle \mid G\text{ is a CFG and }A\text{ is a necessary varia...
EVG is defined as EVC = { <G,m,k>| G is an undirected graph and there is as et of m edges in G that are covered by at most k nodes} If EVG was decidable in polynomial time how could we find the list of m vertices and k nodes that satisfy it in polynomial time? Here's the best solution I found: Run EVC repeatedly with k...
I'm trying to get my hands on a set of these books, and it seems the most recent printing was in 2011. It's currently out of print, and going for crazy money. Meanwhile older editions from the 70s are available on eBay for much cheaper. Is there any reason to hold out for an affordable copy of the newer edition? Or are...
I want to write a compression algorithm for a specific use case that I have. I have many arrays which are for the most part, very similar. Each value in the array is an integer and is related to the corresponding value in the previous array. These arrays have a correlation coefficient of around 0.8 and they will be sto...
Find an algorithm that decides, given 2 regular expressions $E_1$ and $E_2$ and a non-negative integer $k$, whether $|L(E_1) \backslash L(E_2)| = k$. I know that regular expressions are closed under set difference so I can find a regular expression equivalent to the one above, and then convert it to a DFA and then brea...
Is a thread's context stored in the process's PCB, or is a new PCB created for the thread?
I am learning data structures and algorithms currently, and want to understand how the following codes received their O-notations. Code example #1: for (int i = N; i > 1; i--) { for (int j = 0; j < i; j++) { for (int k = 1; k < N; k = k*2) { doSomething(i, j, k); } } } The O-notation for how many t...
Let $\Sigma = \{a, b\}$ I need to find a regular expression for this language: The language where the number of $a$'s and $b$'s is equal and for every prefix of a word the absolute value of the difference between the number of $a$'s and $b$'s isn't greater than 2 But I can't seem to find an expression for this langua...
I'm working with logic formulas of the form '0 & 2 | 0 & 3'. I was wondering if anyone knew of an algorithm that would take in such a formula, detect existing disjunctive relationships, and return a simplified version. For instance, in this case, the algorithm should return '0 & (2|3)'. Ideally, the algorithm should be...
Consider the idea of an extended non-deterministic automation, where transitions can be labelled by regular expressions and not simply by symbols of the input alphabet or $\epsilon$. Such an automaton would work in the obvious way: if there is a transition from state $q$ to state $q′$ labelled with a regular expression...
I have an undirected fully-connected weighted graph of $n$ nodes, where $n=m\times m$. I want to visualize this graph on an $m$ x $m$ 2D grid. My goal is to place nodes connected with edges of higher weights together so that the placement maximizes the sum of weights of edges between neighboring nodes. For example, if ...
So I have a recursive algorithm which sums up the numbers from 1 to n plus one (hence the return 1): public static int S(int n) { if(n < 0) { return 1; } else { return n + S(n-1); } } This algorithm has a time complexity of O(n). Is it possible to derive an algorithm which produces the ...
I've been thinking recently about the Golden State Killer case, in which a crime was solved by comparing a killer's DNA sample with known samples in a public genetic database. The cousin of the killer was in the database, leading to an arrest. I wanted to try to understand/formalize this process a bit further, but ran ...
Context: When trying to tame real-world datasets that contain outliers and noise, the interquartile mean is a handy tool: you sort the data, throw away the top and bottom 25% of the data and take the mean of what's left. (Of course, you can choose other partitioning than top and bottom 25%.) Which led me to wonder: is...
Wikipedia has an explanation for the viterbi algorithm, in particular it describes the following summary of the inputs: What is the difference between O and Y? Also I am trying to understand what the output is
So I am studying apporiximation algorithms for TSP problem and there is a step that I don't get. Essentially trying to solve TSP means we are looking for a minimum cost Hamiltonian path. The well-known 2-approximate algorithm computes the MST , transverses it with DFS while noting down the vertices . I don't get how fr...
Section 4.3 of "Introduction to Algorithms, 3rd Edition By Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein" uses the following recurrence as an example to illustrate the substitution method. $T(n) = 2T(\lfloor{n/2}\rfloor)+n \tag{4.19}$ That section says Let us assume, for the sake of argum...
Let $L$ be any context-free language. Is the set of all palindromes that are elements of $L$ also context-free? I know that the intersection of context free languages isn't guaranteed to be context free, so I can't apply that here. I also thought of maybe using the fact that $\{0^{n}1^{n}0^{n}|n ≥ 0\}$ is not context f...
Suppose $L \subseteq \mathbb N$ such that, for the purpose of Turing machine computation, numbers in $L$ are represented by strings over the alphabet $\{0, 1\}$ in the standard binary notation. Prove that $L$ is decidable if and only if $L$ is finite or $L$ is the image of some strictly increasing computable function $...