instruction
stringlengths
35
29.1k
I am getting more and more familiar with the whole concept of time complexity but I have never encountered an example where more than one parameter is involved. Therefore, is it possible(well, I am sure it is :")) and how to prove a^n = Θ(logn) or any other, similar-looking expression? c1 * logn ≤ a^n ≤ c2 * logn w...
For circuits with $n$ input bits, we know that, for any function $s$, there are at most $O(s(n)^{s(n)}) = O(2^{s(n) \log s(n)})$ circuits with size at most $s(n)$. Say two circuits $C_1$ and $C_2$ are different if the function they compute is different, that is, there is an $n$-bit string $x$ such that $C_1(x) \neq C_2...
What are the limitations of the Symbolic Model Checking? As far as I know, "state-space explosion" can still happen by this technique but it can explore much larger state space. So, is the Symbolic Model Checking always better than the conventional model checking? If not, when to apply which one? By the conventional m...
Given directed graph $G = \langle V, E \rangle$, such that some vertices are red, and some vertices are black, and some edges are blue or green, decide for all vertices $v \in V$ if there is path from $v$ to some red vertex with alternating edge colours (no edges of same colour are adjacent in the path, e.g. blue -> gr...
I don't understand the highlighted text below in CLRS 3rd Ed.: I'm not sure I even understand what the sentence is trying to say. For example: What do they mean by "... operations containing $\mathcal{O}(m)$ INSERT operations"? Which operations contain which? If the (total) expected time is $\Theta(n)$ how can any o...
I have been assigned the min-coin change problem for homework. I have to calculate the least number of coins needed to make change for a certain amount of cents in 2 scenarios: we have an infinite supply of coins and also where we only have 1 of each coin. I was able to quickly implement the solution for the first scen...
I believe primary clustering is a problem with the linear probing method of hash collision resolution. But the description makes it sound like there can be multiple clusters of contiguous blocks. I thought there could only possibly be one block, since linear probing will go through all addresses sequentially?
int n = 1000; int cnt = 0; for (int i = 0; i < n; i++) cnt++; Is the above code O(n) or O(1)? If I run the above code many times, it still iterates 1000 times. I'm really confused. I assumed it's O(1), but I'm not sure about it. Could anyone verify this?
See below a screenshot from CLRS 3rd Edition (Section 11.5, "Perfect Hashing"). The last sentence of the last paragraph says that the choice of $m_j = n^2_j$ leads to collision-free constant-time lookup. Why? Is it because: It assumes that one could, in theory, try or sample several hashing functions $\mathcal{h} \in...
I's like to guess the running time of recurrence $T(n)=3T(n/8)+n$ using iterative-substitution method. Using master theorem, I can verify the running time is $O(n).$ Using subtitution method however, I arrive at a different answer than expected.. $T(n)=3T(n/8)+n\\ =3T(3T(n/8^2)+n)+n=3^2T(n/8^2)+3n+n\\ =3^2(3T(n/8^3)+n)...
Jump search is a search algorithm for sorted lists which runs in $O(\sqrt n)$ time, but has the advantage of only making backwards steps at the end (and given the ability to make arbitrarily long backwards steps, guarantees only a single backwards step); thus, it may be preferable to binary search if reverse traversal ...
Let $A$ be an input alphabet - a finite set of symbols. Elements of $A$ are called the characters. The alphabet I am interested in is the set of all ordinary letters a, b, c, ..., z. The texts (also called words or strings) over $A$ are sequences of elements of $A$. The length (size) of a text is the number of its ele...
If I have one spanning tree from a connected and undirected graph, how can I generate all other spanning trees of this graph by modifying this spanning tree one edge at a time? All intermediates must also be spanning trees of the graph.
I came across this problem: Show that in every infinite computably enumerable set, there exists an infinite decidable set. As an attempt to solve the problem, I could only think of a proof by construction. Without loss of generality, let the alphabet be $\Sigma=\{0,1\}$. The construction goes as follows, suppose that $...
I came across following in Huffman coding: Minimum Hamming distance to correct up to s errors is $2s + 1$ because that way the legal codewords are so far apart that even with $s$ changes the original codeword is still closer than any other codeword. Then I came across following: Consider dataword length of $m$ bits...
I am looking at this question from LeetCode. There are two solutions to this question - the recursive solution and the iterative / breadth-first traversal solution. My question is in regards to the memory requirements of each solution. In the case of the recursive solution, we are going to be using the call stack. The...
I am solving the river crossing puzzle with 6 participants. You must transfer all the people across the river in this flash game respecting the following rules: The ferry can carry no more than 2 people. Only the Adults (mom, dad and policeman) can operate the ferry. Dad can not be in the presence of the girls w/out Mo...
Well, I have heard that the A* algorithm is optimal and complete. However, when trying to navigate from A to R using A*, it outputs the path, A --> E --> R, although there is a shorter path, A --> M --> R. My question is, is that possible for A* to be not optimal sometimes? if not, what am I doing wrong here? Any helpf...
Let $G$ be a non-empty connected undirected graph, which is not a complete graph. We treat $G$ as a set, writing $G \setminus \{v\}$ for vertices $v$, etc; subsets of $G$ should be understood as induced subgraphs. A set $S \subseteq G$ is called a separator if $G \setminus S$ is a disconnected graph. A separator $S$ is...
Are there alternatives to uniform grid spatial partitioning when considering data structures for data with nullable or missing coordinate values? For example with uniform grid spatial partitioning it is fairly trivial to extend it to allow nulls: Given a point P in nullable R3, (x?, y? ,z?), like (5, null, 1) we can a...
Having a hash quickly accessible in a large database is a good thing, most hashes these days are much too large for that. Best performance on a database is 32 bit int followed not too far off by 64 bit int keys but accessing a MD5 key already comes with a noticeable performance hit and requires (more than) twice the me...
This is actually a problem that our professor gave us, and I'm clueless of how to answer this. I browsed through various sources, but none were helpful regarding this question. The question is, In the definition of semantics of logic, P implies Q is defined as true under the assignment of both P and Q are false. Alt...
I read the following in CLRS 3rd Ed: I'm not sure I understand exactly how to avoid this pitfall. How would one know that the $\mathcal{O}$ notation in this case grows with $n$ and is thus not constant? What's a good way to systematically avoid this type of pitfall?
Say you have a graph like a — b — c | | | e — f — g and you would like to find the cycles c1, {a,b,f,e}, and c2, {b, c, g, f}, but not c3, {a, b, c, g, f, e}, because c3 is not "basic" in the sense that c3 = c1 + c2 where the plus operator means to join two cycles along some edge e and then drop e from the graph. ...
I was wondering if the following problem can be solved in asymptotically better time than$ \ O(n \log n)$. Suppose you have an array of integers $a_1,a_2,a_3,\ldots,a_i,\ldots,a_n$ where initially for all $i$,$ \ a_i = \mathrm{INF}$. Now, we will iterate over every element starting from $i = 1$ to $i = n$ and perform...
Everywhere, one grammar is used as an example table-driven LL(1) parser. Grammar S -> E | (epsilon) E -> TE' E' -> +TE' | (epsilon) T -> FT' T' -> *FT' | (epsilon) F -> NUM | (E) With this grammar you can only add and multiply. I wanted a little more so added subtraction and division operations. my Grammar S -> E | (e...
I have spent a lot of time understanding these two issues. If you can help me, please. Prove that the restriction of SAT to CNF formulas in which each variable xi appears at most twice is solvable in polynomial time. Prove that the restriction of SAT to CNF formulas in which each variable xi appears at most three time...
I saw a Computerphile video explaining how a simple circuit could store memory using some logic gates. However, I couldn't wrap my mind around how one could find the value of q if one needs not, which in turn needs q, etc. EDIT: q is the output of a logic gate and at the same time the input of another logic gate. not ...
I recently found out that OOP classes turn out to be F-coalgebras: https://www.semanticscholar.org/paper/Objects-and-Classes%2C-Co-Algebraically-Jacobs/c7c45abf7d99e0aef627fd5223023bf82e70dc71 The coalgebraic perspective on objects and classes in object-oriented programming is elaborated: objects consist of a (uniqu...
The 3-SAT problem is NP-complete, meaning that no known algorithm can provide an exact solution in polynomial time, while a solution can be tested very quickly in polynomial time. My question is, if asking for an algorithm that only provides yes/no, or solvable/not solvable, without providing an exact solution of the...
Say that a graph, $G = (V, E)$ has 2 minimum spanning trees (MSTs). Given this condition stipulated, prove that any cycle formed by all the edges in both the MSTs (i.e., the union of the edges in of the 2 MSTs) that at minimum, 2 of the edges in the set which is the union of the edges have equal weight. Also s...
Consider the following algorithmic problem: Given a list of strings $L = [s_1, s_2, \dots, s_n]$, we want to know all pairs $(x,y)$ where $x$ is a subsequence of $y$. We can assume all strings are of length at maximum $m$, where $m << n$ and are all over a finite alphabet $\Sigma$ with $|\Sigma| << n$. We may also ass...
I have a sorted array of integers [x, ..., n, ..., y] so that x > 0 n - x = random positive integer The array might look something like this: [1, 2, 3, 15, 16, 17, 120, 121, 122, 123, 124, 125, 126, 127, 210, 211, 212, 213, 214, 215] I want to divide this array into segments so that, 1) The difference between last an...
I came across this problem which says that given disjoint sets $A$ and $B$ s.t $\bar{A}$ and $\bar{B}$ are both computably enumerable (c.e.), there exists a decidable set $C$ s.t. $A \subseteq C$ and $C \cap B = \emptyset$. I think one way to construct $C$ is to show that $\bar{A}-\bar{B}$ is c.e., but is the set diffe...
Existential second-order logic (ESO) formulas have the form $$\Phi = \exists R_1 ... \exists R_k. \phi$$ where $R_1...R_k$ are relation symbols and $\phi$ is a FO formula, which can use the relation symbols $R_1...R_K$ as well as other relation symbols. My claim is that $\Phi$ is satisfiable if and only if $\phi$ is s...
It's known that: $$ \textrm{CLIQUE} = \{(G,k): \mbox{G has a clique of size } k\} $$ is $\textrm{NP-C}$, but what if every vertex has 2 neighbours (as defined in $\textrm{2d-CLIQUE}$)? $$ \textrm{2d-CLIQUE} = \{(G,k): \mbox{every vertex in G has exactly $2$ neighbours and $G$ has a clique of size } k\}. $$
Consider the positive integers {1, 2, 3, 4, ...} and the corresponding Integer Number Line. Suppose we have four integer numbers, A, B, C and D. For example: _________________A___________________________B__________________ ___________________________C__________D_________________________ or _________________A__________...
I have computed the average code length using the Huffman encoding. Now, I am asked to compare the average code length with Absolute limit but I ain't sure about the absolute limit here is :( Could someone assist me here with the what the absolute limit ??
$Q=\left\{q_{0}, q_{1}\right\} \times\{0,1, \cup\} \times\{0,1, \cup\}$ What does this mean ? Is it just for saving values in a state?
I want an algorithm which generates random integers, without replacement, from a large range [0-N], N~10^12. However, the whole range should not be stored in memory. The memory footprint should be O(1) relative to N. The algorithm can (probably must) retain state after every sample request. The randomness should be "st...
I need to construct a DAG, from its given topological orderings (i.e. the graph $G$ created must have all the orderings given as its topological orderings). For simplicity, the vertices are labeled as first $n$ natural numbers. (Note that once created, the graph $G$ may have more topological orderings apart from the on...
One of the properties of Red Black trees is: "every path from a given node/vertex to any of the leaves goes through the same number of black nodes" Two related questions about this property: 1) is the vertex we start at counted in this black vertex count? 2) is the leaf we end at counted in the black vertex count? I...
Given a set of nodes, with connections in certain directions (see image), what is the most coins you can collect between the first and last given node. Not all rooms have coins, and we want to output the path taken, as well as total coins taken. You may only travel in the direction of the arrows. We are allowed to take...
I need to create a deterministic finite automata whose language consists of words over $\{0,1\}$ of any length, satisfying the following constraint: Among any subsequent 3 numbers, there needs to be exactly two 1s, and exactly one 0. I've spent a couple hours studying DFAs, but I can only find solutions like the one ...
This is actually a question my lecturer gave us, so I know that it's kind of homework, but I tried to answer this and still had no luck. The question is Give English description of the languages of the following regular expressions. $(1+\epsilon)(00^*1)^*0^*$ $(a^*b^*)^*aaa(a+b)^*$ $(a+ba)^*b^*$ I could only gue...
I do not understand this question,because for saving Number of a's and b's memory is required,which FA does not provide.could anybody please explain this?
Assuming we have $\sf P = NP$, how would I show how to solve the graph coloring problem in polynomial time? Given a graph $G = (V,E)$, find a valid coloring $\chi(G) : V \to \{1,2,\cdots,k\}$ for some $k$ satisfying the property that $(u,v) \in E$ implies $\chi(u)\ne\chi(v)$ so as to minimize the fewest number $k$ of “...
The problem is stated as the following: We are given a grid graph $G$ of $N \times N$, represented by a series of strings that describe vertices s.t. $L$ is the vertice we're interested in $P$ are vertices that are unavailable $.$ are vertices that are available e.g.: .... ...L ..P. P... Would mean a graph that ...
I would like to know if there is a linear-time algorithm ($\mathcal{O(n)}$ time) to convert a Complete Binary Tree with data left-to-right increasing stored in external nodes, to a Priority Search Tree. By conversion, my aim is to create a "Priority Search Tree" with all of the elements of some "Complete Binary Tree", ...
Why is $\log_{2}n = O(n^{0.00001})$ true? This is obvious to me when the exponent is $> 1$ but i'm having trouble understanding the cases where the exponent is very close to $0$. I would have to find some constants $c$ and $n_0$ where $\log_{2}n \le cn^{0.00001}$ for all $n \gt n_0$. Where I'm stumped is that $n^{0.0...
Let $E$ be an equivalence relation defined over a set $S$. The access to $E$ is only via queries of the form $M(s_1,s_2) = 1$ if $s_1$ and $s_2$ are in the same class and $0$ otherwise. Computing $M$ is expensive (say, $O(n^2)$). I am looking for an efficient data structure $D$ that supports queries of the form "given ...
Given a metric space $X$ with finitely many points, and a nonnegative integer $n$, I want to find a set of $n$ points in $X$ which maximizes the minimum distance between any two points. What algorithms are there to do this?
Given a directed, acyclic graph in which each node has an assigned integer score, what is a fast way of finding the path from a start and end vertex with the highest cumulative score? I thought of a DFS approach in which we start at the end and run the graph in the reverse way, saving at each node the best cumulative s...
In Introduction to Algorithms, Lemma 4.4 of the proof of the master theorem goes like this. $a\geq1$, $b>1$, $f$ is a nonnegative function defined on exact powers of b. The recurrence relation for $T$ is $T(n) = a T(n/b) + f(n)$ for $n=b^i$, $i>0$. For the third case, we have $f(n) = \Omega(n^{\log_ba +\epsilon})$ for ...
Small-world networks have two properties: clustering coefficient and average node-to-node distance my questions are: 1- Can a disconnected graph ( which may include multiple connected graphs) hold a small network property? 2- If a graph holds a small "average node-to-node distance" (around 4) but has a low clustering C...
Design a DFA over alphabet (a,b) such that for all it's string no prefix contain two more a's than b's and two more b's than a's and the number of a's is equal to b's. Is it possible to design a DFA in such special cases of number of a's being equal to b's ,as it is not possible to make a DFA for the general case of a'...
Actually it differs from CPU to CPU but it is possible to choose a mainstream CPU technology used in moderate servers or home computers. How many clock cycles it takes to read a file of 50KB from Ethernet socket and then resend this file to another IP address without saving the file to disk? I assume this operation can...
Let the problem of the diophantic equation 0/1 be as follows. Input : A polynomial equation on n variables whose coefficients are integers (ex : $2x^3_1 x_2 + x_1x^3_3 - 3x_4 = 8$) Question: Does this equation have a solution in space {0,1}$^n$ ? (can we satisfy the equation by choosing for each variable the value 0 or...
Let $T$ be a tree with $V$ and edges $E$. Let a linear arrangement $\pi$ of $T$ be a bijective mapping from nodes to integers in the range $\{1, \dots, |V|\}$. You can think of $\pi$ as defining the position of each node in an arrangement on a line. Now define the length of an edge $E = \{u,v\}$ in $T$ under $\pi$ to ...
I was working on a project and am stuck in the middle unable to find an optimal method to solve this problem. Consider an array $A$ of $n$ elements. I have to choose $k$ elements such that the sum of indices is maximal under the constraint of being less than a given element $x$. My approach for this is the naive $O(n^k...
notation: $x+y:=\mbox{OR}(x,y)$, $\bar x:=\mbox{NOT}(x)$, $xy:=\mbox{AND}(x,y)$, 1:=TRUE, 0:=FALSE. Let $f$ be a Boolean function of $n$-variables, i.e. $f: \{0,1\}^n \to \{0,1\}$. minterm:= any product (AND) of $n$ literals (complemented or uncomplemented). e.g, $x_1 \bar x_2 x_3 $ is a minterm in 3 variables $\mbox...
In our exam on algorithms there was a question, where given 3 hashfunctions we had to chose one and explain why it's the best. h_1(x,i)=(x+5*i) mod 1000 h_2(x,i)=(x+17*i) mod 1000 h_3(x,i)=(x+32*i) mod 1000 I am really unsure about this, but I suspect that it is the second one, because it can "hit" more values. If I ch...
To what extent is the abstract model of computation specified by the x86 language Turing complete? The above question is related to this question: Is C actually Turing-complete? In theoretical computer science the random-access stored-program (RASP) machine model is an abstract machine used for the purposes of algorith...
Let $L = \{\alpha\in\{a,b,c\}^{*} \mid \alpha \text{ is palindrome}\}$, show that $L$ is not regular using Myhill-Nerode relation. I don't know how to show that $L$ has infinite equivalence classes because $\alpha$ is a palindrome. I tried to use something like this, but I don't know if its correct: $\alpha \equiv_{L} ...
The variables $a,b,c \in \{0,1\}$, thus $a^k, b^k, c^k \in \{0,1\}$ I want to pass a query to an oracle that returns the coefficients of each term $(1,a,b,c,ab,ac,bc,abc)$ in the expansion of products such as this one $(1-a+ab)(1-b+bc)(b-bc)$. There could be more variables and more brackets to expand. Do I require a si...
Here is a (slightly abridged) problem from Kleinberg and Tardos: Consider a complete balanced binary tree with $n$ leaves where $n$ is a power of two. Each edge $e$ of the tree has an associated length $\ell_e$, which is a positive number. The distance from the root to a given leaf is the sum of the lengths of all th...
I hear that register is in CPU, but the CPU iamge I generally see doesn't mark the position of register, can anyone provide a real image of CPU with mark of register (for example 32 registers in MIPS)? CPU image example , but not marking register position. Another site with 3D CPU Model also without register position....
I'm trying to better understand Question 24.3-4 From CLRS below: Professor Gaedel has written a program that he claims implements Dijkstra’s algorithm. The program produces $v.d$ and $v.\pi$ for each vertex $v \in V$. Give an $O(V + E)$ algorithm to check the output of the professor’s program. It should determi...
I'm currently considering deterministic, nondeterministic, universal, and alternating automata over infinite words and trees, with Büchi, co-Büchi, Muller, Rabin, Streett, or parity acceptance conditions. I know that over words, all these automata accept the same languages, except deterministic and universal Büchi auto...
I'm learning about logic circuits and I've come across full adder. In the book they derived its two carry out expressions - Cout = x&&y || x&&z || y&&z and Cout = x&&y || (x'&&y || x&&y')&&z I've tried to get the second equation from the first one but couldn't. Any one knows how to do that?
I am completing a university exercise deciding whether big notations are true or false. I am stuck on this question : $$3^n = 2^{(O(n))}$$ I want to answer False as the format looks incorrect and I have never seen big O notation written is this way. Is this a valid way to write big O notation?
I'm having some difficulty understanding/being convinced the technique used to prove a greedy algorithm is optimal for the fractional knapsack problem. A proof by contradiction is used. I've never been great at proofs, and maybe this will help me get on the track to becoming more comfortable with them. Consider sectio...
I proposed an algorithm and I want to prove its optimality. It is not a greedy algorithm. I have the whole searching space $\mathcal{S}$ and I only search inside a subset of this searching space $\mathcal{C} \subset \mathcal{S}$ and exclude the remaining search space. I know the logic behind excluding this should not v...
I am researching on AI and its working. Whenever I try to search for AI algorithms, ML algorithms come up. Then, I read the differences between ML & AI. One of the key points mentioned was "AI is decision making" & "Machine learning is generating values and learn new things". I come up with a conclusion that ML allows ...
In general, we have these types of NAND flash cells: SLC, MLC, TLC, and QLC. Since MLC flash cells can store 2 bits, the content of the cell can be 00, 01, 10, or 11 which are detected using different threshold voltages. Each 4KB flash page includes 32768 bits and, thus, 16384 MLCs. So, the content of a page might be a...
There is a database of, let's say, 500k English two-word combinations (e.g. "clover arc", "minister horse"). I can search for an arbitrary string and I will get a list of the alphabetically first 1000 entries containing this string; the time each query takes is proportional to the number of results it returns, plus som...
wikipedia states: Every Post canonical system can be reduced to a string rewriting system (semi-Thue system). [...] It has been proved that any Post canonical system is reducible to such a substitution system, which, as a formal grammar, is also called a phrase-structure grammar, or a type-0 grammar in the Chomsky hie...
I am trying to get a binary string that has been converted from text of a text file, I am able to get that but the problem is, I need each character to be represented by same number of bits, but that is not what I get (please see the below python code and corresponding output). For example, character i is represented b...
I am currently solving a question that asks which of the following functions can be calculated in polynomial time: $$n!, \binom{n}{5}, \binom{2n}{n}, n^{\lfloor \lg n \rfloor}, \lfloor \sqrt{n} \rfloor, \text{the smallest prime factor of } n, \text{the number of prime factors less than }n.$$ In proving the first one, ...
I'm given an array $A = [a_1, a_2, ....a_n] $ using which I construct $n-1$ contiguous line segments by drawing a line from $(i,a_i)$ to $(i+1, a_{i+1})$. Now, I'm given $q$ queries in the form of $x_1, x_2, y, l, r$ where $l$ and $r$ are the range for the array $A$ and the rest indicate a horizontal line segment $L$ ...
I know we can find all articulation points efficiently in a graph using DFS. But what if not all nodes need to be connected, but instead we have set of node pairs that need to communicate (there is a path between them). How to efficiently find all nodes (vertices) which removal will cause at least one of the mentioned...
I am new to CS, and learning asynchronous transmission. Asynchronous Transmission typically also uses SYNC word/bits to provide occasional time stamp for receiver to synchronise its clock to the transmitter clock. Could anyone explain more specifically how time stamp synchronizes the transmitter and receiver cloc...
I am interested in efficient ways of doing certain problem. I have list of $n$ pairs, where $n$ is usually a few houndred thousands and each pair's element is an integer (let's assume it is integer from $0$ to $10000$) and I am trying to find a sequence such that it start and ends at chosen integer (we can assume it i...
We are given directed weighted graph with edges having strictly positive weight(>0) with possibly some cycles with $N$ nodes and $M$ edges. Let's observe all the shortest paths from $1$ to $N$ in this graph, finding the single-source-shortest paths from $1$ in the normal graph and the single-source-shortest path from $...
I am working from presentation from school, but I am not able to understand how they go from one step to the other. This is the decision table that I have. From it, the first thing we have to do is to choose the root node among these nodes: But I do not understand why for example from Q1 the Y branch has a1, a2 and t...
Consider the counting function $\{x\}^* \rightarrow \mathbb N$ that counts the number of occurrences of the symbol $x$. I am confused about the (asymptotic) complexity of computing this function, where the output should be represented in a non-unary system (e.g., binary). My intuition strongly suggests that this shoul...
Suppose a simple program is reading messages from a distributed cluster. The cluster has 3 partitions, and the program has three readers that are assigned one partition each (The setup will always be x partitions connected to x readers, where x can be 3, 4, etc... Each reader handles a specific partition alone. Hence,...
I am having trouble coming up with the space complexity of the TSP algorithm. https://www.geeksforgeeks.org/travelling-salesman-problem-set-1/ To me the space complexity for the brute force is the cost of storing all possible permutations right ? That should take space O($N!$) where N is the number of cities/nodes/ver...
The Box Stacking problem is as follows: You are given a set of $n$ types of rectangular 3-D boxes, where the $i^{th}$ box has height $h_i$, width $w_i$ and depth $d_i$ (all real numbers). You want to create a stack of boxes which is as tall as possible, but you can only stack a box on top of another box if the ...
I have yet to find an un-journaled filesystem that can be resized without data loss or intermediate conversions, and I'm wondering why that is. Filesystems like FAT, for example, leave free space at the end of the block device; it seems pretty simple to me to just add more free space onto the end... Edit: It seems that...
Suppose you have a connected graph and want to remove k nodes such that the result is still connected. How could you do this efficiently? It occurs to me that you could find any spanning tree, say by a tree search of any kind. Identify all leaves in the spanning tree, all of these can be removed without disconnecting...
I found this pseudocode on Wikipedia, and looks very elegant and intuitive: L ← Empty list that will contain the sorted nodes while exists nodes without a permanent mark do select an unmarked node n visit(n) function visit(node n) if n has a permanent mark then return if n has a temporary mark ...
I'm looking for an intersection algorithm for finding the intersection points of two arbitrary mathematical curves. Websites like Desmos, GeoGebra, and WolframAlpha allow you to graph and/or input two(Or more but I'm only interested in two) curves to find their intersection points. I know all of the services I've liste...
I know that P is a subset of NP, but I'm not sure what this tells me about P as it relates to coNP? I feel like this is how I should go about proving it, but I'm not sure how. Otherwise, I could find a language that is in both NP and coNP, but I'm not sure how to prove any examples of that. I know that I can prove L an...
I am trying to solve an equation which I believe cannot be done analytically, but can use a numerical approximation to get a result. The equation is: $$\frac{2*\sqrt{\pi}*h*s*e^{m^{2}/(2*s^2)}}{\sqrt{2}} = a$$ where $h, m,$ and $a$ are given constants. This is for a project that I'm writing in Java, and it would be inf...
I had been going through dynamic programming concepts and happened to read about text justification problem in which the spaces to the right of the line end are penalized with cubic times the number of spaces. The algorithm also works with quadratic times number of spaces as penalty. I have couple of questions 1) Any i...
From the picture, the automata can accept $(\text L|\text D)^*$ following say $\_\text L\text D$, but in the formula above $(\text L|\text D)^*$ can't follow the $\_\text L\text D$. So the Automata in the picture is not equivalent to the RE?
Suppose $A$ is an $n \times n$ matrix, and $k \ge 1$ is an integer. We want to find $k$ distinct indices from $\{1, 2, \ldots, n\}$, denoted as $i_1, \ldots, i_k$, such that $\sum_{p, q = 1}^k A_{i_p, i_q}$ is maximized. In words, we seek $k$ rows and the corresponding $k$ columns, such that the intersected $k^2$ el...
I wrote an algorithm for a leetcode question. The question asks: Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node's descendants. The tree s could also be considered as...
I have an hybrid compression technique I want to implement, my implementation is (so far): I can encode a string into a encoded compressed string. These are binary strings. For example, I read texts from a text file -> then convert it to a binary string -> then convert it to an encoded binary string. At this point, I...