instruction
stringlengths
35
29.1k
I have been reading up on the Count Sketch algorithm, and I stumpled upon the Count Sketh algorithm explained in section 5 of https://www.cs.dartmouth.edu/~ac/Teach/data-streams-lecnotes.pdf. Then, I tried to solve some of the exercises. However, exercise 5-3 is causing me some problems. If we let $\hat{f}_a$ denote th...
Given an array of $n$ elements, containing values in the range $[1, n-1] $ (assume $ n > 1 $) this implies there is at least one repeated element. The problem is to get one of the repeated values in linear time on average. My first try was to do something with the Partition scheme from Quicksort. However, I don't know ...
In Dragon book for compiler design there is this example of SDT in Example 5.16 $L\rightarrow En$ $E\rightarrow \{ print (' +') ; \} \space E_1 + T$ $E\rightarrow T$ $T\rightarrow \{ print (' *' ) ; \} \space T_1 * F$ $T\rightarrow F$ $F\rightarrow ( E )$ $F\rightarrow digit \space \{ print ( digit . lexval) ; \}$ ...
Today I read the following text in CLRS: We say that an algorithm solves a concrete problem in time $O(T(n))$ if, when it is provided a problem instance $i$ of length $n = |i|$, the algorithm can produce the solution in $O(T(n))$ time It is ambiguous for me, because if we consider a problem in which a number $n$ is g...
I was trying to build up this regex but I am having huge expressions but nothing generates the given regex. I tried to break up the regex as $0$ multiple of five times and odd $1$'s $0$ multiple of five times and even $1$'s Bu this doesn't help me. The regex I Found was $(00)^*1(00)^*1(00)^*1(00)^*1(00)^*$. But in ...
We have a list of strings with the same length. Each string only contains a, b and c.(For instance : aabcc) The program gets a string and returns true if the two strings(input and the list of strings) only differ by one character. A = {cacab cbabc} cbbaa : False cbaac : True My first thought was to solve it with brute...
I have generated the CFG of $a^n b^m c^p$ where $m = n+p+2$: $S \rightarrow ASC \mid \varepsilon$ $A \rightarrow aAb \mid \varepsilon$ $C \rightarrow bCc \mid \varepsilon$ I have been trying $a^n b^m c^p$ where $n=m+p+2$ but cannot figure out how to represent $n=m+p+2$. Any hint would really be appreciated.
I'm working on a video game and I'm struggling with the math behind one of the enemies. The enemy is a grenade launcher mounted on a vertical rail, which can slide up and down, and lob a grenade at any angle with any amount of force. The grenade's path will be a parabola which must hit the player, but there are line ...
I'm aware that an algorithm that compresses every input doesn't exist (by the pigeonhole principle), however I tend to think about the problem sometimes and I came up with a (flawed, but why?) idea: Suppose a file, or whatever it is that will be compressed. It can be represented with a number (we can actually invert th...
I have a very silly question, when data is transferred from the RAM to the CPU is this data transferred "copies" of the original data stored inside the RAM?
I came across the following line in the book ‘Deep Learning (Ian Goodfellow) 10.2.1, pg 374; The disadvantage of strict teacher forcing arises if the network is going to be later used in an open-loop mode, with the network outputs fed back as input. Please explain the difference between these modes.
I am going through a fairly non-rigorous textbook called 'Cracking the code interview' and I am bothered by this terminology called "unit of work". It says in the textbook that certain operations take constant work, where as others take variable amount of time. For example, adding/subtracting/multiplying/dividing two n...
I'm not sure if CS SE is the right place for this question, but since originally this question was in the CS area (and I translated it to a mathematical form), I will post it here. I am given two parameters $m\in\mathbb{N}$ and $\frac{1}{2}< p\le 1$, and I want to find the maximal value $k\in \mathbb{N}$, such that the...
This exercise is taken from Goldreich's textbook of "Computational Complexity - A Conceptual Perspective", first ed., p.140. Exercise 4.3: Referring to any reasonable model of computation and assuming that the input length is not given explicitly, prove that any algorithm that has sub-linear time complexity actually h...
I need to prove that the following language is not recursively enumerable, while its complement is recursively enumerable: $L := \{w \in \{0,1\}^* |$ TM $M$ with $w = \langle $ M $\rangle$ does not accept any input $\}$. Should I use a reduction from the halting problem in this case?
I don't have a CS degree but I have recently taken up studying algorithms very seriously. I have been studying greedy and dynamic programming for days and I come across the below definition a lot, seems they all come from the same source, but I do not understand what it means, it is one of the vaguest definitions I hav...
I was wondering about some questions related to the Halting problem. I might have not understood all the assumptions in it fully. Would you kindly help me, please? I understand that the construction in the proof leads to a contradiction. My thoughts are: If one runs these theoretical programs in the real world, I woul...
we know that $n \geq \log{n}$ however I understand that $(\log n)^{\log n}$ grows faster than $n$. I have been trying to prove this however I can't seem to figure it out.
A part of ORCA local avoidance collision is calculating a linear program with an incremental approach - adding the constraints one by one. If the problem is determined to be infeasible, the constraints $g_i(x) \leq 0$ are relaxed, and we could instead solve the problem of $\min_{x,d} d$ $g_i(x) -d \leq 0, \forall i$ Ho...
Consider a uniprocessor system with four processes having the following arrival and burst times: (i) Calculate the average waiting time and also the average turnaround time if shortest (remaining) job first (SJF) scheduling policy is used with pre-emption. Assume that the context switching time is zero. Note that in S...
I have this question which is asking for the worst case time complexity for a balanced binary search tree, assume the nodes are labeled as integers and we consider a range of [nodex, nodey], nodex<=nodey. And also given that the range has exactly k nodes, k can be at most n ie. total number of nodes. The question asks...
Given a simple graph $G=(V,E)$ s.t. $2\mid \omega(G)$, Show that $\exists S\subseteq V\text{ s.t. } f_G(S)=f_G(V\setminus S)$ where $f_G(A)$ is the clique number of the sub-graph of $G$ induced by vertex set $A$. I'm have trouble proving this property of clique number. Several approaches have been tried but none lead...
It is known that for every $\varepsilon>0$ there is an appropriate neural network architecture, such that one can approximate any continuous function $f:[0,1]^n\to[0,1]^m$ by the neural network output $\hat{f}(\bullet;w):[0,1]^n\to[0,1]^m$ as: $$ \|f(x)-\hat{f}(x;w)\|\leq \varepsilon, \forall x\in[0,1]^n \quad \quad \q...
Because of the existence of free variables in lambda calculus, the evaluation of open terms (at least as outlined here) is more complicated relative to the evaluation of closed terms since the evaluator must ensure that the beta-reduction step uses capture-avoiding substitution, i.e., that the variables it substitutes ...
I am doing Shai Simonson's course on Theory of computation. I am not able to understand part b of one of its problem sets. a. Prove that languages of form $0^{mx+b}$, where m and b are positive integer constants and x ranges from 0 to infinite, is regular. b. Give an example of a regular set over the alphabet {0} wh...
Minimum Cost Maximum Flow algorithms have been known to provide an optimal flow routing for network flow problems in satisfactory runtime. Some of the algorithms for solving a min-cost max-flow problems that I'm aware of include : Cycle cancelling (reff) Successive shortest path Relaxation (reff) Cost scaling (reff) ...
It always has been bugging me that we (humans) know pretty easily when most programs we write halt or not, but the halting problem is still undecidable. I have just thought of a variant approximation-like extension to this problem, that tries to "maximize" the correct answers an algorithm can make on this problem. Form...
3SAT with the additional condition that exactly 1 or 3 literals must evaluate to 1.
I'm reading a book CLR via C# which says how Windows does asynchronous I/O: To read data from the file, ReadAsync internally allocates a Task object to represent the pending completion of the read operation. Then, ReadAsync calls Win32's ReadFile function (#1). ReadFile allocates its IRP (I/O Request Packet) and then...
Suppose there is graph problem $L$ such that the instance $x$ of $L$ is a simple graph with $n$ vertices and $m$ edges. In the Turing machine model, we can encode a graph using $O(n^2)$ cells or $O((m+1)\log n)$ cells. (i.e., $|x| = O(n^2)$ or $|x| = O(m \log n)$). Now I want to study the lower bound and the upper boun...
Is database server really really exist? i mean the server wasn't made by general purpose computer but that database device have their own hardware and architecture. We know that good database server means good in shorting data. So the database server i mean have hardware that only found inside it which general purpose ...
This is the given task: Suppose you are given an arbitrary directed graph G in which each edge is colored either red or blue, along with two special vertices s and t. Describe an algorithm that either computes a walk from s to t such that the pattern of red and blue edges along the walk is a palindrome, or correctly re...
Task: A Hamiltonian path of a graph is a path that visits all nodes of the graph exactly once. The hamiltion path problem (HPP) consists in deciding whether a given graph has such a path. Similarly, the 1/2 hamiltion path problem (1/2-HPP) asks for a path that visits exactly half of the nodes. Show that: $HPP \le_{P} ...
I am learning about regular expression, and trying to describe a regular expression for the language L $\qquad L = \{a^i b^j c^k \mid i+j = k\}$ What is the right approach and how to describe a regular expression like this?
I could not find an answer to the question directly by google. I think this question is rather simple but I am not really sure about it. Any advice is welcomed. Thanks
Let $f$ be a maximization problem. If there is a reduction from SAT to the following problem: "given an integer $c$, decide if there is an $x$ for which $f(x)\geq c$", then $f$ is NP-hard. Suppose there is a reduction from SAT to the following problem: Given an integer $c$, return "yes" if there is an $x$ for which $f...
I'm trying to develop an the algorithm for the problem: The cat-and-mouse game is played by two players, “Cat” and “Mouse,” on an arbitrary undirected graph. At a given point, each player occupies a node of the graph. The players take turns moving to a node adjacent to the one that they currently occupy. A special node...
It is usually assumed that the average time complexity of the linear search, i.e., deciding whether an item $i$ is present in an unordered list $L$ of length $n$ is $O(n)$ (linear). I have read several proofs, usually assuming either: that $i$ and the elements of $L$ take values in an infinite domain, in which case th...
Chlebik and Chlebikova prove that the problem "maximum 3-dimensional matching" is NP-hard to approximate within a multiplicative factor of $95/94$. This means that, unless $P=NP$, there is no polynomial-time algorithm that finds a 3-dimensional matching with at least $(94/95)\cdot OPT$ edges, where $OPT$ is the number ...
I have to show that this language is not context free $\mathcal{L} = \{ \omega \omega^R a^{|\omega|} : \omega \in \{a,b\}^* \} $, where the $R$ corresponds to the reverse. For this I will use the pumping motto for free context languages. I know how it works, but I have problems choosing the correct $ \sigma $, because...
I have to prove or disprove the following identities: $(RS+R)^*RS=(RR^*S)^*$ $(R+S)^*S=(R^*S)^*$ $S(RS+S)^*R=RR^*S(RR^*S)^*$ So what I tried: Not same because LHS cannot generate $\epsilon$ while the RHS can. Not same because LHS can generate $\epsilon$ while the RHS can. Not same because LHS is the set of strings s...
Need to prove $(a + ab)^*a = a(a + ba)^*$ by using regular algebra. Concatenation does not commute. So repeated use of commutativity will fail. I am getting confused about which identity I should use to prove this. What I can interpret is that I just need to change the side of $a$ but the $^*$ must be kept outside. But...
The paper "The Knowledge Complexity of Interactive Proof Systems" uses the language of quadratic nonresidues defined via the following excerpt from page 293 as an example of constructing an interactive proof system. Example 1: Let $Z_m^*$ denote the set of integers between $1$ and $m$ that are relatively prime with $m...
There are implicit versions of some set system problems or matroid problems. A set system is a pair $(U, \mathcal{F})$, where $U$ is a universe of size $n$ and $\mathcal{F}$ is a collection of susbets of $U$. $\mathcal{F}$ may satisfy some properties (e.g. Matroid). We define $\Phi$ is a polynomial-time oralce which de...
We consider the NP-complete $CLIQUE$ problem. Let furthermore $MST^*$ be the minimum spanning tree problem. Assume that $P \ne NP$ and explain whether the following assertions hold: $MST^* \le_{P} CLIQUE$ $CLIQUE \le_{P} MST^*$ Definitions: $\le_{P}$ ... Karp reduction $MST^*$ ... Given is a weighted graph $G$ and ...
I have a query in solving the problem below: An automobile company has two factories. One factory has 400 cars (of a certain model) in stock and the other factory has 300 cars (of the model) in stock. Two customers order this car model. The first customer needs 200 cars, and the second customer needs 300 cars. The cost...
Can somebody help me with this recurrence please? $T(n)=4T(\sqrt{n}/3)+(\log n)^2$
I want to compute the amortize time of a type of dynamic array (inserting such that if i have no place to insert i am multipling the array by (1+a) (a is between 0 to 1). I need to compute the time with the accounting method. The answer is that i need for each insertion a 2 + $1/a$ coins. I can see why the answer is ri...
I have two related questions: What are the ways to prove that a certain problem is in $W[t]$ in the W-hierarchy for parametrized complexity, except using the straight definition of boolean circuits? I mean, is there a similar classification like for the FPT class, that if there exists an algorithm which runs in a cert...
Suppose that $w \in \{0; 1\}^*$ is a binary word. Let's denote the number of $0$-s in $w$ as $\#_0(w)$ and the number of $1$-s in $w$ as $\#_1(w)$. Now suppose that $q \in \mathbb{Q}$ is a positive rational number. Consider the language $L_q \subset \{0; 1\}^*$ of all words $w$, such that for any its prefix $p$ we have...
Assume $P \ne NP$, and $A$ is a problem in $P$ and $B$ is a problem which is $NP-complete$. Are the following assertions valid? $A \le_{P} B$ $B \le_{P} A$ My approach: $B \le_{P} A$ isn't valid, because if $B$ is reducible in poly-time to $A$, so $B$ has to be also in $P$. But thats not possible because $P \ne NP$...
I have to show that if G is an unambiguous CFG, the transformed grammar G' in CNF is also unambiguous. But couldn't come up with something concrete. I could only visualize the case where the grammar G is ambiguous, not necessarily G' will be.
I understand what is derivative-free optimization, and I am thinking a similar problem where the function $f$ we are optimizing is unknown and the only information we can acquire is the derivative. In other words, we can get $(x_1, \nabla f(x_1)), \cdots, (x_n, \nabla f(x_n)$ to optimize the unknown function. I know th...
The context: Consider the following optimization problem. Let $f_1,\dots,f_L:\mathbb{R}\to\mathbb{R}$ arbitrary (continous) functions for $L>1$ and $x_k\in\mathbb{R}$ evolve according to $$ x_{k+1} = f_{\sigma(k)}(x_k), $$ given $x_0$, where $\sigma_k \in\{1,\dots,L\}$. We want to find $\sigma(0),\dots,\sigma(N-1)$ to...
I have a problem where I'm asked to prove that if P is a pushdown automaton, then there exists another pushdown automaton P' with only two symbols in its stack alphabet that accepts the same language as P. I've tried to codify the stack alphabet of P in binary, using the same ammount of symbols for each representation...
Suppose a process does system call, hence it goes to kernel mode, the registers are saved. Now the system call will be running in process' allocated kernel stack. Can there be a context switch when a system call is processed? Is really the system call allocated process' kernel stack? If context switch is possible, thi...
Let $L\subseteq \Sigma^*$ such that $\{\epsilon\}\not\in L$. Then for any $S\subseteq \Sigma^*, S=SL\implies S=\emptyset$. So we suppose $S=SL$ and $S\ne\emptyset$. Then $\exists w\in S$ such that $0\le|w|\le |v|$ for some $v\in S$. Now $|w|\ne 0$, since $|w|=0\implies\{\epsilon\}=w\in S=SL\implies \{\epsilon\}=xy$...
Assume we have some statement called $\alpha$. We will define a new statement $P(\alpha):="(\alpha\text{ can be proved})\lor(\lnot\alpha \text{ can be proved})"$ I claim that $P(P(\alpha))$ is always correct (that is, we can always prove\disprove whether a statement can be proved or not). The following is a "proof" for...
I have a directed multigraph (a multigraph is a graph that can have more than one edge between any two nodes). In Wikipedia's terminology, this is a directed multigraph (edges without own identity). I want to find its longest directed trails (a directed trail is a directed walk in which all edges are distinct). I.e., I...
I am looking at register machines like the Random Access Machine. Wikipedia says: Random-access machine (RAM) – a counter machine with indirect addressing and, usually, an augmented instruction set. Instructions are in the finite state machine in the manner of the Harvard architecture. Does this mean the instructions...
I’m a self-taught software engineer who’s been working in industry for 12 years. I don’t have any formal education in CS and math was never my strong suit (although I’m willing to do the work to make it my strong suit!), but when I first started learning how to program I went through some basic courses offered by Stanf...
It is known that there is a $748$-state Turing machine that halts if and only if $\mathsf{ZF}$ is inconsistent. So by Gödel's second incompleteness, $\mathsf{ZF}$ cannot find what $S(748)$ exactly is, where $S$ is the maximum shifts function (Also known as the "Frantic Frog"). I'm rather confused by this fact. As $S$ i...
I'm working with squared matrices that can be quite large, for instance, a M = 50 x 50 matrix. My objective is to compute the power of the squared matrix M^t for very large t values (for example t = 4000). I work in R and I have used the R function matrix.power from the matrixcalc R package. I'm exploring the possibili...
How can I quickly judge whether matrix A is the inverse matrix of B? This is an exercise for the course I take. This question is given in the section of randomized algorithms. So I think its solution may be related to randomized algorithms.
I am wondering whether the language $$L_{\textrm{hanoi}} = \{\langle k,s \rangle \mid \text{$s$ is a solution of Tower of Hanoi problem on $k$ rings}\}$$ is in $R\setminus \mathit{NP}$. I want to claim that there is a Turing machine that solves the problem, therefore, $L_{\mathrm{hanoi}} \in R$, but given a solution to...
I don't 100% understand this. But I have a entailment, and I want to prove whether it is satisfiable or not, and I will do this using resolution and variable elimination. Here is the formula: $$ (x_1 \lor x_2 \lor x_6) \land (\lnot x_1 \lor x_3 \lor x_8) \land (\lnot x_2 \lor \lnot x_3 \lor x_4) \land \\ (\lnot x_4 \lo...
Consider the following setting. You have $n$ cities, and there is a cost to travel from a city $i$ to a city $j$ given by $c_{ij}>0$ where $c_{ij}\neq c_{ji}$. Moreover, if you are traveling to city $i$, you are allowed to stay exactly $d_i>0$ days. The problem is: Find a travel schedule, this is: a number $m$ and a se...
I know the basic definition between parallelism and concurrency. But there is not much information about concurrency in multiple core. what is the difference between concurrency in single-core vs concurrency in multiple-core? Is there much difference performance-wise between concurrency in multiple core vs parallelism ...
I have to show that the language $ \mathcal {L} = \{a ^ k b ^ {2k} a ^ k: k \geq 0 \} $ is not a regular language. So that's what I want to use the pumping motto for. What I could do is this: let $ \ sigma = a^Nb^{2N}a^N $, where $| \sigma | = 4N \geq N $, fulfilling that $ \alpha \beta^k \gamma$. But at the moment of ...
I'm working on a project where I need to create search functionality that can efficiently search a list of data structures like: json1 = [ { "name": "bob", "age": 55, "active": false, "location": { "state": "FF", "country": "NZ" } {, { "name": "susan", "age": 30, "activ...
I am trying to prove the above statement. A DeMorgan circuit is a circuit that has only $\{ \wedge, \vee, \neg \}$ gates, and the negation is applied only to input variables. So, assuming we have a circuit of size $s$ that computes a function $f: \{0,1\}^n \rightarrow \{0,1\}$. The basis for this circuit is $\{\wedge, ...
I was wondering if there is any formal, general way to prove the correctness of a candidate solution to the critical section problem in synchronization. For example, in the image enclosed, I have considered the Petersons solution to the critical section problem(reference: operating system concepts by Gagne) The exampl...
Consider sequences $p=(p_1,\dots,p_N)$ (the order matters) of length $N$, where $p_i\in\{1,\dots,D\}$ for fixed $D$. Moreover, consider a cost function $c:\{1,\dots,D\}^N\to\mathbb{R}$ which comply $c(q)\neq c(p), \forall p,q\in\{1,\dots,D\}^N$ with $p\neq q$. The problem is to find $p\in\{1,\dots,D\}^N$ with least cos...
I am trying to enumerate and display all possible divisions of an n-polygon into (n-2) triangles (as in the following mathworld picture) I know how to count how many divisions (Catalan numbers, 1, 2, 5, 14, 42, ... ), but I am struggling to find a way to generate all the C(n-2) triangulations. Can anyone point to exis...
I am so confused between concurrency vs parallelism in multi-core processors. If a concurrent process has many threads and if the processor is multi-core then can each thread run on multiple cores? If the answer is YES then multiple threads are running in parallel but the process is concurrent. How is it possible and w...
Suppose we have N natural numbers in a queue. ex queue = [3, 14, 1, 20] and an empty stack We are allowed to make only two actions: Action "x": Dequeue an element from the queue and push it to the stack. Action "o": Pop an element from the stack and enqueue it in the queue. In the above example, the following actions...
Context Let's say I have a finite set of points of size $N$. I can represent the points in a metric space and then compute distances between them. My goal is to replace a point in the set with another one (let's say a completely random point), only if the new point maximum distance is better than a set's point maximum ...
Given a set of elements {e1, e2, ... en}, a set of pairs of these elements (each element may be present in several pairs) and a number k. I need to count how many combinations of size k exist which not include any pair? For example: if there only one pair {e1, e2} result in number of all combinations without elements e...
I have to show that a PDA accepts empty language, but for this I have to use some algorithm, with what kind of algorithms could I demonstrate it? I've heard about the algorithm from Moore, Brzozowski or Thompson, but they are for DFA, so I don't know if it would work.
I recently decided to review the B-tree chapter (chapter 18, p 486 in 3ed) in Introduction Algorithms, and found that they call pages what I always referred to as blocks or clusters: In order to amortize the time spent waiting for mechanical movements, disks access not just one item but several at a time. Information ...
How to get the expected time complexity of while loop below? While infinity: case1: Return 0 with a probability of p(1 - p) case2: Return 1 with a probability of p(1 - p) case3: otherwise repeat this loop until return 0 or 1 I can understand the probability that this loop runs only one time is $2p(1 - p)$. But I...
Just trying to solve the second part of a question with two parts. First part was to prove that you can't add decrement method to a standart binary counter without hurting the amortized complexity and change it to be more than O(1). This part i have done with no problems. Solution in a nutshell - after some method you ...
What is the advantage of probability algorithm? e.g. Las Vegas. I would also like to know some applications of the randomized algorithms. Are there any recommendable courses or books?
I have to form a free context grammar for this language $w^{m-1}aca^m$ where $w \in \{a,b\}$, so what I have been able to do is this: $X \rightarrow SacA$ $S \rightarrow aS|bS$ $A \rightarrow aA$ But I don't know how to do it or if possible, condition the exponents as long as $ S $ is repeated $ m-1 $ times, and $ A $,...
I am not a formal student for CS nor have I ever been, I just want to understand something simple about your field for general knowledge, in plea. Turing, RAM, or Von Neumann --- which theory/model is consensually accepted to describe how "generally every computer works" (among computer scientists)?
I am trying to work out the time complexity of my function but I'm not sure how it works with powers. I've got $y=(\frac{x}{3})^n$ as one of my lines. How many basic operations is this? Would it be $2(n-1)$ for the power then $1$ for the division and $1$ for the assignment of $y$? Also, is the square root of a number j...
Wordsense.eu gives a definition of epilogue as (computing) A component of a computer program that prepares the computer to return from a routine. I’d like to know more & haven’t been able to successfully search for info. Could anyone point me to a source / share their knowledge?
I am not in the computer science field and was looking for some guidance on books/papers/programs that allow me to learn how to design algorithms for problems that involve very large number of calculations and search in very large datasets. Texts that have advanced mathematics is not an issue. I am just looking for som...
As shown above, several NP-Complete problems are derived from GSAT (general satisfiability problem) by a polynomial-time reduction. Then, my question is that is every pair of NP-Complete problems reduced in polynomial time? In other words, I think that the above graph should be represented as a complete graph by the d...
I wanna know if $X'(X+Y)$ means $X'.X+Y.X'$? Does it have an AND gate after $X'$? Notation: $X'$ : NOT $X$ $X + Y$: $X$ OR $Y$ (OR gate) $X.Y$ : $X$ AND $Y$ (AND gate) New to boolean, can't seem to understand this question.
I've been stuck on this problem for some time now.. Given an array A of size N that ranges between [1..N], a "move" is to increase or decrease an element (by 1). After each move the array must remain within [1..N] I need to find the minimum number of move operations to make the array pairwise distinct.
Tangled cable: Let's have a long cable, from both ends of which protrudes n wires. Each wire at the left end is connected to just one at the other end and we want to find out which one. To do this, we can use the following operations: (1) apply voltage to a given wire at the left end, (2) disconnect voltage from a give...
I was reading Professor Knuth's Volume 2 (page 136) about generating a geometrically distributed random variable $N$ (with $p$ as the probability of success). Basically, the idea is to generate a uniformly distributed random variable $U$ in $[0,1]$. Then, we can apply a simple formula $N = \left\lceil\frac{\ln(U)}{\ln(...
We define language substitution for a Context-Sensitive Language (CSL) $S$ over an alphabet $\Sigma$ is a map from $\Sigma$ into CSL's, for example: $f(abc) = L_1(a) L_2(b) L_3(c)$ such that (I guess) the union of all $L(s)$ for $s \in f(S)$ is defined to be $L(f(S))$ and $L(f(S))$ is known to be a CSL itself. That is ...
Let $L_1$ be a non-regular CFL. Let $L_2$ be a regular language. Assume that $\left(L_1\right)^{*} \subseteq L_2$. I'm looking at $L_3 = \left( L_1 \right) ^{*} \circ \overline{L_2}$. Is $L_3$ always non-regular? I can find multiple examples of it being non-regular, yet none of it being regular. Edit: $\overline{L_2} \...
The first step of Johnson's algorithm is the creation of a new vertex s which has an edge to every other vertex with a weight of 0. Then I perform only one iteration of the Bellman-Ford algorithm on this new graph and with this one iteration, you can see if there are negative cycles in this graph. But why is that? When...
Consider the sampling algorithm as described here section 2.2 specifically Algorithm 2.4. Essentially we are given a stream of $N$ elements and wish to maintain a uniformly random sample, $S$, of size $k$. Initially we put $k$ elements into $S$ and then for each iteration, $i \in [k+1, N]$ we choose a random number $x ...
There are many reasons why numbers larger than 64 bits must be computed. For example, cryptographic algorithms usually have to perform operations on numbers that are 256 bits or even larger in some cases. However, the programming languages that I use can only handle at maximum, 64 bit integers, so how do computers perf...
I saw this algorithm question which is as below. There is a server that receives request Ids that are positive integers. The High Water Mark (HWM) for the server at any instant of time is defined as the highest integer request Id n such that every positive integer request Id less than n has already been received. For e...
Given the image attached, I am looking for a way/strategy/pseudocode to iteratively find each polygon created either by two blue-dotted line segments, a blue-dotted line segment and an intersection, or two intersections. I have an ordered list of line segments for each line, an ordered list of blue-dotted line segments...