instruction
stringlengths
35
29.1k
I have a question about determining preconditions for Hoare's Axiom Scheme. For example, if we have P { x=2 } x==1 and we are trying to determine the precondition, P, could we just set P as false giving us False { x=2 } x==1. I've read some of the other posts on this forum about Hoare's Axiom Scheme but am having a har...
Let suppose we order the nodes first by degree (in + out), to get a list of node structures: Node: labels: [] # lexicographic ordered out_arrows: [] # ordered by ordering of the nodes in_arrows: [] # ordered by ordering of the nodes Then how should we order the nodes that have equal degree? Or am I appr...
How to calculate the number of Integers that can be represent in Double-Precision floating-point form?
Suppose we are computing a sum over $n$ factors which can be represented as a planar tensor network. What is the complexity of finding an optimal elimination order? For example, take the following summation over 5 variables: $$\sum_{v1,v2,v3,v4,v5} f_1(v_1,v_5)f_2(v_1,v_2,v_3)f_3(v_3,v_4)f_4(v_2,v_4,v_5)$$ Each variabl...
Here is a simple but very common grammar rule case in EBNF format, the Statements is a none terminal symbol and Statement is none terminal symbol: Statements ::= (Statement ';')* After converting this rule to NFA, and then do the subset contruction for converting the NFA to DFA, and at last get the dfa: State0 -> Stat...
How can a directed graph be efficiently represented in a purely functional language like Haskell? Could someone suggest relevant materials on this topic? (functional pearls perhaps?) Thanks.
I am unable to understand why do we need to encode turing machine at all? I heard that we are trying to build a programmeable turing machine but can't relate how encoding it will make this programmeable. Please share some insights. PS I have seen different encoding in different slides, are all encodings fine? https:/...
Suppose given two strings $s_1$ and $s_2$ each of length $n$. We consider $s_1$ and $s_2$ as dual, if one of the following conditions satisfied: Strings are equal. Else, if $n$ is even then: Divide $s_1$ into two equal partitions $a_1,a_2$, also divide $s_2$ into $b_1,b_2$ then: $a_1$ with $b_1$ and $a_2$ with $b_2$...
The query-equivalence problem is undecidable. However there are theorem provers that attempt to solve instances of undecidable problems. I am curious how I could go about using an automatic theorem prover (or other solvers) to prove that one MongoDB query is equivalent to another. The MongoDB query language is large, s...
I would like a name for the following problem. We consider a relaxed vertex coloring problem, where Let $k$ be the number of colors Let $B$ be the set of edges violating coloring, i.e., $$B := \{(u,v) \in E \mid c(u) = c(v)\}$$ Then the objective is something like $k + \beta |B| \to \min$ over all colorings (for som...
Context: Consider $M$ finite state systems with evolution given by: $$ x^i_{k+1} = f(x_k^i,u_k) $$ where $x_k^i\in\{1,\dots,X\}$ is the state of system $i\in\{1,\dots,M\}$, $k\geq 0$, and $u_k\in\{1,\dots, U\}$ is some input which we can use at time $k$ to control the evolution of all systems (notice that $u_k$ is sha...
So I have a database pre-loaded with data related to food recipes and the assignment says: 'Provide an API call that allows us to specify an ingredient or set of ingredients and return full recipes containing those ingredients.' I am not sure if this means to create a webpage with a search box that would allow the clie...
I need to understand how adversary argument works to prove the lower bound of an algorithm. For now, I am looking to prove that a "certain" algorithm that takes in input array requires omega(n) comparisons. Basically it needs to compare the ith element with i+1th element, then i+1 to i+2 element and so on. The adversar...
The formal problem statement is: Given a set S of n distinct numbers and a positive integer k<=n, determine the k numbers in S closest to the median. My thoughts: I have read about the median of median algorithm, which goes like group n elements in groups of 5 and finds the median of them and then recursively finds th...
Consider a set of jobs, each having its deadlines and process time. How to find a permutation of them such that if they are executed in that sequence, they all finish before their deadline or figure out that no such permutation exists. My Thoughts: There could be some greedy strategy, but I am not sure how to arrive ...
Im specifically referring to the bully algorithm for synchronous systems, described in [Garcia-Molina 1982]. In it, the timeout for failure detection is concretely defined as the sum of the round trip time and the message processing time. Additionally, there is a separate timeout that the process must wait before re-st...
Assume I have a game actor (name it MyActor for further references) to be moved up and down according to $z=f(t)=A\sin \omega t$ (or any non constant velocity). The game engine provides us with callable GetGameTimeSinceCreation() to obtain the age of the actor. overridable Tick(float DeltaTime) in which we put our cod...
I am playing with L-System using the wonderful tool jflap. Below is the L-System for the dragon curve in the "JFLAP book: JFLAP – An Interactive Formal Languages and Automata Package " (you can find it in the left column of its homepage). What does the third rewriting rule "$g \to \lambda$" mean? I did not find any ref...
What is the definition of P, NP, NP-complete and NP-hard? here is a good answer but it really doesn't answer mym question. np-hard-: a problem A is NP hard if for all B$\in$NP, B is polynomial time reducible to A.(i.e A is easier than B). Then why is A called NP Hard? It should be called NP easy problem? Isn't it? n...
How can we actually define a polynomial-time 4-approximation algorithm for vertex cover or knapsack problem? For say we have 2 approximation problems which less than equal 2C*. But when we have a larger or 4 approximation sizes how we can derive it.
In a computer network, the store and forward mechanism is used. In this mechanism, the packet is sent from one system to the next along the network path, and in the second system, the complete packet received is checked and then sent to the next system in the network. This mechanism is quite similar to the behavior of ...
Reading the book Practical Foundations for Programming Language. In section 5.1 Transition Systems, the author said that Whereas all final states are, by convention, stuck, there may be stuck states in a transition system that are not final. Thus every complete transition sequence is maximal, but maximal sequences a...
After having searched a bit, it seems I can't find terminology or references for this outermost class, 2Σ* in blue -- see below. What is it describing?
Suppose we have $r$ copies of the integer $a$ and $t$ copies of the integer $b$, and a capacity $C$. We would like to find the maximum sum of the given integers, that is at most $C$. This is a special case of the subset sum problem. Since there are at most $(r+1)(t+1)$ possible sums, one can just check all of them and ...
Question: Consider an arbitrary directed graph $G$ with weighted vertices, the weights can be positive, negative or $0$. The prefix of $G$ is a subset of vertices $P$ such that there's no edge $(u \rightarrow v)$ if $v \in P$ and $u \not\in P$. Find an integer linear programming to describe the maximum weight prefix of...
I am working on finite state machine pruning, a problem that requires me to build finite state machines (in the manner of the Aho Corasic algorithm) to match an evolving input string against a set of suffixes. If a match occurs, the search is aborted (i.e. we don't care about outgoing transitions from accepting states...
Wikipedia's Minimum Spanning Tree reads: Minimum-cost edge If the minimum cost edge e of a graph is unique, then this edge is included in any MST. Proof: if e was not included in the MST, removing any of the (larger cost) edges in the cycle formed after adding e to the MST, would yield a spanning tree of smaller weigh...
I need help figuring out how to prove the following statement using the definition of "Big-Oh" notation which says that f ~ g if there are constants C and n_0 such that f(n) <= C*g(n), for n >= n_0. I have down below shared my attempts but am quite unsure about everything. For all I know I am not doing this correctly. ...
Consider the following problem 11.2-6 from CLRS book: Suppose we have stored $n$ keys in a hash table of size $m$, with collisions resolved by chaining, and that we know the length of each chain, including the length $L$ of the longest chain. Describe a procedure that selects a key uniformly at random from among the ke...
I have a graph theory or combinatorics problem that probably has a solution, but I haven't been able to find it. The problem can be simple: in the second figure below, choose one yellow block from each oval such that the blue edges between the blocks look like the edges in the first figure below. Find all possible such...
In the apriori algorithm there's the self join step, So, say we have 1 3 2 3 3 5 2 5 If I were to do an exhaustive join I'd end up with a tuple including (1, 3, 5) - although (1, 5) has no support. What's an efficient way to only get the wanted result of (2, 3, 5)? I had a look at the geeksforgeeks explanation, but ...
I am working on the polygon triangulation algorithms from "Computational Geometry - Algorithms and applications 3rd ed", chapter 4. I've managed to turn polygons into y-monotone polygons using the sweep line technique. For this, diagonals are added to the DCEL which ignoring any face values (which are then corrected la...
In Unix shell programming, there's the ideom: program1 && program2 && program3 where successful completion of program1 and then program2 will lead to the execution of program3. In Perl, there's 2 set of condition operators - punctuation styles &&, ||, etc., which binds more closely; and keyword style and, or, etc., wh...
This is a homework question. Consider the problem of finding if an undirected graph $G$ can have a spanning tree with no more than 50 leaves. Is this problem NP-hard? I think it is and I'm trying to prove it. So far I've tried to reduce Vertex Cover to this problem. My idea is that the internal nodes of a spanning tree...
The Task You are given $n$ columns each of length $m$. All values are either $-1$ or $1$. Find an assignment $s$ of each of columns to 1 of $m$ groups in order to maximize the sum of all the absolute values of group row sums. For example Suppose $$n=7,$$ $$m=3,$$ $$a=\left( \begin{array}{ccccccc} -1 & -1 & 1 & 1 & -1 ...
I'm in the first year of computer engineering and I feel completely lost when it comes to solving hard programming exercises. I think it's due to a bad modus operandi. And that is why I'm asking this question. My question is that: what do you do when you have to do a difficult task? In other words, what do you do when ...
Will u.f and u.d of a vertex in DFS traversal change if we change order of vertices in adjacency list ? I know that u.d won't change but what about u.f? u is a vertex of the graph. u.f, u.d are finish and discovery times of the vertex u respectively in Depth traversal search algorithm.
Can I exclude $\epsilon$? Will that make a difference. This is really confusing me. It seems everything could contain $\epsilon$. Is there some way of thinking to realize this contains $\epsilon$ or not. I was looking at a DFA for $a$ followed by $b$. And it also contained $\epsilon$ which seems confusing to me. That m...
In resolving collisions while hashing by chaining , if we store keys in the list in sorted manner, will we obtain any substantial performance in successful searches , insertion, deletion? What would be the time - complexities of these operations if we maintain sorted lists in chaining?(assume keys are integers)
I'm a computer science bachelor student tasked with understanding On the ICP Algorithm by Esther Ezra, Micha Sharir, and Alon Efrat, and I'm having a lot of difficulty with even supposedly obvious claims. The setup is as follows, wherein we only look at translation, not rotation: Let $A = \{a_1, ..., a_m\}$ and $B = \{...
Let's say that we have a language $L$ that is finite. How can I prove that the complement of $L$, i.e., $\bar{L}$, is always an infinite language? Obs.: infinite language in this case means that is possible to construct an infinite set of words that are acceptable by $\bar{L}$.
I was trying to minimize given DFA: a b -> 1 4 2 F 2 1 1 3 1 4 F 4 1 1 I've watched few videos about solving this problem and decided to use the equivalance method. While doing it I've come to the solution below: 0 Equivalance: {1,3} {2,4} 1 Equivalance: {1} {3} {2,4} a b -> 1 2,4 2,4 F ...
I just encountered this formulation of the shortest $s$-$t$ path problem as a linear program in a homework. I don't understand exactly the meaning of the variables and restrictions. Here, $G = (V, E)$ is an undirected graph with non-negative weights $w_e$. $S'$ is the set of all cuts in $G$ and $M(S)$ is the set of all...
S → aX | bX X→ aS | bS | ε This is required cfg, I want to learn how we arrived at this cfg? What steps did we follow to arrive here? Do we memorize some standard cfgs? I can derive strings using this but that is not useful when I don't know the cfg already. I have solved a cfg on my own and came up with this, if you ...
Given an undirected graph $G=\{V, E\}$ with its vertices numbered from $1$ to $V$, given two vertices $s$ and $t$ $(1 \leq s \lt t \leq V)$, what is the minimum number of vertices (except $s$ and/or $t$) that we need to remove (we also remove the edges associated with those vertices) so that there doesn't exist any pat...
Let NextPrimeNumber be an oracle that accepts a prime number n and returns the smallest prime number m such that m > n. It can be called by a Turing machine and returns the answer in constant time. Let F be the Turing Machine that receives K a positive integer as a number. Suppose its code is the following: current_pri...
I understand $R_{fa}$ etc. I understand why the diagonals are higlighted. I understand D={a,d,f}. But I don't understand what is the conclusion we derive from this?
In my opinion the contradiction should be-: If $n^2$ is even then n is even. But it is written in my discrete mathematics book that, "n is even then $n^2$ is odd". How do we find contradiction statement? This is what is written in my textbook.
Definition: Problem A is reducible to problem B if an algorithm for solving problem B efficiently (if it existed) could also be used as a subroutine to solve problem A efficiently. When this is true, solving A cannot be harder than solving B. In these reductions, a YES instance of A maps to a YES instances of B and NO...
A Boolean polynomial in $n$ variables $x_1, \dots, x_n$ is an expression of the form $$\sum_{\mathbf{s} \in \{0,1\}^n} c_{\mathbf{s}} x_1^{s_1} \cdots x_n^{s_n}, \quad \text{ where } c_s \in \{0,1\} .$$ Addition of Boolean polynomials is performed modulo $2$, while multiplication follows the distributive property and t...
Consider inverse of Ackermann function, can we conclude that the growth rate of it as the same as growth rate $\log^*n$?
I have a computer science question: Let Σ = {a} be a one-element alphabet and L ⊆ Σ^* be an arbitrary language over Σ = {a}. Show that L^* is regular These are all the facts I have been able to gather thus far: an alphabet Σ, any set L such that L ⊆ Σ ∗ is called a language over Σ Fact 1 For any alphabet Σ, any languag...
The original problem I was solving was what would the time complexity of a merge sort algorithm be, if it used a merge algorithm with complexity $\Theta(n^2)$ instead of $\Theta(n)$. The solution says the time complexity will be $\Theta(n^2)$, but I don't understand why it's not $\Theta(n^2\log n)$? I tried using a rec...
I am learning Computational Complexity. Is Knapsack-optimization problem (find an arrangement to maximize the value) known to be NP-hard, while Knapsack-search problem (find an arrangement so that value >= a number) known to be NP-complete? For the Knapsack-search problem to be NP-complete, should I have assumed that a...
For brevity, let $s(D) = \sum_{d\in D} d$ denote the sum of the elements in $D$. Given a set $A = \{a_1, \dots, a_n\}$ of positive integers, and a target value $K$, the subset sum problem is to determine if there exists a subset $A' \subseteq A$ such that $s(A') = K$. Given a set $B = \{b_1, \dots, b_m\}$ of positive i...
I'm trying to understand how to prove a language is regular or not regular, for example this language: $$L=\{a^nb^m:n,m\in\mathbb{N}\land n-m=5 \}$$ Is this language regular or not? My solution Using the pumping lemma, I can choose a string with a pumping length $p$ like: $w=a^{5+p}b^p$, then $x = a^j, y=a^l$ and $z=a^...
My question concerns the version of the Master Theorem described in CLRS and in this handout. I already understand the following: If the regularity condition in case 3 does not hold, then we can't apply case 3. If the regularity condition in case 3 holds then $f(n)=\Omega(n^{\log_ba\ +\ \epsilon})$ is definitely true....
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'm starting a job soon that involves a large number of disciplines interacting at once. I'm knowledgeable in most of these areas; at least enough that when I don't know something I know how to look it up. There is however an element of distributed computing involved in my new job and I don't think I'm as prepared for ...
So I'm trying to solve this problem(problem 8 from section 3.4) of the book Computability, Complexity and languages by Martin Davis: Let k be some fixed number, let f be a function such that f(x + 1) < x + 1 for all x, and let h(O) = k h(t + 1) = g(h(f(t + 1))) Show that if f and g belong to some PRC class C, then so...
Can you make interesting decentralised systems, e.g. cryptocurrencies or serverless games, that aren't susceptible to 51% attacks by design? (Rather than, as I've seen proposed, external solutions like fining mining pools that have too large a hashing power)
I'm looking for a data structure that supports the following operations: add(elem) - Add an element to the data structure. remove_random() - Remove and return a random element. The best I got so far is just shuffling a list on every insertion (or on every lookup), and popping from the top. However, this can be quite sl...
I am currently dealing with a network flow problem and I am trying to find some similar solved problems to help me formulate my solution. The text is: You are the owner of a large chain of franchise shops, and you would like to expand to a new city. The blocks in your city make an $n ×n$ grid. However, although your pr...
I've red that a binary heap can be implemented using a priority queue. I've also red the opposite, that a priority queue can be implemented using a binary heap. This seems strange to me as conceptually they are different: a priority queue is a linear data structure with a priority assigned to each element, whereas a bi...
I'm reading though The Algorithmic Foundations of Differential Privacy and the authors define a database in a mathematically convenient way. Unfortunately I'm a little confused about what the definition actually means in practice. From page 17 of the pdf: We will think of databases $x$ as being collections of records ...
I'm trying to solve this discrete optimization problem:$\newcommand{\I}{\mathcal{I}}\newcommand{\R}{\mathbb{R}}$ $$\max_{|\I| \le k} f(\I) \qquad\text{where}\; f(\I) :=x_{\I}^{\top} (\Sigma_{\I})^{-1} x_{\I}.$$ Here $\I \subseteq [d] = \{1, 2, \dots, d\}$; $x \in \R^d$ is a fixed vector; $\Sigma \in \R^{d \times d}$ i...
My question is for (c), as I struggle to find an algorithm that can do this in O(m) time.
We are given two Turing machines $M_1$ and $M_2$ and we wish to decide whether the union of the language $L(M_1)$ accepted by $M_1$ with the language $L(M_2)$ accepted by $M_2$ coincides with $\Sigma^*$. Is this problem undecidable? In other words, is the language $\{ (M_1, M_2) \mid L(M_1) \cup L(M_2) = \Sigma^*\} $ ...
A common way to resolve a dependency graph is to compute an execution order, and then execute each stage in turn - storing and fetching the resources as necessary. In this example, when executing stage E we know that stage B is present in the cache due to the execution order. At the end of execution, the output of ever...
I have a similar question as this post:Given a complete, weighted and undirected graph $G$, complexity of finding a path with a specific cost My question: Given a weighted and directed graph $G$, it might contain negative cycles, is there a simple path(no repeated vertices) from $s$ to $t$ with total weight at most $T$...
I want to model the following procedure. Given a shape $L\subseteq\mathbf{R}^2$ (imagine e.g. a letter) and another (could be convex if it makes life easier) shape $K\subseteq\mathbf{R}^2$, I want to compute $\{p\in\mathbf{R}^2: ((1-1_L)*1_K)(p)=0\}$ (in terms of convolution) or $\{p\in\mathbf{R}^2:\forall k\in K:p+k...
I am currently dealing with a problem that I believe to be a Greedy releated problem and I'm trying to find some similar problems in order to solve it. I would like to have some hints or resources to study because I'm stuck on it. The text is: You are tasked with creating a competitive programming squad, selecting stud...
According to DFS algorithm for graph traversing: DFS(G) for each v ∈ V (G) v.mark = false time = 0 for each v ∈ G.V if not v.mark DFS-Visit(v) DFS-Visit(v) v.mark = true time = time + 1 v.d = time for each (v, w) ∈ E(G) if w.mark == false w.parent = v ...
I know that we can compute $x^n$ in $\log n$. Are there any lower bound for computing $x^n$?
Recently, I studied how to prove a problem is NP-complete. From the book Introduction to Algorithms (CLRS, 3rd edition), there is an example of reducing vertex cover to Hamiltonian cycle. I believe that it is possible to directly reduce clique to Hamiltonian cycle in an undirected graph, but how to convert it in polyno...
I was surprised to hear that the threading module from python uses OS level threads. From what I know, OS level threads are more expensive (but can achieve parallelism) meanwhile green threads are user-level, more lightweight, but can only achieve concurrency but not parallelism. Why doesn't the python virtual machine ...
I have a DAG graph which contains two types of nodes, A and B. I am looking for a graph partitioning algorithm that can partition a graph in sub-graphs such that each sub-graph contains up to X number of node type B. For example, given this graph, I need to partition it topologically such that each sub-graph contains u...
I'm new in programming, I'm currently studying programming languages. I'm trying to implement Shallow Binding with static scope, starting from an abstract syntax (producing a programming language based on Ocaml with static scope). According to "Programming Languages: Principles and Paradigms" (Maurizio Gabbrielli Simon...
Please correct me if im wrong but this is how I think quantum computers work. Say we have a q-bit. The q-bit is put through a quantum gate to put it into a superposition and manipulate its probabilities. We can represent this q-bit just like a normal bit on a vector where a normal bit would, when represented on a circl...
Let $\Delta = \lambda x.(x)x$ and consider $\Omega = (\Delta)\Delta$. Then $\Omega$ is exactly the only $\lambda$-term of the form $(\lambda x.t)v$ such that $(\lambda x.t)v=t\{v\ /\ x\}$. Does someone have references about this statement ? I could not find something enough relevant in my ressources or in my lectures m...
I am stuck with the following exercise: Is it possible to decide whether a given flow $f$ is a unique mamimum flow in $O(\lvert V \rvert + \lvert E \rvert)$ time? I am not sure that this is possible. I understand that we can check in $O(\lvert V \rvert + \lvert E \rvert)$ time whether $f$ is maximal. (Just build the ...
Here's the statements of problem A, "ABC String" in Educational Codeforces Round 105 (Rated for Div. 2) You are given a string a, consisting of n characters, n is even. For each i from 1 to n $a_i$ is one of 'A', 'B' or 'C'. A bracket sequence is a string containing only characters "(" and ")". A regular bracket seque...
I wanted to ask here a question about a simple algoirhtm to compute a div d and a mod d. My doubt specifically depend on negative numbers: Doesn't the algorithm get wrong results for $-4$ and $2$ for instance, since the reminder of that division is 0? In this case the algorithm should give a quotient of $2$, But i ima...
I have a polygon as a set of coordinates (fex [(0,0), (1,0), etc.). I'd like to find a way to divide this into as few rectangles as possible. The background for this is that I wish to have a user interface where the user can select a specific area on a map (a polygon). The frontend will send the coordinates describing ...
Assume that there is a maximal matching of size k in an bipartite graph, G=(U,V,E). I now want to utilize this maximal matching in order to find a maximal matching in the bipartite graph where we add some node u to U and some edges (u,v_1),...,(u,v_n), where v_1,...,v_n are vertices in V. I have figured out that such a...
Came across the following question. All the answers provided there have used brute force, more or less. My hunch was that it could be solved using dynamic programming or perhaps, network flow algorithm. I am writing my unsuccesful attempt at solving it using dynamic programming at the end of this thread. What is the ri...
For: $$\sum^{k}_{i=1} \log(x_i)$$ where: $$\sum^{k}_{i=1} x_i = n$$ Is there any big-$O$ result in terms of $n$ ? I found this, but is not what I'm looking for.
I have about 200'000 data points distributed on the unit-sphere. Aside of each point's location on the unit-sphere, it has also assigned a width and height. I can perform nearest-neighbor queries by placing the cartesian 3D coordinates of the points in a 3d kD-tree, since shortest cartesian distance also means shortest...
I am applying substitution method to find the time complexity of the following recurrence relation. But I am having difficulty solving it past a certain point. $$T(n) = 2^n T(n/2) + n^n$$ After substituting $T(n/2)$: $$T(n/2) = 2^\frac{n}{2} T(n/4) + (n/2)^\frac{n}{2}$$ I get, $$T(n) = 2^\frac{3n}{2}T(n/4) + n^n + 2^\f...