instruction stringlengths 35 29.1k |
|---|
If $L_1 \in \mathsf{P}$ and $L_2 \in \mathsf{NP-Complete}$ and $L_3$ is the symmetric difference between $L_1$ and $L_2$, is $L_3$ also in $\mathsf{NP-Complete}$ necessarily?
I'm pretty sure the answer is no but I can't find even one example that shows I'm right.
|
Given a connected graph $G=(X,E)$ with positive edge weights. We assume that $G$ contains a unique min weight spanning tree $T_{\min}$ (this is true for example when for all the cuts, the edge with the minimum weight is unique). What is the necessary and sufficient condition that insures that the following holds:
There... |
I can't seem to find the explanation for why all r-type instructions have opcode 0 always. Can anybody explain why this is so.
|
Here is the algorithm in pseudo code:
Where $A$ is the array to search, $p$ is the starting index in the array, $r$ is the ending index and $i$ represent the number of smaller values we want from our goal value, the $i$ smallest number in the array.
I dont understand the $k$.
It gets a value that dont realy represen... |
The knapsack problem is NP-hard and can be formulated as:
$$\begin{align}&\text{maximize } \sum_{i=1}^n v_i x_i,\tag{P1}\\&
\text{subject to } \sum_{i=1}^n w_i x_i \leq W,\\&\text{and } x_i \in \{0,1\}.\end{align}$$
What if $v_i=i$? Is it still NP-hard?
$$\begin{align}&\text{maximize } \sum_{i=1}^n ix_i,\tag{P2}\\&
\te... |
It's claimed in Wikipedia that:
F-bounded quantification or recursively bounded quantification,
introduced in 1989, allows for more precise typing of functions that
are applied on recursive types. A recursive type is one that includes
a function that uses it as a type for some argument or its return
value
Her... |
I am trying to find an algorithm which finds the least expensive route from one town to another.
This is the general setup.
There are a series of one-way roads from some towns to other towns. Not all towns have roads between them. Let R be the set of all the roads and let T be the set of all towns. For two towns u, v ∈... |
For a homework assignment I am asked to provide claim sequences to verify that the given conditional does indeed satisfy its specification (to compute in r the absolute value of x).
val x: Z = readInt()
var r: Z = x
l"""{ 1. r == x premise }"""
if (x < 0) {
l"""{
1. x < 0 premise
... |
This question is given as an exercise to me . I took a look at the solution given by the instructor which is not the same as my solution .
So I thought it would be wise to ask it here considering I am a newbie on that topic.
My solution basically is as follow :
S -> aSa | bSb | aTb | bTa
T-> aTa | bTb | aTb | bTa... |
In CLRS, Section 33.1, we are given the any-two-segments-intersect algorithm. It's a cool algorithm for sure but going through the correctness proof, I don't know how they arrived at the following conclusion:
"Given that we have two segments (call them $a$ and $b$) that intersect at some point $p$, then there must be s... |
Are there any existing proofs involving a reduction of the single machine scheduling problem (in any of its forms really) from vertex cover in order to prove its NP-hardness?
Particularly looking for a proof that does not involve linear programming (if it exists).
|
I know that I cannot use Floyd's algorithm if I have a graph with at least one negative cycle, because
path-lengths between vertices can be arbitrarily small.
I am wondering, how the distance matrices at each iteration of $k$, where $k=0, \dots n$ will look like.
I now that there will be negative numbers on the main... |
A "general" Boolean (combinatoiral) circuit is a labeled (with the labels: AND, OR, NOT, IN, OUT), directed, acyclic graph, that satisfies:
fan-in=2 for the AND and OR nodes
fan-n=1 for the NOT nodes
fan-in=0 for the IN nodes
fan-out=0 to exactly one node (the OUT node)
Unbounded fan-out to the rest of the nod... |
In classical computers we have List,Queue,Tree & etc data structures, since classical computers using 1's & 0's on those data structures. Then what happens when it comes to quantum computers,
Do they(computer scientists) need to create new data structures ?
Or use existing data structures with some sort of optimization... |
I read that a reasonable encoding of inputs is one where the length of the encoding is no more than a polynomial of the 'natural representation' of the input. For instance, binary encodings are reasonable, but unary encodings are not.
But say that the input is a graph, and its natural representation is a vertex and edg... |
A "general" Boolean (combinatoiral) circuit is a labeled (with the labels: AND, OR, NOT, IN, OUT), directed, acyclic graph, that satisfies:
fan-in=2 for the AND and OR nodes
fan-n=1 for the NOT nodes
fan-in=0 for the IN nodes
fan-out=0 to exactly one node (the OUT node)
Unbounded fan-out to the rest of the nod... |
Can someone help me calculate the time complexity of the algorithm?
I have an array and I want to check if it's sorted or not I start in the middle of it and I check the numbers first to the right and after that, I check it to the left.
I check it with a variable and that variable increases by 1 every time so it starts... |
I get the impression it has to do with either some quirk involved with limiting to 2^8 or that I'm misunderstanding what addition can be within the context of a finite field, but I'm not quite sure why it's described as 'addition' in the literature I read but the code I see implements it with XOR.
|
My understanding of free objects is: Free functors, free applicatives, free monads, free monoids, &c, give you more structure "for free", i.e. in general, or for all some thing with less structure, you can have more for free. For example, the free monad give you a monad instance for any type with a functor instance, ev... |
Given a collection of finite sets, is there an algorithm for finding the set (unordered) of all systems of distinct representatives for the collection?
Example:
S: {{1, 2}, {1, 2, 3}}
Unordered SDRs: {{1, 2}, {1, 3}, {2, 3}}
Notice that {2, 1} is already counted by "{1, 2}" as the SDRs are unordered.
System of Distinct... |
I am aware ML is not necessary for many graph classification problems (as the graph theorists have many clever solutions), but I'm specifically interested in ML approaches to these types of questions. I imagine if you had enough training examples (1000s?) you could use a supervised approach for classification type of q... |
Are there in any relatively efficient known algorithms to compute the partition function $P(n)$ for a given $n$? What's known about the complexity class of this problem as a function of $n$?
Perhaps I'm missing something trivial here, but other than listing some recurrent definitions of this function and some of thei... |
We have a set of possible "key"s $S$ represented by bitstrings of length $k$. In other words, $S$ contains an arbitrary subset of all bitstrings of length $k$. For example, when $k=3$, it can be $S = \{001, 010, 011, 000, 111\}$. I would like to find a "guess", which maximizes the Hamming distance of itself and the pos... |
Can someone explain (or provide a reference for) how to show that uniform circuit families can efficiently simulate Turing machines? I have only seen them discussed in terms of specific complexity classes (e.g., $\mathbf{P}$ or $\mathbf{NC}$). I would like to see how uniform circuit families is a strong enough model fo... |
I have been trying to come up with an efficient algorithm for the following problem.
Let $G = (V,E)$ be an undirected acyclic weighted graph, where there is exactly one path from a vertex $u$ to any other vertex $v$.
Let $S \in V$ be a set of vertices from $G$.
$|S|$ is the size of the set.
$0 \leq |S| \leq |V|$.
Spli... |
I am looking for an algorithm that fills a given region of connected particular nodes in minimum time. I have tried using flood flow algorithm but it's too slow and inefficient for large array, it checks each pixel more than once. Is there any algorithm that is more efficient than flood flow algorithm.
If that helps, ... |
I have tried to find and print more than one successive shortest paths between two vertices in the undirected graph. Using BFS as DFS will not be optimal in this case, as it can go deep into the stack.
Wrote this function but not getting the correct response and also tried to find help over StackOverflow and other plat... |
In Introduction to Algorithms (CLRS), Exercise 33-1-1, we are asked to prove that if $p_1 \times p_2$ is positive then $p_1$ is clockwise from $p_2$ and if it's negative, then $p_1$ is counter-clockwise from $p_2$.
This is a picture from CLRS
I found the following proof:
https://sites.math.rutgers.edu/~ajl213/CLRS/Ch3... |
We know that the lower bound is the minimum amount of work needed to solve a problem. So for a given problem say x it has the best algorithm ( the most efficient algorithm to solve this problem ) say algorithm y, then the lower bound efficiency calculated from this algorithm y is the least time this problem x can be ... |
Problem: Find an O(E + V) time algorithm that outputs the vertices of a cycle of G, if it exists. If G has no cycles, the algorithm outputs no cycle. So if there is a cycle 1, ... 3, 1, it would print 1, ..., 3, 1.
So I was thinking of doing a BFS, and if the currently examined vertex's neighbor v has been visited prio... |
I have a collection of intervals and I want to sort them so that the order is interpreted as a sort of "z-index". That is, a given interval may or may not be "visible" depending on whether the merge of the intervals to its left (i.e. preceding it in the given order) contains it.
I am looking for an algorithm to search ... |
For a practical task, we are asked to provide the transition table for a Turing machine that validates the number of open brackets is equal to the number of closing brackets.
The only tape symbols allowed are ( ) E B
If the number of brackets is equal (opening brackets = closing brackets) then the machine must halt in... |
I often encounter these terms, seemingly bearing same semantics and meaning. I'm almost sure they mean same - the types of Algorithms categorized based on their implementation strategy/paradigm.
Just wondering if I'm right and I get this correct, because, again - in different books/courses these terms are encountered i... |
I need help how to interpret the following notation for $f$:
Zeroes and ones form a binary number which can be converted to
decimal notation. Thus, we may think of the computer as calculating a function
$$
f:\{0,\dots, N-1\} \rightarrow \{0,\dots, N-1\},
$$
where $N$ is a number of the form $2^n$, and $n$ is th... |
I have been assigned some homework in uni, related to push-down automatons (evaluated via final state, not empty stack) and context-free grammars. I have noticed that questions related to generating push-down automatons from context-free grammars are not always phrased in the same way, with mostly two variations:
For ... |
Given a list of intervals with nonnegative endpoints, e.g. $ [3,5][1,7][2,60] $, the goal is to find the number of pairs of intervals $I,J$ such that $I$ is a subset of $J$.
In this particular case the total number is 2 because $[3,5]$ is a subset of $[1,7]$ and a subset of $[2,60]$.
Furthermore we were asked to find a... |
We are provided with the following verifier of primality:
Verifier for prime
Input: integer n ≥ 1
integer d
if 1 < d < n and d divides exactly n then
return ’no’
else
return ’yes’
But the answer is that it is wrong:
Note that in order to be a verifier it is required that for every n, n
is a positiv... |
Say I have a dataset of n vectors. These are, by nature, clustered so that there is a significant distance difference between any two points within a cluster and any two points in separate clusters.
I want to create a single centroid per single cluster. However, I cannot initially know how many clusters there are - thu... |
Suppose there is $N$ property. Each property is owned by multiple person. (they have shared ownership) For example: $Person_1$ owns 22% of $Property_1$, $Person_2$ owns 35% of $Property_1$ and $Person_3$ owns 43% of $Property_1$. Also every person has shared ownership in multiple property. The number of persons is $M$.... |
In Trivial lower bounds we just need to count the number of items in the input that needs to be processed and the number of items that need to be generated and the trivial lower bound time is then the sum of these two found numbers. My question is , we know that the time complexity = number of times the basic operation... |
How to find the longest path with the sum $0$ in a weighted tree (where each edge is labeled with an integer weight)?
In other words, I want to find a path so that the sum (sum of numbers on edges) is equal to zero, and the amount of edges along which I went is the maximum.
|
The first line on the Wikipedia page for basic feasible solutions reads, In the theory of linear programming, a basic feasible solution (BFS) is, intuitively, a solution with a minimal number of non-zero variables.
I do not understand this, I could always have the origin within a convex polyhedron, but it is not necess... |
CNN use convolutions to perform many tasks. In some architecture, the first layer(s) are basic filters such as Gabor's. Many CNN work by stacking a number of convolution layers to build detectors which are more and more complex.
Now, it's clear that filters are typically learned and that, at a given depth, usually full... |
I'm a little confused about how monotone priority queues work.
As far as I understand:
A queue is a FIFO data structure
A priority queue is a queue where the current element of highest (or lowest) priority is served before an item of lower (or higher) priority
Now, for monotone queues, I read the following on Wikiped... |
why don't we put a network card or usb adapter to connect to wifi and connect all the computer to the internet without LAN and WAN cables
i may act stupid so please explain it to me my friend
|
Consider the following problem :
Consider the problem of finding the median of a three-element set {a, b, c}.
a. What is the information-theoretic lower bound for comparison-based
algorithms solving this problem?
b. Draw a decision tree for an algorithm solving this problem.
The answer of this problem is shown below ... |
Given a uni-weighted graph G (in which each edge has the capacity of 1), and we have k extra capacities (k is an integer) that we can spend on any subset of existing edges. That is, we can increase the capacity of any existing edges but all increases should sum up to k.
How to improve the max (s,t) flow as much as poss... |
I have a graph in which there is a set of leader vertices $L$. There is no edge between any pair of leader vertices. Each leader vertex $u$ has a common set of colours $C$ and a set of neighbour vertices $N(u)$. A leader vertex is oblivious of the decisions of other leader vertices. Each leader vertex picks a colour fo... |
Consider the problem
$\frac{n}{3}$-CLIQUE:
determining whether a graph contains a clique with at least $n/3$ vertices.
I want to prove it is NP-complete using a polynomial transformation from CLIQUE.
How can I approach this problem?
|
I'm kinda new in this topic and I don't know how to figure out the rules to make a CFG out of this language, if anyone could give me an idea or hint so I can try to solve it knowing that, I would be very thankful.
Thank you for yout time.
|
I was trying to improve the algorithm since its the most effective and known algorithm among many others, I came across " Quicksort algorithm with an early exit for sorted subfiles 1987 by University of Tulsa, Roger L. Waiwright" check it out its interesting, do you guys know any other ways/researches ?
I think reducin... |
How to change the constraint's arity from n to 3?
I know how to perform binarization of constraints, explained here: https://cw.fel.cvut.cz/b172/_media/courses/b4b36zui/binarization.pdf, but I don't know how to get a constraint of arity 3.
A ternary constraint is one based on four variables, for example, constraint $C=... |
Suppose we had a domain with two individuals, $x$ and $y$. Suppose we had two predicate symbols $p$ and $q$ and three constants $a$, $b$, and $c$. Suppose we had the knowledge base KB defined by:
$p(X) \leftarrow q(X)$
$q(a)$
How many of these interpretations are models of KB?
So we know that in total there are 128... |
There are two uses of a boolean expression in a language like C, one as a condition in flow of control statements and the other as boolean value in assignment and arithmetic expressions.
I was studying the translation of boolean expressions into three address code from the Dragon Book.
Now, I came across the followin... |
I have read that yacc generates bottom up parser for LALR(1) grammars. I have a grammar for Java 1 that can be used for generating three address code and is strictly LALR(1), but the translation scheme I am employing makes it L-attributed. Now I have read that L-attributed LR grammars cannot be parsed by using bottom ... |
For a mapping between a bit-arrays and values I want cheap lookups using bitwise-or instead of equality.
Slightly more formally, I have a set of associations $k_i \mapsto v_i$ where $k_i \in \mathcal{P}(\mathbb{N})$ is a set of naturals and $v_i$ can be of any type $T$. A query on $q \in \mathcal{P}(\mathbb{N})$ matche... |
I have been trying to find a context sensitive grammar for the language $\{ a^{2n} b^{2n+1} c^{3n} d^{n+3} \mid n \ge 1\}$ for some time but I cannot get it done. Any ideas ?
|
Shift means that you need to put the status and terminal symbol on the stack. But what is the terminal symbol used for? After all, if the reduce command is executed, both the state and the terminal symbol are deleted and the terminal symbol will never be used.
Why not push into the stack only state?
(English is not my... |
In compiler design, control-flow statements are translated to sequences of three-address-code (3AC) instructions a lot of which are jump statements. A 3AC instruction of the jumping type could be an unconditional jump in the form of a goto statement with a target label as its argument, such as
goto L1
or it may be ... |
Suppose I have two 5-digit numbers (A and B) and two 50-digit numbers(C and D). Do the operations A+B and C+D have equal complexity in terms of time and space? or C+D is more complex due to the size of digits?
|
Let $G=(X\cup Y, E)$ be an unweighted bipartite graph. We are given that for every $W\subseteq X$ it holds that $|W|\leq |N(W)|$, where $N(W)$ is the neighborhod of $W$ in $Y$ (aka Hall's marriage condition).
My goal is to find a subset $W^*\subseteq X$ with $|W^*| = |N(W^*)|$, if such a subset exists (obviously it nee... |
I have a single job of unit length, a set of $n$ slots, and a budget of $B$ units. If the job is scheduled at slot $t$, then it will consume $c(t)$ units of the budget $B$. If the job is not scheduled for a period of $x$ consecutive slots, then a penalty of $\lfloor x/2\rfloor$ occurs. The objective is to schedule the ... |
Suppose that we have a group of N bytes. One can add a very basic (and not particularly reliable) check of the consistency of this data by storing an additional (N+1)th byte containing exclusive XOR of all N original bytes. It will be enough to detect a single byte error during the transmission.
In the practical proble... |
Airlines has a new policy to give a first-class upgrade coupon to their customers based on the number of miles accumulated. They decided to give it to their top $\log(n)$ frequent flyers, where n is the total number of the airlines’ frequent flyers. Their current algorithm runs in $O(n \log(n))$ time to sort the flyers... |
I have a min heap.
I need to find the 7'th biggest value in the heap with $O(1)$.
I need to build the algorithm.
I dont realy have an idea how to get to this efficiency.
Help?
Thanks.
|
Hope someone can point me to the right direction to solve this problem.
Premise.
I call quasi-deterministic Büchi automaton (qDBA) a Büchi automaton $B = \langle S, \Sigma, S_0, \delta, F \rangle$, where $S$ is the set of states, $\Sigma$ the alphabet of transition labels, $S_0 \subseteq S$ the set of initial states, $... |
I was reading up on DFA's and their accepted languages when I stumbled across this:
Let a DFA $M$ accept the language $L⊆Σ^∗$, DFA $M'$ accepts $P(L)=$ {$w∈Σ^∗|wy∈L$ for some $y∈Σ^∗$}.
Since any $wy$ has to be an element of $L$ in order for $w$ to be an accepted string, and $L⊆Σ^∗$, then wouldn't all states be accepted... |
Let $H$ be a max binary heap with $n$ elements (vertexes).
Pick a vertex $z$ in the heap with height of $k$ ($0<k<\lg n$)
To every element in the sub heap of $z$ we add the constant value $c > 0$.
We need to fix $H$ to be again a max heap, withour changing the value of the elements in the heap.
We need to do it with... |
Let $A[1..n]$ be an unsorted array, we want to find the $n/lgn$ intermidiate numbers in the array.
Namely the $(n/2)+1$ biggest number and the $(n/2) + 2$ biggest number and so on... until the $(n/2) + (n/lgn)$ biggrst number.
We are studing on the select algorithm and sortings.
I think it should go somehow with sel... |
I have a heap with $n$ elements.
$k$ represent a number that is the height of one of the elements in the tree.
I need to compare two run times and prove what i claim.
The 2 run times are:
$$
(1)O(\lg n \cdot (\lg n - k))
$$
And:
$$
(2)O(2^k \cdot \lg n)
$$
Where:
$$
\lg n - k
$$
Is a constant value.
For the first... |
I need some help to prove that the language is decidable.
$K$ = {$N$ : $N$ is a DFA (Sigma = {a, b, c}) and $L$($N$) contains at least one word in which there is no a}.
It tried to make an algorithm which receives as input a DFA $N$ and which
determines whether or not this automaton accepts at least one word which cont... |
Consider the problem of finding, for a given input array, the longest subarray with at most two different values.
For example:
Input: [3,3,3,1,2,1,1,2,3,3,4]
Ans = 5, the longest subarray would be [1,2,1,1,2].
Input: [1,2,3,2,2]
Ans = 4, the longest subarray would be [2,3,2,2].
Below is dynamic programming solution ... |
Let $G$ be a complete directed graph with $n$ vertices. Each vertex $v$ has a weight $w(v)>0$, such that the sum of all vertex weights is $n$. We have that the edge $e$ from $u$ to $v$ has a weight $0 \leq w(e) \leq w(u)$.
We say that these weights can be balanced, if there exists a directed spanning tree, $T$, and fun... |
I have looked for proof that a machine cannot compute itself in more than realtime (Which would allow infinite computing speed) and I came to the conclusion that it is impossible for any computer to simulate all other computers. However, I lack proof of this intuition.
So the idea is that the state of every (modern, n... |
I hear a lot about how quantum computers are a big thing because they allow solving some problems in polynomial time which we don't know how to do classically. As far as I understand it still isn't fully proven that they can be built in a scalable way. But what about less dramatic speedups? Could we build a computer th... |
I want to implement fast text-search over a Rope data structure. That is, a B-Tree of characters, where the characters are not sorted. (Meaning the standard way to search in a B-Tree by key does not apply.) This data structure is good for making incoherent edits to, but retrieving the character at a given index takes $... |
For a personal learning and fun project, I build an abstract virtual machine based on a stack. The instructions are simple and act on the top of the stack only. There are also stack operators such as SWAP, DUP or ROT. I have no way to manage memory, pointers, or variables (it's all on the stack after all). Typically, h... |
Let $L_1=\{Q,\Sigma,q_0,\delta,Q\}$ be a DFA that accepts a language $L$ and where all the states are also final states. If we want a DFA that accepts the complement of $L$, we swap its accepting states with its non-accepting states, that is $\overline{L_1}=\{Q,\Sigma,q_0,\delta,Q-Q\}$. In this case we have a DFA witho... |
The 0-1 knapsack problem is given by
$$\begin{align}&\text{maximize } \sum_{i=1}^n v_ix_i,\tag{P1}\\&
\text{subject to } \sum_{i=1}^n w_i x_i \leq W,\\&\text{and } x_i \in \{0,1\}.\end{align}$$
Running the dynamic programming algorithm for this problem would give an optimal solution in $O(nW)$.
If I define $p_i=w_i/W$... |
Claim: $3SAT \le_p 4NAE $, where reduction $f$ is defined as such: given a 3CNF formula $\varphi$, add to each clause a new literal $z$ (where $z$ is same literal for each clause), and return new formula $f(\varphi)$.
It seemed pretty easy to show that $\varphi\in 3SAT\Rightarrow f(\varphi)\in 4NAE$:
If $\varphi \in ... |
I'm using first_order_model for an expression transfer between an video and a static image.
Part of the algorithm makes a facial comparison to get the frame in the video where the face is best aligned with the foto.
This is made with:
def normalize_kp(kp): # original kp is (step 1)
kp = kp... |
I have converted nfa to dfa. But when I checked with some examples, it looks like it is wrong.
This is the full question.
Convert the nfa defined by
δ(q0, a) = {q0, q1}
δ(q1, b) = {q1, q2}
δ(q2, a) = {q2}
δ(q1, λ) = {q1, q2}
with initial state q0 and final state q2 into an equivalent dfa.
First, I made a table.
... |
What are some of the known properties of half-integral linear programs?
That is, linear programs for which the solution vector always takes its values in the set $\{0, \frac{1}{2}, 1\}^n$.
I'm asking this in relation to half-integral linear programs that are relaxations of integer programs (are they "faster" in terms o... |
I have a this tree, i want to print out all paths from root to all child nodes:
NOTE: I wanted to come up with a solution that does not involve passing state between recursive calls.
a
/ | \
b c d
/ \ \
e f g
/ / | \
h i j k
This is the my code to create and print the paths.
class Node:
... |
I was going through the classic text "Introduction to Automata Theory, Languages, and Computation" (3rd Edition) by Jeffrey Ullman ,John Hopcroft, Rajeev Motwani, where I came across few statements about a pushdown automata (PDA) which accepts by empty stack, as:
1. $n$, the total length of the input, is surely an uppe... |
How can we manually read and interpret packets properly without using wireshark?
Now from the Ethernet header I know that the Destination MAC Address should be at the 5th byte (after converting bits/bytes). So from this data, I thought it would be 4a onwards. However, in reality it's 00:17:f2:d0:4c:82.
Same goes for th... |
Would a sparse NP-Complete language imply L = NP?
Update: Thanks to Noah Schweber for clear and comprehensive answer. Having thought about it more, one would need a logspace reduction from NP-complete to L-complete for NP=L. [4] below does not directly address this.
Here is my proof attempt:
[1] Assume there exists a (... |
BACKGROUND
I am writing a grammar and parser for a domain-specific language. There is a specific form of expression that, while simple, is giving me headaches.
Given terminals:
"a": KEYWORD
"b": INTVAL
"c": DECVAL
"d": STRVAL
Given rules:
"E": VALUE <- INTVAL
"F": VALUE <- DECVAL
"G": VALUE <- STRVAL
"H": VALUES <- ... |
How do you find a sub-digraph in a digraph such that the in degree and out degree of each vertex is 1. My professor told in the class that an algorithm can be build for it using bipartite matching but I have not able to do so. I am just looking for hints on how to proceed because I am kind of stuck on where to start.
|
I want to translate a java switch-case statement to intermediate representation of the three address code form. Three address code or TAC is a form of intermediate representation where each instruction contains at most three addresses and one operator. An address is a name such as x (stored in the symbol table), compil... |
I created an algorithm to convert a hexadecimal digit into an alphanumeric string, but now I want to create the inverse of this algorithm. The algorithm, in short, is as follows:
hexadecimal digit % length of alphanumeric character array = index in alphanumeric character array
For example, the algorithm takes hex dig... |
I am a CS undergrad and a huge enthusiast of pure math. I have been doing competitive programming and proofs for a while. My ambition is to become an academic in theoretical computer science. The problem I face, like any math enthusiast, is that academia pathway jobs are not reliable in terms of funding. So, I thought ... |
I think this is a basic topic in complexity, but I would like to ask how to understand co-$\mathcal{L}$ where $\mathcal{L}$ is a class of languages. From the definition of my textbook, $$co-\mathcal{L} = \{ \overline{L} \mid L \in \mathcal{L} \}$$
and where $\overline{L}$ is the complement. From what I read in an earl... |
so this is more or less a shot in the dark as I am feeling stuck. Maybe some of you have an idea which helps.
Here is the problem description (pseudo formal):
I want to have a structure $T = \{ \hat{x_1}, \hat{x_2}, ... \}$ with $\hat{x_i} = (p_i, k_i, v_{k_i})$.
$p_i \in \mathbb{N}$ can be interpreted as an associated... |
I'm given an array $A$ = ($a_1, a_2, \cdots a_n$), where n is uneven. For an element $a_i$ we denote its position in the array with $p(a_i)$. This element would be an $ε$-approximate median of the array, if after we sort it, the following inequality holds:
$$\frac12 ((1 - ε) × n) < p(a_i) \leqslant \frac12 ((1 + ε) × ... |
The following question is taken from leetcode: 1278. Palindrome Partitioning III
You are given a string $s$ containing lowercase letters and an integer $k$. You need to:
First, change some characters of $s$ to other lowercase English letters.
Then, divide $s$ into $k$ non-empty disjoint substrings such that each subs... |
I have the grammar $S = aSbS|bSaS|\varepsilon$. When I was first looking at the problem I thought it was unambiguous. When I looked at the answer it said that it was ambiguous. The solution it gave was:
$S \rightarrow aSbS \rightarrow a\varepsilon bS \rightarrow a\varepsilon b\varepsilon \rightarrow ab$
$S \rightarrow ... |
def find_perms(s):
"""
Finds permutations of the given string.
>>> find_perms("abc")
['cab', 'acb', 'abc', 'cba', 'bca', 'bac']
"""
if len(s) == 1:
return [s]
elif len(s) == 2:
return [s[0]+s[1], s[1]+s[0]]
else:
perm = find_perms(s[0:len(s)-1])
last_char ... |
Consider an array of sets. As you know a set must not have multiple elements. I need a data structure to handle following queries:
Insert element x to all sets on interval [ L, R ].
Erase element x from all sets on interval [ L, R ].
Query the sum of sizes of sets on interval [ L, R ] of the array.
Is there any data ... |
Suppose i have a quadratic equation like this, 2x^2 - 4x - 5 = 0, the solution here is x1=2.87 and x2=-0.87. I tried this python snippet to find the non-negative solution(2.87) by setting range 0 to 1000 and it worked but how to find the negative one too?. I tried the range -1000 to 0, but no luck!
def solve():
low... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.