instruction
stringlengths
35
29.1k
Given an array of N non-negative integers, and a number K, we need to find two non-overlapping contiguous subarrays that have a total sum of K. Our algorithm is supposed to find the minimum total length of the two subarrays that have total sum K. Also, after I checked the biggest test cases that we got, N doesn't go ab...
Can someone tell me what the rules are for moving log or exponents into the $O(n)$ notation so it is still correct? For example: Is this $\log(O(n))= O(\log(n))$ correct? Or is this correct $O(n)^2=O(n^2)$? Or am I not allowed to do this?
Consider a boxing match between players A and B. If A wins, then $1$ point is gained; otherwise $1$ point is lost. Assume that $A$ is as same good as B. Denote by $X_t$ the expected point of A at time $t$, then the assumption means that $(X_t)_{0\le t\le T}$ is a Markov martingale. The match ends if either of the two c...
I've been trying to implement a program for matrix multiplication of multiple of 4 (ex: 4x4, 8x8, 16x16, etc.) and while I my program works for 4x4 matrix, it only fills the first 4 row of every other matrix (which are filled with the proper value). My guess it's because I don't have the proper algorithm implemented, ...
This is the knapsack problem where the items are unlimited. Let $K(w)$ be be the maximum value achievable for the knapsack capacity of $w$, and $w_i$ and $v_i$ are the weight and value of the item $i$. My textbook (Algorithms from Dsgupta et al.) boldly that If the optimal solution to $K(w)$ includes item $i$, then re...
I wish to construct a sequence of unlabeled binary trees $T_n$ satisfying the following properties: $T_n$ has $n$ leaves $T_n$ is well balanced (height $\lg n+O(1)$) $T_n$ is obtained from $T_{n-1}$ by one of the two operations $t\to (t,\ast)$ or $(t,t')\to (t,(t',\ast))$ In other words, we are limited to right inser...
How can it be proved that two different kinds of dfs ( for example let call them inorder and postorder) unequivocally define a unique tree? Let's say we have two dfs arrays: A0(inorder) = {a01, a02, a03, ... a0n}; A1(postorder) = {a11, a12, a13, ... a1n}; So can we say that the pair {A0 and A1} defines a unique tree, ...
I believe problems like quicksort and other divide-and-conquer are problems that have optimal substructure but do no have any overlapping subproblems. I hope I'm correct here. But I'm unable to think of some examples of overlapping subproblems that don't have an optimal substructure.
Out of the following, which type can cause problems with encapsulation? A. Int B. Int[] C. String D. non of the above I chose D and was incorrect. I am kind of confused what this questions is asking about... I just began to learn about the encapsulation and it seems it's just to keep the fields private and not changea...
Preface: I know there are a lot of posts already here and elsewhere about algorithms for solving quadratic Diophantine equations in general. I am posting this in the hope that my very particular case might allow an approach much simpler (both in time complexity and the need for me to relearn combinatorics) than those f...
In our course: Automata and Computation there is a definition about Context-Free Grammars which states: "Two CFG's $CFG_{1}$ and $CFG_{2}$ are equivalent if $L_{CFG_{1}} = L_{CFG_{2}}$ where $L_{CFG_{i}}$ is the language that is derived by $CFG_{i}$". Below the definition, it is stated that this defines an equivalence ...
It's fairly well known that $REG \in TIME(n)$. I would like to know similar inclusions for the language classes $DCFL$ and $CFL$. I have found a variety of claims for these classes on the internet. For instance, In this diagram of the arithmetic hierarchy, it is claimed that $DCFL \in TIME(n^2)$ and $CFL \in TIME(n^6)...
I am working on something that requires checking a very large natural number $x$ to determine if it is the square root of an even larger natural number $y$. So I am wondering what are the fastest algorithms for computing square and square root, and how should I be approaching this i.e. Computing $\sqrt{y}$ and compari...
Here, Yuval Filmus wrote: Unary encoding is only relevant in contexts where the length is not fixed. Are there words without fixed size length? Is there a Computer Science theory which describes computers which can include such words in their memory cells (while at least some words are unary) and could the output of ...
I am training a model for ham and spam classification using LSTM. I am indicating the spams as 0, and the hams as 1. However, the dataset has much more hams than spams, so I tend to get an output very close to 1. That means the output is almost always above 0.5. So I have two questions about this : Q1. Should I rate my...
I need to perform 2's complement operations on -50 - -48 From a mathematical point of view the following would be true. -50 + 48 = -2 If I would follow the steps I would have: I got to this result by getting the bite for 50 and 48 and then reversing -50 = 11001101 -48 = 11001111 In 2's complement: the bite result for ...
I'm struggling in understanding how to recognize irregular languages. I know what the meaning of irregular language but still find it hard to recognize. Are there any tips to recognize better and to know which is regular and which not? For example, which of the following is not regular, and what gives you the intuition...
For example, I have one program that requires $O(i)$ time complexity, and a second program requires $O(j)$ time complexity. Would the total time complexity be $O(i+j)$? And why?
I am currently reading the paper On computing the length of longest increasing subsequences by Michael L. Fredman. I'm struggling to understand parts of the proof of Theorem 3.5, especially this bit: Now consider the following enhancement $A^*$ of $A$. Whenever $A$ concludes that $L < k$, $A^*$ continues to completely...
Given two equally sized sets, $P$ of Boolean predicates and $E$, I want to decide if there exists a bijective function $f: P \rightarrow E$, such that \begin{align} \forall p \in P \; p(f(p)) \end{align} It seems like a special case of having a weight matrix $W$ where $w_{ij}=0$ if $P_i(T_j)$ and otherwise $1$, and the...
What data structure would one use to keep a large number of IP addresses (v4 and v6, but not at the same time if that makes a difference), and I'm talking about millions, preferably hundreds of millions at a time for fast look-up. The preference would be for fast look-up. Initial filling of the data structure is not to...
I am unable to understand how the negation of a sentence into CNF actually makes sense, hopefully somebody can explain it to me in understandable terms! Given the sentence: If the battery is charged (A) and the screen is not cracked (B) then the phone is working (C) The following makes perfect sense: (A ∧ B) => C I can...
Consider a graph $G = (V, E)$, where $V = \{0, 1, 2, \ldots, n\}$. The graph $G$ is complete, which means we can traverse $(i, j)$ for all $i, j \in V$. At each vertex $v \in V$, there is a task that we must complete. The task at vertex $v$ takes $q_v > 0$ minutes for $v \neq 0$, and we must complete all tasks. We star...
Given the sentences, S1, S2, if S1 |= S2 then all models that satisfy S1 also satisfy S2, how is the following statement correct? A ∧ ¬A |= B How can something and not something equate to true? I am stuck trying to work out how true and false can still entail true, actually how can A and ¬A occur at the same time? Than...
https://leetcode.com/problems/bus-routes/ You are given an array routes representing bus routes where routes[i] is a bus route that the ith bus repeats forever. For example, if routes[0] = [1, 5, 7], this means that the 0th bus travels in the sequence 1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ... forever. You will start at th...
$$T(n)=2^n+4T(\frac{n}{2})$$ I have started substitution for: $$T(\frac{n}{2})=2^{\frac{n}{2}}+4T(\frac{n}{4})$$ $$T(\frac{n}{4})=2^{\frac{n}{4}}+4T(\frac{n}{8})$$ $$...$$ $$T(\frac{n}{4})=2^n+4[2^{\frac{n}{2}}+4(2^{\frac{n}{4}}+4T(\frac{n}{8}))]=2^n+4\cdot 2^{\frac{n}{2}}+4^2\cdot 2^{\frac{n}{4}}+4^3T(\frac{n}{8})$$ S...
Construct a turing machine (TM) over the alphabet {a,b,0,1,#} that reads strings of the form (ab)^n with n>0. If the string w on the tape has this structure, the TM should overwrite all letters with the character 1 and go into an accepting state and if not, the TM should overwrite all letters with the character 0 and ...
I have a set of $d$-dimensional hyper-rectangles with integer axes. These hyper-rectangles may overlap. The union of these hyper-rectangles forms a $d$-dimensional orthogonal polyhedra $P$. I sort the $d$ dimensions in order. So there are dimensions $1,2,3,\cdots,d$. I want to express $P$ by a directed graph $G$ (inste...
I am reading Algorithms by Dasgupta et al and the graph section provides an example graph and mentions that there are 4 orderings with one of them being B, A, D, C, E, F. Are the other 3? B, A, D, C, F, E B, D, A, C, E, F B, D, A, C, F, E
I'm reading The Algorithm Design Manual and this is one of the excersizes: Prove or disprove the following statement: $\Theta(n^2 ) = \Theta(n^2 + 1)$ I think this is untrue because the right side of the equation claims to have a multiple $c$ such that it is smaller than all the multiples of $n^2$, which is untrue. B...
I am currently working on CLRS 1.13. The idea is to use Stirling's approximation to prove that $${2n \choose n} = \frac{2^{2n}}{\sqrt{\pi n}} \left( 1 + O \left( \frac{1}{n} \right) \right)$$ Now directly replacing Stirling's approximation I arrive to something like: $${2n \choose n} = \frac{2^{2n} \left( 1 + \Theta(\...
I have a large (10 million+) set $X$ of data points in some high dimensional $\mathbb{R}^d$ ($d \geq 500$) space. Each data point is quite sparse, e.g. has around $10$ components. Every missing component can be seen as having value $-\infty$ for the purposes of this problem. Associated with each data point $X_i$ is a ...
I'm having troubles finding information on how to solve/optimize a problem I'm currently facing, which probably means I'm either approaching it poorly and/or I don't know what to search for. The question I think I need the answer to: given several sets of possibilities, what is the smallest number of sets I must select...
how can I find the regular expression for this intersection ? I've tried to find words but it did not help too much.. $$[\; (a+b)^* c^* (a+b)^* \;] \cap [\; (c+b)^* a^* (c+b)^*\;]$$
int P(int n) { if (n==1) return 1; else return P(P(n/2)); } How will this function P(P(n/2)) be executed and what will be the recurrence relation for this code? Original image with the code
In the book - Computer Organization and Design: The Hardware/Software Interface [RISC-V Edition] by Patterson and Hennessy, CPI is defined like this: The term clock cycles per instruction, which is the average number of clock cycles each instruction takes to execute, is often abbreviated as CPI. Since different instru...
If I have two kinds of LinkedList $A$ and $B$. $A$ is a move to front one which means: >>> lst1 = 1, 2, 3, 4, 5, 6, 7, 8, 9 >>> lst1.contain(7) True >>> lst1.to_list 7, 1, 2, 3, 4, 5, 6, 8, 9 $B$ is a swap list, which means: >>> lst2 = 1, 2, 3, 4, 5, 6, 7, 8, 9 >>> lst2.contain(7) True >>> lst2.to_list 1, 2, 3, 4, 5, ...
Suppose I have some (increasing, nice asymptotics) function $f(n)$. Does there exist a complexity theoretic problem (e.g. PATH, 3-SAT, GO etc.) that can be solved in time $\Omega(f(n))$ on a deterministic Turing machine. In other words is there a problem proven to be an element of $\mathsf{DTIME}(f(n))$, but not $\math...
I have to work on something , but I am making an error that I can not identify. Propably, it is going to sound simple to you but it's my first course on computer architecture and there is nothing in my slides or book. "We are given a memory, where the smallest chuck of information that can be adressed is 1 byte, and we...
I was studying shortest path algorithms and was met with an issue regarding Bellman Ford for the image below. Following the graph, i see that node 3 has a length of 1 while node 2 has a length of 2. When computing the path from 1 to 8 which is the correct path between 1->2->6->4->7->8 and 1->3->2->6->4->7->8 ? I can s...
Suppose you have an $n\times m$ 2D array consisting of each $n$ rows of $m$ real numbers. What is the sequence of indexes $i_1,i_2...i_m$ such that $\sum_{j=1}^mA[i_j, j]$ is maximized, subject to the constraint that each run of a value in $i_1...i_m$ must be at least $r$ entries long? A correct algorithm with time lin...
We consider training one-dimensional open map of Kohonen with neurons in one-dimensional input space. We assume it is completed the phase of the device and the weights $w_i$, $i = 1,2, \dots, N$, are placed in ascending order. (As we know, this provision will not change in rest of the training.) At each step of the tra...
I get $n$ numbers, where every number is an integer between 1 and 1000. If within given numbers are duplicates, I sum all of them to one number. I repeat it until I have only distinct elements. As a result I return number of distinct elements at the end. How do I do it in additional space complexity $O(1)$ and time com...
Let $n$ be a positive integer. On a circle are arranged $n$ points $A_1$, $\ldots$, $A_n$. We put some arrows from $A_1$ to $A_2$, from $A_2$ to $A_3$, etc., from $A_n$ to $A_1$. On each arrow are written a string ($\textit{name}$ - so that we could distinguish all arrows from each other) and a number. How can we find ...
Given a random graph $G(n, p)$, where $n$ is the number of nodes and $p$ is the probability of connecting any two edges, it is known that $t = \frac{\ln(n)}{n}$ is a threshold for the connectedness of the graph: if $p$ is greater than $t$ the graph will be almost surely connected, otherwise disconnected. The farther yo...
I am working on a chatbot designer interface. The dataset for the conversation flow consists of messages. Each message has a parent message and can have multiple possible next messages. The system displays one of the possible next messages depending on the reply. This makes it a complicated structure of parent-children...
There's lots of answers on the proof but I didn't find anything that regarded my difficulty directly. Question ( From " Introduction to Algorithms ( Cormen ) " ): Answer ( Found on the net ): I don't understand the case where $ A[j] = v $ when we prove the maintenance step for before the j+1-th iteration ( after ass...
I have the following mixed integer programming (MIP) problem: $$ \begin{array}{rll} \text{Maximize } & z=k \\ \text{subject to } & a_ik - m_i \geq 0 & (i=1,\dots,n) \\ & b_ik - m_i \leq 1 & (i=1,\dots,n) \\ \text{where} & k \in \mathbb{R}_{\geq 0}, m_i \in \mathbb{N}_0 & (i=1,\dots,n), \end{array} $$ where $a_i,b_i$ ar...
I'm pretty confused so I hope I don't mix up the different terms here. The two's complement representation of decimal 0 is simply 000 The two's complement of 000 is 111 I imagine that complementing a number is equivalent to flipping bits in binary The nine's complement of 000 is 999 This is what confuses me. Are ...
I am reading Automata and Computability by Dexter C. Kozen and I am in the first chapter entitled Strings and Sets. If we have a set $A=\{ab,b\}$ do we get to assume that the null string $\epsilon$ is also a member of that set? If we have another set $B=\{\epsilon\}$, does $A\cap B = \{\epsilon\}$ or does $A∩B=\emptyse...
In boolean logic, why is the "opposite" of AND (&) equal to OR (|)? For example, why would !(A & B) be equal to (!A | !B)? I understand that not A would simply be !A, but why does AND change to OR?
I drew a Push-down Automata, accepting the following language: $$ \{ xcy : x,y \in (a+b)^*, \#_a(x) > \#_{bb}(y) \}. $$ Here $\#_{bb}(y)$ counts the number of times that $bb$ appears in $y$, with overlaps. For example, $\#_{bb}(bbb) = 2$. My question here. Is it possible to reduce my PDA to less states? Thanks.
Let $G=(V,E)$ be a weighted undirected connected graph and $w: E \to \mathbb{R^{+}}$ a weight function so that there are no two edges that have the same weight, and $T$ is an MST of $G$ . Then in each cycle in the graph, the edge with the minimum weight belongs to $T$. I either need to prove it in a positive way or gi...
I've been trying to find a formula that helps us identify where an address can be depicted in cache. I remember my professor talking about some kind of division but I can't find it in my textbook nor internet (maybe I am not searching the right words). For example: I have a cache that has $2^{14}$ blocks, each 32 byte...
I'm trying to prove that $L=\{a^kb^ra^m|k,r,m\ge0 \text{ and } m=k+r\}$ is not regular and, although it's trivial to prove it via pumping lemma, I'm having troubles trying to find a way to prove it via closure properties (for example a union of $L$ and another regular language which may give a non-regular language). It...
I am a beginner at Java and this code example came up in class: int horsepower = 15; if(horsepower > 15) if(horsepower <= 20) System.out.println("There is a lot of horsepower"); else System.out.println("The car super fast"); the output is nothing but I can't understand why. I...
For an alphabet $A = \{ a_1, a_2..., a_n \}$, the set of regular langages $L_r$ on $A$ are recursively defined by closed union, concatenation, and Kleene star's operator. I understood that languages ($A^*$) and regular languages (a subset of $A^*$) are different. Why do we need Kleene star, isn't concatenation enough f...
Suppose I have a $n$-state non-deterministic finite automaton $F$ over alphabet $\Sigma$. Let $S(x)$ be the set of states reachable from the starting state by consuming string $x$. I am interested for a given NFA to compute a $n \times n$ simultaneous reachability matrix $R$, such that $R_{ij} = [\exists x : \{i, j\} \...
Suppose $L$ is a regular language over $\Sigma$ and we want to show that $$\frac{1}{2}L = \{x \in \Sigma^* \mid \exists y \in \Sigma^* (xy\in L \wedge |x| = |y|)\}$$ is regular. I thought of taking the set of even length strings over $\Sigma^*$ (given by $(00\cup01\cup10\cup11)^*$) and then interescting with $L$, which...
Finding a clique $C$ in an undirected graph $G= (V, E)$ such that $|C| > |V|/2$ is in P or NP-hard? How can I prove it?
I noticed that in complexity classes, logspace class is defined but there is no logtime. I was wondering how is that possible? Normally, I would expect the opposite, It is possible to do a search query in an ordered list in time less than the time of iterating over all items (==> Logtime?). However you can't store a li...
I have a grammar: $G → id > id$    $| id < id$    $| G and id$ Does anybody know how I can do left recursive elimination on this one, when it doesn't have any extra non terminals?
Hello I am currently working on an implementation of MCTS and I ran into the problem that my tree traversal policy selects nodes with terminal game states. Furthermore how do I prevent selecting a Node that only has children Nodes with terminal game states ( and so on and so on )?
A theorem says if $f$ is a computable function and we can prove $x \in A \Leftrightarrow f(x) \in B$, then we can use reduction so $A \leq_m B$. But i'm confused if should I prove if : $(x \in A \Rightarrow f(x) \in B )\land (f(x) \in B \Rightarrow x \in A)$ Or $(x \in A \Rightarrow f(x) \in B ) \land(x \notin A \Ri...
I recently started learning about distributed computation on graphs (not to be confused with parallel computation with threads). I have seen as a side note in a few lower bound proofs, a reference that says the proof could be shorter using the "linear lower bound theorem for the Equality problem", but I couldn't find t...
Assuming we have a regular language $L$, how can we prove that $L'= \{ xz \mid \exists y : xyz \in L \text{ and } |x|=|y|=|z|\}$ isn't necessarily regular. So far I can't come up with much for how to solve this. I was thinking we could solve this by either generating an example where $L'$ isn't regular or we could use ...
I've got a very general question about the relational model and it's relationship to 1st order predicate calculus. It will probably seem very basic to most, I'm afraid, a consequence of me grappling with these concepts on my own for the first time. I would love it if someone could please clarify. One often sees example...
I recently read the Berry and Boudol's chemical abstract machine [1, 2]. I found the way they describe the semantic really nice and quite intuitive for a process calculus. The aspect that really appealed me is that, in the chemical abstract machine (ChAM hereafter), configurations are multiset of processes (and process...
I am curious about something pretty simple, though I have never heard, read and more sadly seen any example of it. Take any image, represent it as a matrix, invert the matrix (assuming the inverse exists) and represent it as an image again. This in some sense visualizes the process of inverting a matrix. It would be pr...
In my Computability and Complexity class, we are focusing on P, NP, NP-complete, and NP-hard problems and the one thing that keeps coming up is the SAT problem, in the context of reduction from one complexity to another or to explain certain concepts. Why is SAT so ubiquitous in theoretical computer science?
Suppose that I want to enumerate all English language words of length 5. If I've got nothing more than a check of whether an arbitrary string is an English word, I have to do 5^26 calculations. However, suppose that I can check a partial specification to see if there are any words consistent with it. By partial specifi...
Assuming the input photo is focused on a person's face, if the person is wearing a surgical mask, most face recognition software fail to identify the subject's face. Most facial landmark models are trained to identify at least the eyes and the tip of the nose (for example, dlib's 5 point landmark). Is it possible to co...
The Problem: I'm trying to simulate part of the game tantrix which is a board game played with hexagonal tiles. Each tile has 3 lines of different colors that each start at one side of the hexagon and end at another side. a line is drawn between these tiles. Adding multiple tiles together one can make a line consisti...
Recently, I've encountered the following problem: Given a collection of sets $S_1 \dots S_n$ of elements $e_1 \dots e_k$ with element $e_k$ denoted privileged, and a $k-1$-vector $r$, choose at most $m$ of the $n$ sets to maximize the number of times the privileged element $e_k$ occurs in the multiset union of the chos...
I am having trouble on the following algorithms question: Given $f(n) = \sum^n_{y{=}1} (n^5\cdot y^{22})$, I am trying to find a $g(n)$ such that $f(n) = O(g(n))$. I know that this means I need to find constants $c,n_{0}$ so that $f(n) \leq g(n)$ for all $n > n_{0}$. I began by considering the expansion of $f(n) = n^{5...
I am reading chapter 3 Decomposition of Graphs of Algorithms by Dasgupta, Papadimitriou & Vazirani and they show a pictorial representation of pre and post numbers with brackets for tree, forward, back and cross edges. I have pasted the image of the area I am unclear on. I am assuming that u is the node/vertex we see f...
Many times, I've wished to plug in my backup hard disks into my PC without the risk of any of the data being deleted, overwritten, or modified in any manner. Purely for "inspection" and copying over certain files from it. But, unlike on the old floppies, there's just no hardware switch anywhere to enable "read-only" mo...
The distance transform gives the distance of each pixel in a mask to the nearest zero. E.g. lets take the Taxicab distance transform: input distance 1 1 0 2 1 0 1 1 1 -> 3 2 1 1 1 0 2 1 0 I'm looking for a generalized distance transform where each each element in the mask also has a "weight" or "i...
I am trying to devise a Las Vegas algorithm to solve Maximum Independent Set, but I don't know how to start. Also, I want to devise a Mont Carlo algorithm for this problem. I would appreciate any help. Thank you.
I was reading about simulated annealing on its Wikipedia page, and was drawn to a particular example illustrating the annealing schedule. Below is the picture and its description: Example illustrating the effect of cooling schedule on the performance of simulated annealing. The problem is to rearrange the pixels of a...
I read following explanation from Dasgupta's Algorithms book for Median finding, this is the same philosophy applied in randomized quick-sort. Here as per book terminology $S$ denotes array of integers, $v$ is pivot, $S_{L}$ and $S_{R}$ are left and right side of pivot element. To distinguish between lucky and unlucky ...
For algorithms involving binary trees, time or space complexity is often O(logn) in the best case of a completely balanced tree, and O(n) in the worst case of a completely unbalanced tree. Sure, it's a generalization, but it's also a reasonable one. But in real algorithms, we're typically not interested in the rare wor...
Suppose that there are two probabilistic automata $A_1$ and $A_2$ with a same finite alphabet $\Sigma$. The languages of them are $\mathcal{L}_{1} \subseteq \Sigma^*$ and $\mathcal{L}_{2} \subseteq \Sigma^*$ respectively. For every input $x \in \Sigma^*$, $\Pr \{ x \in \mathcal{L}_{1}\}=p_1(x)$ and $\Pr \{ x \in \mathc...
Suppose the use of linear regression. The result of the MSE is 120.5(mean squared error) for the train-set. Wev'e reached the minimum of training the data. Is it possible that by applying Lasso(L1 form) we would get a lower MSE for the train? and for the test? is the same also holds for Ridge(L2 form)? Lasso Train Las...
I need to build a turing machine that decides $A=\{0^{2^n} | n \ge 0 \}$ with an alphabet of two symbols - $\{0, \_ \}$. I'm aware of the known TM that decides this language with three symbols $\{0, x, \_\}$ but I am not able to come up with one that does it with just two. Any advice would be highly appreciated
I have some problems to understand computability and hope you can help me. In the lecture we had following problem: Consider the three partial functions $f,g,h\colon N \to N$, where $f$ is computable and $g$ is not computable. The following two statements are correct: If $h(x) = g(f(x))$, then $h$ could be computable....
In several posts on StackExchange and elsewhere, I have seen claims that you only need to show you can construct constants, successor, projection, composition, and minimization to prove a language Turing-complete, since primitive recursion is allegedly a special case of minimization. But as I have been thinking about i...
How do I construct a DFA for the language $\{0^m1^n \mid m+n \text{ is even}\}$? The corresponding regular expression is $(00)^*(11)^* + (00)^*0(11)^*1$.
I'm trying to come up an efficient algorithm that, given a list of positive integers $a = \left(a_1, \ldots, a_D\right)$ and positive integer $c$, finds a list of non-negative integers $b = (b_1, \ldots, b_D)$ that minimizes $\prod_{i = 1}^{D}\left(a_i + b_i\right)$ such that $\prod_{i = 1}^{D}\left(a_i + b_i\right)$ i...
I try to express datastructures in a form of mathematical functions. For example an array or a dictionary is just a function to me. Is there a good way to model a tree in terms of functions?
Say we have two strings s and l, and they only have characters 'a' through 'z' (lowercase English alphabet characters). The task is to find the maximum number of consecutive occurrences of s in l. Ex. s = "ab" l = "defgababajklabe" The answer here would be 2, because there is "abab" which would be 2 consecutive occurre...
I am given the following problem description: Given $l$ lists, $L_1$, $L_2$, . . .$L_l$ each containing $N$ bit vectors of $n$ bits each, we want to find tuples $(x_1,···,x_l)$ with $x_i$ in the corresponding $L_i$, such that:$$⊕_{i=1}^l x_i = S $$ for some target n-bit vector $S$. In other words, we want to find one...
I understand that the language $L = \{ a^mb^nc^k \mid m=n \text{ or } n=k \}$ is context-free because it can be represented as the union of $L_1 = \{a^mb^mc^k\}$ and $L_2 = \{a^mb^kc^k\}$, which are both context-free. But I can't figure out the working of the PDA accepting $L$. To check whether $m=n$, first of all $m$ ...
In this circuit, if the two qubits are initialized at state 0, then after the oracle they are entangled and in the state: $$\frac{1}{2} (|00\rangle+|01\rangle+|10\rangle-|11\rangle)$$ My question is, how do the two $H$ gates act on them? Do they act like: $$\frac{1}{4} [(|0\rangle+|1\rangle)\otimes(|0\rangle+|1\rangle...
I am struggling with a specific question regarding complexity classes. The question goes as follows: There are three languages A,B,C so that: A is NP-complete B is in P C is polynomial time reducible to A $\triangle$ B (symmetric difference) Which of the following statements is valid: C is in P C is in NP C is ...
As I was preparing for the CCC this year, I am quite confused as to why a certain code modification was able to speed up my code for CCC Seniors Problem 2. Here was the C++ source code for my first attempt, which scored 13/15 in the cccgrader website as well as the DMOJ online judging website. #include <bits/stdc++.h> ...
For an optimization problem $x^* =\text{argmax}_xf(x)$ s.t. $x \in Y$ satisfy to some constraint $Y$. Can I argue that if there is a polynomial algorithm for this optimization problem. Then there must exist a polynomial algorithm checking if $x$ satisfy constraint $Y$?
If a constraint satisfaction problem $x \in Y$ is NP-Complete. Can I conclude that the optimization problem $^* =\text{argmax}_x (x)$ s.t. $x \in Y$ is also NP-Complete?
I am trying to design an LL(1) Parser that accepts regular notation where 'E' represents epsilon, and 'U' represents "or" like ' | '. So far I made one that accepts T = { a, b, *, +, (, ), E} S -> T S' S' -> + S | ε T -> F T' T' -> T | ε F -> P F' F' -> * F' | ε P -> ( S ) | c | E c -> D M M -> C | ε D -> a | b I ...
If 2 CPUs have the same Instruction Set Architecture, which of the following properties will be the same? Clock Rate CPI Execution time No. of instructions MIPS