instruction
stringlengths
35
29.1k
If the objective function contains $n$ variables (e.g. $f(x_1, ..., x_n)$) in the Nelder-Mead algorithm (or other direct search methods), is there any known lower/upper bounds on how many times the algorithm needs to evaluate $f$ to achieve the desired value by precision $\epsilon$? For instance, suppose $f(x_1,x_2) = ...
I'm trying to figure out if the following statements are true: • Savitch’s theorem implies that $NSpace(\log n)$ = $DSpace(\log n)$. • Savitch’s theorem implies that $NSpace(n^2)$ = $DSpace(n^4)$. • Savitch’s theorem implies that $NExpSpace = ExpSpace$. • Knowing that QBF validity is $PSpace$-hard, Savitch’s theorem im...
The following comes from Exercise 2.3-3 of “Introduction to Algorithms, 3rd Edition by CLRS” Here is a solution to that exercise that solution says at the end “By P.M.I., T(n)=n lg n, when n is an exact power of 2”, what does P.M.I. mean in this context?
The Weight Distribution / Subspace Weights Problem in coding theory is defined as this: Instance: A binary $m$ by$n$ matrix $H$ and an integer $k > 0$ Question: Is there a set of $k$ columns of $H$ that sum to the all-zero vector? You might also say: Given a binary $m$ by$n$ matrix $H$ and an integer $k > 0$, is the...
I am trying to find the constants $n_0$ and $c$ to show that some given functions belong to the $O(\cdot)$ equivalence class. But, while it seems easy, I am not sure whether I am allowed to do what I will showcase below, or rather, what decides which constants I should take into consideration. For example: $$n^{\frac 2...
In the Optimal Substructure Wikipedia, As an example of a problem that is unlikely to exhibit optimal substructure, consider the problem of finding the cheapest airline ticket from Buenos Aires to Moscow. Even if that ticket involves stops in Miami and then London, we can't conclude that the cheapest ticket from Miami...
It is possible to have this logical consequence? $$ \forall x (p(x) \vee q(x)) \models \forall x p(x) \vee \forall x q(x) $$
I am stuck on what to do. I am trying to create a simple implementation of the Flajolet–Martin algorithm using Python. The stream will be the contents of a text file and you will produce an approximation of the number of unique words in the file as given by the algorithm. You will need to process the file one line at a...
Suppose $f$ and $g$ are Boolean functions without a constant term, and where every variable has the same influence. How to show every variable will have the same influence in $f \circ g$? To me it seems like influence of a variable in $f \circ g$ is the product of influence of the outer variable in $f$ with the influen...
If we have a deterministic algorithm $A$ such that $\#3CNF \in APX$, how can we show that there is a fully polynomial deterministic approximation scheme for $\#3CNF$? How can we show that $\#3CNF \in FPTAS$?
$k$-$\text{RSAT}$ is a variant of $k$-$\text{SAT}$ where we restrict our attention to formulae in which each variable occurs at most $3$ times, and each literal occurs at most twice. The language $k$-$\text{RSAT}$ is $$\{\phi \in k{-}\text{SAT} \mid \text{ no variable (literal) occurs more than 3 (2) times in }\phi \}...
I have a project in Golang. But i don't have any idea about how to solve it. n will be an odd number (Feedback will be given if an odd number is not written) As output, a structure with n*n matrix appearance will be created according to the following rules and printed on the screen. Rules The rules will be transferre...
Suppose given a directed graph $G=(V,E)$ with positive weights and we try to find shortest path $d(s,t,\ell)$ from $s$ to $t$ such that we traverse at most $\ell$ edges ($\ell$ is even). Let $w(u,v)$ be weight of edge (u,v), so we use this recurrence, $$d(s,t,\ell)=\begin{cases} \min_{x \in V}\{d(s,x,\frac{\ell}{...
The book I took this example from (Introduction to Algorithms, CLRS) wants to prove that the recurrence relation $$T(n) = 2T(\lfloor n/2 \rfloor)+n$$ is $O(n\lg n)$ using the so-called substitution method. When proving the inductive step, they use the strong mathematical induction, so they assume that $$\forall m : m <...
Andrew S. Tanenbaum, in his book Modern Operating Systems states that, When a hardware interrupt occurs while a user thread is running, the interrupted CPU switches into kernel mode. If the interrupt is caused by an event not of interest to the interrupted process, such as completion of another process’ I/O, when the ...
I am trying to learn notations for a course and I am stuck on how to even start. I need to figure out the BigO for this function. Question is there's a C# function bool isPalindrome(string S) which runtime is 3n - logn + 1 milliseconds, where n is the length of the string S. Please help!
How to convert Pseudo boolean constraints to CNF format for example L1 + … + Ln ≥ 1 is converted to L1 ∨ … ∨ Ln but how about: L1 + … + Ln ≥ k L1 + … + Ln < k or L1 + L2 = k or 2 L1 + 2 L2L3 + L4 ≥ 3 is it there a book that I could read to understand more?
Consider Euclidean algorithm to find $GCD(a,b)$ as follow: $$\gcd(a, b) = \begin{cases}a,&\text{if }b = 0 \\ \gcd(b, a \bmod b),&\text{otherwise.}\end{cases}.$$ I read this link, suppose $a\geq b$, I think the running time of this algorithm is $O(\log_ba)$. My argument is as follow that consider two cases: $b\leq \fra...
So recently I've been involved in a discussion and I was told that literally the only thing computer can do is addition. Is that true? What about logic operations? Aren't they performerd by physical logic gates?
I came across this simple algorithm for finding a k-core of a graph, but every paper I read gives this notion of being maximal without proof, and I'm wondering how I might prove it. So a k-core of a graph $G$ is a maximal induced subgraph $H \subseteq G$, such that all the degree of the vertices in $H$ are at least $k$...
Given a set of $n$ stones, arranged in a row at equal distances from each other. The stones are numbered from $0$ to $n-1$. A frog that is on stone number $0$ has to get to stone number $n-1$. A jump is a move from stone $i$ to stone $j$ ($i<j$). Such a jump has length equal to $j-i$. The maximum jump length of the fro...
Suppose you are given two sets $\{p_1, p_2,\dots , p_n\}$ and $\{q_1, q_2,\dots , q_n\}$ of $n$ points on the unit circle. Each point $p_i$ is connected to $q_i$ by a line segment. How could we count the number of intersections of all $n$ line segments in $O(n\log n)$? You could also see the problem in Jeff Erickson's...
Construct a regular expression for the set of strings over {a, b} that contain an odd number of a's and at most four b's. So far, I have $(aa)^*a((b+\varepsilon)(aa)^*)^4$, but I don't think this covers all cases. For example, $abaabaaab$ should fit the criteria, but it wouldn't be in the language described by the abov...
In Sipser's Introduction to the Theory of Computation this is how $0^n1^n$ is proved to be not regular Example 1.73: Let $B$ be the language $\{0^n1^n|n \ge 0\}$ We use the pumping lemma to prove that $B$ is not regular. The proof is by contradiction. Assume to the contrary that $B$ is regular. Let $p$ be the pumping ...
Consider the language $$L = \{\langle M \rangle \mid \text{$\exists$ an input $x$, where $|x|<i$, such that $M$ halts on $x$, but it takes at least $j$ steps} \}$$ where $i$ and $j$ are fixed non-zero natural number for L I am trying to prove that $L$ is undecidable. My thought is that reduce the Universal Language to...
Let $L=\{b^ma^n \mid \text{$m$ and $n$ are coprime} \}$. Using Nerode's theorem, prove that $L$ is irregular. From Nerode's theorem I know that $L$ is regular if and only if the number of equivalence classes of $R_L$ (the relation defined in Nerode's theorem) is finite, so I need to prove that there are infinitely ma...
I have a sequence of floating point numbers. I want to map each of them to one of their closest integers. There is one rule: Sum of integers must be as close to the sum of original numbers as possible (ideally sum of integers is a rounded sum of originals). You can think about it as of snapping to grid some bar plot wi...
I am reading the book Randomized Algorithms By Motwani and Raghavan, and one of their exercises gives a modification of Karger's Min-Cut algorithm(Both is Monte Carlo) which picks two vertices and contracts them instead of an edge. You then have to show that the probability of this modified algorithm suceeding is expon...
The RIP routing protocol was published in 1988 and uses Bellman-Ford algorithm to calculate shortest path. Also more recent version of RIP (RIPv2 and RIPng) use the same algorithm. The Djikstra algorithm was published in 1959. Why RIP use Bellman-Ford instead of Djikstra? More generally, why routing protocols prescrib...
a friend of mine sent me a question which he can't solve and I didn't succeed to solve it as well. Question: We define two languages: $$ACCEPT=\{\langle M,w\rangle\ \ |\ M\ is \ a\ turing\ machine.\ M\ accepts\ w \}$$ $$REJECT=\{\langle M,w\rangle\ \ |\ M\ is \ a\ turing\ machine.\ M\ \ halts\ on\ w\ and\ rejects\ it ...
As in, given a regular language $V$, does there exist a deterministic Büchi automaton $\mathcal{A}$, or equivalently a regular language $W$ such that $\mathcal{L}(\mathcal{A})=\vec{W}=V^\omega$? For clarity, if $L$ is a finite-word language, then $L^\omega$ and $\vec{L}$ are resp. the $\omega$-closure and the limit of ...
Consider this problem from Jeff book Given a rooted tree $T$ and an integer $k$ as input, and it should compute the largest possible number of disjoint paths in $T$ , where each path has length $k$. Do not assume that T is a binary tree. How we can use greedy approach to solve above problem?
Given a boolean variable $x$ and nonnegative integer variable $s$, I want to select $y = \begin{cases} 0 & \text{if} \ x = 0 \\ s & \text{if} \ x = 1 \end{cases}$. Currently in the problem, $s$ is the sum of $n$ boolean variables $x_1 + x_2 + \cdots + x_n$ so I want to compute $x \land x_1 + x \land x_2 + \cdot...
Suppose the optimal color assignment of graph $G$ is given. Does there exist any polynomial-time algorithm that provides the optimal color assignment of its complement graph $\overline{G}$? A relation between $\chi(G)$ and $\chi(\overline{G})$ is present here. But it is not providing the exact value of $\chi(\overline...
From what I can gather priority queues are typically implemented with heaps. If I have a small fixed number of priorities (such as 4), wouldn't a small array where each index represents the priority, and indexes into the associated linked list at that priority, be a more efficient implementation than using a heap, allo...
Cheers, I am trying to solve the problem of minimum length cycle in a graph, and I came across a solution that suggested that I should tweak the Floyd-Warshall algorithm to solve that. It stated that instead of setting path[i][i] = 0 I should instead set path[i][i] = INFINITY, but I don't exactly understand why that is...
Suppose given a positively-weighted tree $T=(V,E,w)$ and $k\in \mathbb{N}$, where $|V|=n$, the weight function $w:E\to\mathbb{N}$, and each node has degree at most $3$. How we can find a path on $T$ that has weight $k$ and the minimum number of edges in $O(n\log^2n)$? I think we can use BFS because BFS give us the shor...
I am absolutely stumped on this one. I am unsure of how to start with this one. I have thought to reducing the problem to Atm. Another thought I have had is to convert M1 to a PDA and use the complement of EQPDA to solve this but I am honestly really unsure. Any tips that could point me in the right direction or soluti...
I came across this recent Reddit thread, Thoughts on Botton vs Unit Types, but I don't understand what the similarities and differences are in regards to when you are creating a programming language. If you are creating a programming language, why do you need both a Bottom and a Unit type (as defined in the thread). F...
For instance can we categorize the following problems into NP-Hard ? Is the Universe finite ? Is there life after death ? What came first, the chicken or the egg ? My question is more around what can be modelled into the PSPACE category of problems ?
This is cross-posted from a similar question on Mathematics Stack Exchange, on the advice of a commenter. In mathematical logic, a formal system is a structure which includes, amongst other things, a set of axioms, and which is able to determine the truth or falsehood of statements with respect to those axioms. A numbe...
Reading the Wikipedia pages on these topics, it seems that sparse conditional constant propagation (SCCP) is a more powerful form of constant propagation (CP)? E.g all optimizations available in CP are subsumed in SCCP.
For example, if it takes 1 cycle to read the cache and 3 cycles to write the cache, is the hit time equal to 4 cycles? Also, does this vary based on whether the cache is an instruction cache or a data cache?
I was given a question in Automata that I need to prove or disprove, and I thought about this language: $$L = \{w\in \{0, 1\}^*\mid 1\le |w| \le 2^6\}$$ Can you please help me to figure out if its minimal DFA contains only 6 states? How can I get intuition about DFA sizes?
I am wondering about the complexity of the following SAT related problem: Given a CNF with $n$ clauses containing exactly $k$ literals with the following properties: The intersection of any pair of different clauses only contains 1 variable. Every variable is only contained in one intersection. So every variable appea...
I am reading Michael Sipser's "Theory of Computation". In one of the proofs he talks about converting "DFA to Regular Expression" and he talks about "GNFAs". I understand one method of converting DFA to Regular Expression that is using Arden's Theorem. I assume GNFA is a medium between DFA and Regular Expression. Can s...
Suppose we have $n$ candidates from a candidate pool $\{1,2, .., n\}$ and we have $m$ departments. A candidate can be assigned to at most one department (so not being assigned is possible). Each department $d$ is considering candidates in $C_d \subseteq \{1, 2, ... n\}$ (with possible overlap between departments), and ...
Suppose we are at the centre of a $k$ road intersection (i.e, there are $k$ different roads radiating out from where we are standing, infinitely). Suppose along one of these roads is a treasure. This treasure is along one of these roads at distance $d \in \mathbb{Z}$ from the center. We do not know which road and we do...
Consider a function $C(n, d)$ which counts the number of well formed, i.e, balanced, parenthetical 'words' of length $n$ and maximal nested depth $\leq d$. That is, $(())$ has $n = 4, d = 2$. $()((())())$ has $n = 10, d = 3$ and so on. $C(n, d)$ counts all well formed strings above (i.e, $($ and $)$ are balanced), of l...
Consider the following problem from Jeff Erickson: Algorithms that also appears in this post, which wants us to prove a lower bound for the problem. Suppose you are given an array $A[1 .. n]$ of integers, each of which may be positive, negative, or zero. A contiguous subarray $A[i .. j]$ is called a positive interval...
I read from this post the term configuration space. I don't know the meaning of configuration space. What is the exactly meaning of configuration space? And why DFA's configuration space is finite and PDA's configuration space is infinite? Give one example for both the cases then it could be better for me.
Consider exercise 23(c) of chapter "Greedy Algorithms", Algorithms by Jeff Erickson. Given a tree $T=(V,E)$ in which each node has a reward, and $k\in\mathbb{N}$, our goal is to find a set $S$ of paths, each having length exactly $k$, such that the paths in $S$ are pairwise vertex-disjoint and and the overall reward (...
I am trying to find a better way to find all leaf nodes in my undirected waypoint graph. This is how I define a leaf node: A leaf node is a node that is never part of a cycle and so has to meet one of these two criteria: It has only one connection Or The node's total connections minus the total leaves connected to s...
To get the dual of a planar graph, each of the faces becomes a vertex. And then, two vertices in the dual graph are connected if they share a common face. My question is about planar graphs that have disconnected components. It's unclear to me how to define a face for these. As a simple example, consider the graph belo...
I am reading chapter 1 of Michael Sipser's "Theory of Computation" and in the section "Formation defination of NFA" he says the following: 3rd point of the above image is the point of interest in the post According to a few stackoverflow post: 1)https://math.stackexchange.com/questions/1689850/is-the-empty-string-alwa...
I am studying "Theory of Computation" by Michael Sipser. I am studying the section where he teaches how to convert "RE to FA". He uses empty transitions for union, concat and star, but that is very getting very confusing for me But i found this another method here: https://www.codingninjas.com/codestudio/library/conve...
I have to write the language of the below $NPDA$(Non-Deterministic Push Down Automata). I think that from $q_0$ to $q_1$ and then $q_2$, we are actually building the below all the strings of $0$'s and $1$'s of the form $a^nb^n$ with the lenght at least 2. But there is also a transition from $q_2$ to $q_0$, which makes...
I have read that when programming it is good to identify relations -- invariants -- that should hold true throughout the program, and it is good to insert assertions throughout the code to check that the invariants are maintained. I can see how programs that involve mathematics can have invariants, i.e., some mathemati...
I’m looking for a distribution that is non-negative, or has good tail bounds (so non-negative with high probability) and maximizes the ratio between the expected maximum of $n$ iid samples and the mean. That is, if $X_1,\ldots,X_n$ are iid samples from the distribution, $Y = \max(X_1,\ldots,X_n)$, and $X$ is another sa...
I have to design an NPDA(Non-Deterministic Push Down Automata) for all the strings over $\{a, b \}^*$, which have equal numbers of $a$'s and $b$'s but do not end up with an $a$. I know how we should create an NPDA for the strings with an equal number of $a$'s and $b$'s, which its machine would be like this: But I don...
In linux, when I access /proc for a particular program it shows memory mapping for the program in maps file. Something like this: I wanted to know what is this [stack] memory mapped to i.e the kernel stack or the user stack and how can I access the contents inside that memory area? There is another file within the /pr...
Given the problem of having a sorted array $A$, an element $x$ to be searched for in the array $ A $, what is a lower-bound on the process of finding $x$ in $A$? The answer is $ \Omega(\log n) $ because I was told that $ n $ is the number of leaves in the decision tree and so $ \log n $ will be the height of the tree. ...
That's a question from a home assignment by T. Zur: Say that a Turing machine $M$ is monotone if it halts on every input, and if the length of $w$ is greater than the length of $w'$ then $M$ performs more steps on $w$ than on $w'$. Prove that MON is undecidable. My idea is to define a reduction from HALT to MON. We d...
Can anyone please help me with a better solution than O(n^3) for this problem? So the problem is given a string, we want to output the substring's length where freqency[c1] - frequency[c2] is MAX. c1 = Most frequent character c2 = Least frequent character e.g 'aaabbbbbabcbbbaaaa' => 8 ( corresponding to the substring '...
Let's say that we want to convert the regular expression: (ab + a)* to Finite Automata, where '+' is union and '*' is kleene star. Using the Thompson method, Thompson Method I end up with this: My question is, is there a way to cross verify that my E-NFA accepts the language of Regular expression mentioned at the start...
I was wondering if someone could help resolve some issues I have understanding the proof given for the Cook-Levin theorem provided in the Sipser text (3rd edition) – as this proof has truly stumped me. Having read through this proof numerous times, the only issue I have is that I simply do not understand how it actuall...
How do I being to show that if $L_{1}$ is Turing-recognizable language over $\Sigma=\{0,1\}$, then $L_{2} = \{ww^R | w ∈ L_{1} \}$ is a Turing recognizable language too. There is another similar problem, but instead of the language being recognizable, it's decidable. If anyone has any ideas on how to approach both of t...
Can anyone please help me solve this better than $O(|a-b| \cdot n)$? Given an array of both negative and positive numbers, we want to find the maximum sum of the elements in contiguous subarray having a length between $a$ and $b$. Example Input: 8 1 2 -1 13 -2 5 13 -5 2 2 Output: 18 Here a = 1 , b = 2 Although Maximum ...
I know that retrieving an item in a collection can be done in $O(1)$ time(on average) using hash tables. I would like to know if there is an algorithm that could be as performance without using arrays. My main motivation for this question is to know if it is possible to build a retrieve element algorithm in $O(1)$ time...
I have a large system of $3$-$XORSAT$ constraints (i.e. up to $3$ variables per constraint) and this can be represented in matrix form as a linear algebra problem $Ax=b$ $mod$ $2$. Solvability (i.e. the satisfiability of the $3$-$XORSAT$ system) can be tested by using Gaussian elimination which involves multiple rounds...
Show a reduction of max flow to min cost (not min cost max flow!!)
I am studying the Master Theorem, but there is a case in which I have no knowledge on how one should proceed. If it's given: $T_1(n)= 1$ if n=1 $T_1(n)= 4T_1(\frac n2) + \sqrt{3n}+1$ otherwise. For this case $T_1(n) \in \Theta(n^2)$ We then have: $T_2(n)= 1$ if n=1 $T_2(n)= 14T_2(\frac n4)+ T_1(n)=14T_2(\frac n4)+4T_1(...
Orthogonal arrays often appear in probabilistic algorithms. They can be efficiently constructed from, e.g., BCH codes. But is there an efficient algorithm that can verify if an array is orthogonal? I would be particularly curious about the strength-4 binary arrays. In my last edit I added that the array is binary. It s...
I am trying to understand how the input size, problem size and the asymptotic behavior of an arbitrary algorithm given in pseudo code format differ from each other. While I fully understand the input and the asymptotic behavior, I have problems understanding the problem size. To me it looks as if problem size = space c...
Consider a logical address space of 4096, page size = 1024 physical memory = 8192 $\begin{array} {|c|c|} \hline \text{Page No} & \text{Frame No} \\ \hline 0 &7 \\ \hline 1 &4 \\ \hline 2 &2 \\ \hline 3 &3 \\ \hline \end{array}$ What is the physical address corresponding to logical address 500, 1000, 2000, 3000, and 400...
There are people and the food they prefer: John -20> Apple John -10> Pear Ethan -20> Apple Ethan -5> Orange Michael -10> Pear Michael -10> Limon The numbers indicate how strongly they prefer the respective food. i.e. John likes Apple more than Pear (20 > 10). And so for everyone. The task is to distribute food to absol...
Let $G = (\{A,S\}, \{a,b\}, S, P\}$ be the grammar with the following productions: \begin{align} & S \to aAb | Sb \\ & A \to aAb | ab \end{align} What is the language $L(G)$ generated by the grammar? Prove your answer to 1. by induction. Here is my attempt. I think that the language generated by $G$ is $$L= \{a^nb^...
I was wondering whether someone could help me resolve an issue I have understanding the proof given for Savitch’s theorem in the Sipser text (3rd edition). The question I have is more or less identical to the first question given in a previous post (The crux of Savitch's Theorem); which has remained unanswered – hence ...
Let $L=\{ a^c \mid c \text{ is composite} \}$. Prove that $L$ is not regular using the pumping lemma. You can use Dirichlet's theorem, which states that if $(a,b) = 1$ then there are infinitely many prime numbers of the form $an+b$. I am thinking about this question for a lot of days and I don't find it trivial, do y...
I have recently come across a result that showed that a given problem is in FPT when parameterized by the treewidth of a graph. However, they did this by showing that the problem is in FPT when parameterized by the treewidth of an augmented version of the graph that had treewidth of at most 2k+1 when the treewidth of t...
I encountered an exercise in which I am struggling to understand the solution provided even though I spent a lot of time trying to figure it out. The exercise is the following and was taken from the book "The art of computer programming - Volume 1 by Donald Knuth" Imagine four railroad cars positioned on the input si...
I know that : $T(n,k)=T(n−1,k−1)+T(n−1,k)$ is the Pascal triangle. But what is this then: $T(n,k)=T(n−1,k−1)+T(n,k-1)$ Is there any name for it? I am trying to learn about it's time complexity etc, but I can't find anything online.
Let $G=(V,E)$ be a complete finite graph with the vertices arranged in a circle. Each edge has a nonnegative weight, and we would like to find an efficient algorithm to find a subgraph of maximum total weight, which is a triangulation of the graph. A triangulation of the graph is a subgraph such that no edges cross a...
In an introductory course on Dijkstra's algorithm, I enunciated the following lemma : Let x →* z be a shortest path in a weighted graph and let y be any vertex along that path. It follows that x →* y and y →* z are shortest paths too. To which one of my students pointed out that it does not seem to hold in the undire...
It is pretty simple to implement a DFS algorithm for a binary tree but what about BFS for binary trees? I tried to adapt the BFS algorithm for ordered tree, this is the result: I presume that better solutions are possible. Could someone suggest a better solutions?
I know that swapping is avoided in mobile systems because of limited memory but I came across this question and couldn't answer if the answer is yes. Should swapping be done in Mobile systems? If yes, what should be the appropriate swap size in case the secondary storage is 16 times that of RAM. Which swapping location...
Given three arrays A, B, and C of size n, m, and m respectively (1-based indexed). A function F(i) is defined as - F(i) = minimum_of(⌈ Ai / B1 ⌉ * C1 , ⌈ Ai / B2 ⌉ * C2 , ⌈ Ai / B3 ⌉ * C3 , .... , ⌈ Ai / Bm ⌉ * Cm) where ⌈x⌉ is defined as the ceiling function. For example : ⌈2.3⌉ = 3, ⌈3.9⌉ = 4 and ⌈3⌉ = 3. Find the va...
I am studying Communicating Sequential Processes (CSP), and I understand that an event can be "emmited" ($\overline{e}$) and an event can be "waited on" ($e$), so that an event will sync with another parallel event ($\overline{e} || a \rightarrow e$). Now how do I represent the fact that an event must not occur at the ...
Given an undirected and unweighted graph $G = (V, E)$ and two of its vertices $s$ and $t$. My task is to find an algorithm that checks if there exists an edge belonging to $E$ such that its removal will result in the shortest path from $s$ to $t$ being extended (and if so returns this edge). We may remove only one edge...
I am studying B-trees and reading Introduction to Algorithms by Cormen et al. Unfortunately, they have this diagram Figure 18.1 and they do not list the order of the tree. I understand that for a B-tree of order $m$, the tree has 5 properties: Every node has at most $m$ children. Every internal node except the root h...
I misunderstanding about some logarithm property in algorithm course: is it correct that we say following three term is equivalent? $O(\log a + \log b)$ $O(\log (ab))$ $O(\log (a+b))$
I need to prove: reverse(push(as,bs)) = push(reverse(bs), reverse(as)) where: def push[T](as: List[T], bs: List[T]): List [T] = as match { case Nil => bs case x::xs => x::push(xs, bs) } def reverse[T](ls: List[T]): List[T] = ls match { case Nil => Nil case x::xs => push(reverse(xs), x::N...
I am confused with the terms inhabitant vs. subtyping. For example, We usually think that "john is an inhabitant of Human". This sentence is correct, because john is an individual, and an individual belongs to the set Human (that reflects the meaning of inhabitant). However, if we think of john as a subset with only o...
I have the following problem: There are $n$ variables $x_i$, $i=1...n$, each can take integer values from 1 to $m$. For every set of values I can run a test which has a binary outcome ('Pass' or 'Fail'), and it is known that the test outcome only depends on a value of a single variable being larger than some threshold....
Can somebody explain to me the meaning of $::$ in the following predicate? $$(\forall i : P(i) : Q(i)) \equiv (\forall i :: P(i) \implies Q(i))$$
Suppose you have an $n\times n$ matrix and you want to find a local minimum. To find it you scan the middle row and column and identify a minimum. If it is a local minimum, you're done; if not, you recursively search the sub-quadrant where the smaller value was found. Now I can analyze the runtime in two different wa...
(a || b) || (c && d)) Given the above, how do I derive the table below: a b c d output T - - - TRUE F T - - TRUE F F T T TRUE F F T F FALSE F F F - FALSE I'm told that this is short circuit evaluation, basically, we take away some branches/paths that always lead to false or true so we don't waste ti...
There is this certain slide in Coursera Computer Science: Algorithms, Theory, and Machines course: I think it is saying finding the optimal size of given data is undecidable. However, I thought there is a theorem in information theory that gives the limit of the lossless compression? I think I must have misinterpreted...
Can’t a PDA get stuck in a cycle of blank transitions? Should the implementation detect such cycles and do something about them? That seems quite complex to consider all the edge cases. Does the answer vary for nondeterministic PDAs?
Some time ago I had in one of the big tech interviews the following question that I still don't know how to approach it. You have a chains of reservations from AirBnb: reservations:[ {user = 1, res_id = 1001, checkin = 100, checkout = 101}, {user = 2, res_id = 1002, checkin = 104, checkout = 105}, {user = 1...