instruction
stringlengths
35
29.1k
Where "switches" are the basic abstract building blocks for logic gates: vacuum tubes, transistors, magnetic relays, or whatever. We're not counting any switches in the RAM or tape drive because that's a separate component. I'm not sure if the exact number is known or provable, but an upper bound could be proven by imp...
I asked the following question on math.se but it wasn't really answered so moved it over here as I feel it's more relevant. I saw the question below on an old stack exchange question when looking to understand NP-completeness. At first, I thought I understood it so I gave it a go but ended up more confused than before ...
By "indexing" I mean assigning addresses or labels or whatever to nodes to make them easier to locate, similar (in its effect, not necessarily in the implementation) to how a database can be indexed. I feel this question must be pretty elementary, but as a CS noob I don't know how to search for the answer. I may not ev...
Given an undirected graph with at least one path connecting $u, v$, and a sequence of edges to be removed: $e_1, e_2, \dots$, I would like to quickly identify the point at which $u$ will be separated from $v$. Clearly this could be done by doing a full path search after each removed edge, but this is very expensive. Is...
Pure Prolog (Prolog limited to Horn clauses only) is Turing-complete. In fact, a single Horn clause is enough for Turing-completeness. However, pure Prolog is incapable of expressing list intersection. (Disequality, dif/2, would allow it to do it, but dif/2 is not Horn, unlike equality). This seems like a paradox, at f...
I found this on Wikipedia and I'm confused by the parenthesis in the notation not that it doesn't make sense to me but is there a more natural human version? And im generally confused about all the different notations surrounding logic and quantifier. $(\forall L \subseteq \Sigma^*)(regular(l)\Rightarrow((\exists p\geq...
I have an array (|A|≤10^6) of numbers (not guaranteed to be distinct) and a set of prime numbers. For each of the prime numbers, I want to know how many numbers in the first array are divisible by this prime number. For example: Array = {5 5 7 10 14 15} Set = {2 3 5 7 11} result:2:2; 3:1; 5:4; 7: 2; 11:0 Brute force ...
I am trying to develop the intuition of the master theorem for the case where $a > b^{d}$ [Case 3] in this video. In the video, they say that since most of the work is done at the leaves, we should expect $O(\text{number of leaves})$ but I don't see how that is similar to $O(n^{\log_b a}$), which one would get from th...
I'm trying to understand the solution of the following problem (LC 801): Given two arrays, A and B, of the same nonzero length, find the minimum number of swaps (A[i] <--> B[i]) to make A and B strictly increasing. The solution is guaranteed to exist for the given input data. Example: Input: A = [1, 2, 9, 4, 5, 6], B ...
This is a homework question and I am trying to fully understand what I have to do and how to go about it. Therefore, I don't want full answers to the question. The programming language PRE-WORK-POST is defined as follows: Let P, Q, R be LOOP Programs. Then "PRE P WORK Q POST R END" is a PRE-WORK-POST program, whereby ...
Many languages with GC perform escape analysis to reduce heap allocations. Is there a language with a "no-escape" construct that tells the programmer during compile time to not escape certain variables? This way they could be guaranteed to be allocated on the stack instead of the heap. Compare with value types in Java ...
I began a simple collection of the events behind todays computers. My knowledege in these fields is so limited, and I read: "In the 1930s and working independently, American electronic engineer Claude Shannon and Soviet logician Victor Shestakov both showed a one-to-one correspondence between the concepts of Boolean lo...
I'm creating a tool where, given a list of N items that have a volume (v) and a price (p), it should produce a list L that optimally fits as much value as possible into a single bin with a fixed size V. L does not need to contain all N. My current solution is a heuristic that simply sorts all the items by price-per-vol...
Given a graph $G = (V,E)$, how to partition $V$ into $k$ parts $P_1, P_2, \ldots P_k$ of at most $M$ vertices, such that the number of triangles (3-cliques) contained in the parts is maximal? This seems NP-complete. Was this problem studied before? (I couldn't find anything after searching clique graph partition). Furt...
I have a list of items that have a parent/child/grandchild/etc. type of relationship. Each item has a list of descendants, and an _.isDescendentOf(other) member function that returns true when a node is a descendant of another node (they have a list of immediate parents, and can sweep upwards to find grandparents). Som...
It is well known that for arbitrary flow networks, Goldberg's push-relabel algorithm takes $O(V^2E)$. Part of that comes from $O(V^2E)$ non-saturating pushes. Another part comes from $O(V)$ relabelling operations per vertex, each taking $O(V)$ time, for a total of $O(V^3)$ for all relabelling operations. I'm intereste...
What is the fastest known time complexity for computing central trinomial coefficients? Let $C_n=1,1,3,7,19,51,...$ (OEIS A002426) denote the coefficient of $x^n$ in $(x^2+x+1)^n$ starting at $n=0$. It can be shown that, if $n$ is prime, then $C_n=1 \pmod n$, because by the binomial theorem $$(x + y)^n=\sum_{k=0}^{n} \...
I need to find a regular expression for the language of all words over $\{0,1,2,3\}$ which do not contain $222$ as a substring.
So, I was watching a video about the conversion of $\epsilon$-NFA to a DFA. In the resulted DFA, she didn't write the state 4 in any successor set of the sets containing the state 3, and her explanation was that this happens because the state 3 has no outgoing transitions that are labeled with letters from $\Sigma$ in ...
I'm looking for an algorithm that will let me optimally select items from a set. These items have properties which are involved in defining constraints as well as the objective function. .e.g Say each item in the set has integer-valued properties A, B, C. I need to select n items (say 2, can pick any item at most once)...
Let me just say that this is for a university project. I do not expect an answer but more of a "hint". I have a schema of a Supermarket that holds a sequence of queues: +-- Supermarket------- |queues: seq Queue ---------------------- And here is how I've defined a queue: +-- Queue ---------- |length: ℕ ---------------...
Given $A_1$ - DFA with $n$ states, $A_2$ - NFA with $m$ states (both over the same alphabet - $\Sigma$). What's the state complexity, i.e. an upper bound for the amount of states of the minimal DFA, recognizing the language $L(A_1)\setminus L(A_2)=L(A_1) \cap(\Sigma^*\setminus L(A_2))$. What I thought of: evaluate the ...
Consider the Halting problem : No TM H exists which given any TM and input, decides whether that TM will halt on that input. The usual proof (informally) is that if such an H existed, then a function D(X) = {if H(D,X) then loop; else Halt;} can be constructed, with D(D) leading to a contradiction => hence H can’t exist...
I'm really interested in the idea of functional programming, it seems like a very modular way of doings things. I've seen some suggestion that functional programming is just as powerful as procedural programming (any problem you can solve with one can be solved with another). I'm curious as to how this conclusion was o...
The following is a function to write a recursive function that accepts an array and a callback. Function returns true if a single value in array returns true when passed to the callback otherwise it returns false. I have trouble understanding the "if not" line written here(line 4), how does the cb interact with arr? Pl...
I am working on my own personal project. I took an intro to coding class last semester so I have been exposed to coding but I am still lost with it. Basically, for my project, I want to build a web map (I'm not even sure if that's the right word for it) using python. Here is an example. Basically, some numbers will ha...
Looking at the pumping lemma, I've noticed that in the string $xy^pz$, there seems to be no rule explicitly stated for $x$ and $z$. If I understand correctly, $x$ and $z$ are basically anything on the 2 sides of the string $y^p$ that we're pumping and thus can be anything in $L$. Rule 2 & 3 of the pumping lemma are: $...
In the Partition problem, there is a set of integers, and the goal is to decide whether it can be partitioned into two sets of equal sum. This problem is known to be NP-complete. Suppose we are given an instance and we know that it admits an equal-sum partition. Can this partition be found in polynomial time (assuming ...
Consider the following language $$L= \{ \langle M\rangle | \text{ $M$ is a TM, and $L(M)\in coRE$} \}$$ I don't understand why the language $L$ is in $R$, intuitively, I think this is not true. Indeed, suppose we have a TM $M$, now for input $x$ such that $x\notin L(M)$, it seems that we cannot decide whether $x\notin...
I was writing up an algorithm that involved knowing the size of integers my hardware can manage without having to resort to software implementations of math operations and the additional computational load that comes with them, and I realized that I've never given this much thought. In theory, a 64-bit computer has 64 ...
I have a numerical dataset of $N$ columns ($\approx 150$) and $K$ rows ($\approx 60000$). On a user interface, you can apply a filter to one or more columns. We can call the number of filters = $Z$ (with $Z \le N$). Those filters are double sliders allowing to get a min/max for the column. For each filter, I would like...
I just built a LRU cache that combines a hash table and a double linked list. To me it was a brilliant idea to combine those two structures and use the strengths of each together, so it got me thinking, can people or do people combine hash tables with other more complex data structures like trees and graphs? Are there ...
I need help proving the following fact: Let $G$ be a random $d$-regular graph with adjacency matrix $A$. The smallest eigenvalue $\lambda_n$ of $A$ should satisfy $|\lambda_n| = o_d(d)$. (In particular, I think $|\lambda_n| = O(\sqrt{d})$.) Exercise 7 in [1] is to prove this fact, so it seems like there should be a sim...
Consider the fact that each player can either sit on their desired chair or on the neighbouring chair. Two configurations are distinct if at least one person is sitting in another chair. My attempt For example, if there are 4 players sitting around a circular table there can be 9 distinct arrangements. F1,F2,F3,F4 F2...
I have found two interesting questions regarding the quotient of languages, described as: $A/B = \{ w \text{ | }\exists z \in B, wz \in A\}$ The first one is: Let $A$ and $B$ be regular languages, prove that $A/B$ is decidable By using the proof from this other question, it can be proved that $A/B$ is regular if $A$ ...
I'm working on a problem 2.3a in Shalev-Shwartz/Ben-David's Machine learning textbook, which states: An axis aligned rectangle classifier in the plane is a classifier that assigns 1 to a point if and only if it is inside a certain rectangle. Formally, given real numbers $a_1\leq b_1, a_2\leq b_2,$ define the classifie...
The problem. Let us consider a huge file with billions of lines, each containing a string. There are $n$ different strings and $m$ lines in the file, with $m$ much greater than $n$, although both are huge. In particular, neither the entire file nor the list of all distinct strings fit into central memory. The global fi...
I have a very poor understanding of gray code in general and I find it to be a difficult thing to learn. While trying to learn about it I stumbled upon this seemingly looking trivial question that I can't answer. Can the bit pattern 01110011 represent offset gray-code? What is "gray-code" and how do I construct it and ...
I have implemented Thistlethwaite's algorithm however, it is far too slow as it is only using graph traversal over many Rubik's cube states. I am currently unsure of how look-up tables are implemented so any help on how I could do so would be greatly appreciated.
I'm an igsce student. I'm taking computer science as an OL subject this year. Pixels are the small squares which make an image. Inside each pixel there are 3 channels: one for blue, one for green, one for red. The three primary colours from which any other colour can be made. And that's how I imagine it: When we say an...
The address bus(of cpu) is connected to a digital decoder inside the memory which sets 1 pin logic high and activates the read/write operation of the memory let's say DRAM. Is the data bus(of cpu) connected directly to the bit line of the DRAM(columns) or are there some in between steps?
I'm trying to understand the statement of the Goldwasser-Sipser Set Low Bound Protocol as presented in "Computational Complexity: A Modern Approach" by Arora and Barak. In particular, I'm trying to understand why the following claims yield what we would want: $S \subseteq \{0,1\}^m$ is a set such that members can be ce...
I want to make sure my understanding on P vs NP is correct. I know that NP-complete problems cannot be solved in polynomial time, and if P != NP, then all problems in NP cannot be solved in polynomial time. Furthermore, if we consider the church turing thesis, and if P != NP, then no computational formalism can solve N...
I found in some exercise in computation the following step: I can't understand why is it equal terms, based of what I know about De morgan's law: OR should be replaced by AND where $w=\varepsilon$ come from
We are given an Undirected, Weighted and Connected Graph $G$, (non-negative weights, all distinct) with one property that shortest path between any two vertexes on this graph is on MST. The following Facts is False, and True. $I$) Graph $G$ is a Tree. False. $II$) weight of each ${u,v}$ edge, is at lea...
This problem is a mix of the bin-packing and the knapsack problems. I call it "the moving van problem": there is a moving van with a limit on the weight it can transport, and a set of boxes that you want to fill with valuable objects to be transported in the van. Both the boxes and the objects that are available can be...
In an online discussion on Turing machines and decidability recently, I blatantly theorized that any problem about a specific single Turing machine must be decidable, the question of undecidability only arises when we are talking about a class of a problem. As a rebuttal to the original argument someone replied that if...
In mathematics and computational geometry, a Delaunay triangulation for a given set P of discrete points in a plane is a triangulation DT(P) such that no point in P is inside the circumcircle of any triangle in DT(P). A Voronoi diagram is a kind of tesselation that divided the medium into polygons in 2D and polyhedrons...
As is well known, there is no single procedure for deciding whether any given Turing machine halts on an empty input tape. This is easily shown, e. g., by applying Rice's theorem. But what if, instead of considering the entire set of Turing machines, we only focus on a subset thereof? Clearly, if the subset is finite, ...
Problem Below is a program named X: y = 1; while(y < x){ y = 10 * y; } What does this program X do? What are appropriate pre and post conditions? (Assume that x and y are integers). My solution Given a whole number x > 1, X should give us a power of 10 greater than or equal to x. pre-condition: (|x = x0 ∧ x0 > 1...
I want to optimize an algorithm for calculating $g(n)=\sum^n_{k=2} p(\Omega(k))\Omega(k)$ where $$ p(n) = \begin{cases} 1 &\text{if $n$ is odd} \\ -1 &\text{if $n$ is even} \end{cases}$$ and $\Omega(k)$ is the prime factor counting function or more exactly, I want to optimize calculating all its values up to $n$ My c...
Problem: A segment of a program is shown below: ⋮ _ _ _ _ _ _ z = x - 7; (|z = 5 ∧ n = 4|) ⋮ What is the dashed line hiding? My solution: I think the dashed line is hiding: (|x - 7 = 5|) However, I am not sure if it is the correct solution, it would be nice to know how to solve this trivial problem.
In our lecture it was proven that WHILE-Programs are turing-complete. In short a WHILE-Program only allows the following: Variables x1,x2,... (initially all 0 and can only be positive) Constants c 0,1,2,3,... Assignment xi := c Addition/Subtraction xi := xj + c, xi := xj - c while-loo...
I want to show that there is a polynomial-time reduction from the standard $\text{Clique}$ problem to the $\text{N-Degree-Clique}$ problem, where: $$ \text{N-Degree-Clique} = \{ \langle G, k\rangle: \text{$G$ has a clique of size $\geq k$,} \\ \text{and every vertex of $G$ has degree at least N} \}$$ I am not sure how ...
I have created a custom implementation for PriorityQueue using max-heap and everything works fine. But now i want to change it and keep only the k highest objects in the heap after every insertion. I have to use only one instance of my PriorityQueue and no other helping data structure. So my problem is how should i kno...
lately, I have encountered a problem that I struggle to find a satisfactory solution for. I need to prove that triangle-free 3-colorability is NP-complete. Therefore I assume the right way is to find an NP-complete problem and reduce it to my problem. I tried it with general 3-colorability, but I was unable to create f...
I have a taxonomy (tree) of product categories. To each leaf product category, I have assigned a shop department where the products of a given category can be found. Now for each department, I would like to find the smallest number of the largest subtrees in the taxonomy. For instance, in the example below leaf nodes h...
I have a grammer with the following productions, S -> aA | bC | b A -> aS | bB B -> aC | bA | a C -> aB | bS I have to construct regular expression for it. I derived words for this language and which are b, aab, aba, baa, bbb, aaaab, aaaba, aabbb, abaaa, baaaa, ... So after I deriving the words I concluded that it's...
I am using Christofides' algorithm to calculate the best route from one location to another given multiple nodes on a map that the route must pass through. The last step in the algorithm requires the route to connect back to the first node, right? Is this step necessary? If no, why? Edit: I essentially want the data th...
Assume that we are given an undirected graph $G$ of n vertices. For this graph, we also know that there is a clique of size $c$, for some $c\geq \lfloor n/2 + 1\rfloor$. In other words, the majority of the vertices will belong to this clique. This clique may or may not be maximal; however, given these assumptions it wi...
Problem description We are given two sorted arrays of even numbers: A and B. Values of A are generally supposed to be smaller than values of B. So we are asked to find a value X where X is an odd number to predict which set an element belongs to. If an element is smaller than X, it will be assigned to A,and if it is bi...
When looking at hashing, and given the following question: Given ASCII values: a = 97, b = 98, c = 99, d = 100, e = 101 Given keys: {e, ae, be, ce, de, abe, ace, ade, bae, cae, dae, bce, bde, cbe, dbe} If we choose: h(k) = k mod 2^6 to map these keys to hash tables indexes, what do you notice? The answer to this is ...
To the best of my understanding, $m \models p$ asks whether the LTL formula $p$ satisfies the LTL formula $m$. In other words, $m \to p$ is a tautology. Here are some examples of where $m \models p$ holds: Xp |= Fp q |= p U q Gq |= Fq Of course, trying to visualise all this in you head and trying to work out if $m ...
Given a tree $T$, I want to find a subset $N$ of $n$ leaves that are farthest apart. I.e., I want to find $N$ that maximizes function: $$f(N)=\sum\limits_{x_1,x_2 \in N, x_1 \neq x_2}{dist(x_1,x_2)}$$ where $dist(x_1, x_2)$ is the number of edges in a path between two vertices/nodes $x_1$ and $x_2$. What algorithm can ...
After asking another question(Is the last step in the Christofides' algorithm necessary), I have decided Christofide's algorithm probably doesn't solve the problem I'm facing. Is there any algorithms that would best suit this problem? The input is a set of nodes on a graph (an implementation would be similar to the il...
I wonder why do we say $\log n$ is the best possible approximation factor for Set Cover Algorithm? We already know there exists a 2-approximation algorithm for vertex cover, which is obviously better than $\log n$. So we can use Vertex Cover algorithm to solve Set Cover problem and get a better approximation ratio. Can...
I'm looking for an algorithm which takes spherical coordinates (say lat-long) and identifies which face of an icosahedron a ray moving in that direction would intersect. My end goal here is to explore various cartographic map projections from a sphere onto an icosahedron (ex: Gnomic, Fuller Dymaxion, Snyder equal-area)...
Can there exist a language L in PSPACE such that L isn't PSPACE-hard and L isn't in the polynomial hierarchy (PH)? Intuitively, it seems like the answer is no, since TQBF is PSPACE-complete, and any version of TQBF bounded finitely to i alternating quantifiers is complete for one part (depending on whether it starts wi...
In my uni lecture, I am covering address decoding. I understand that memory addresses are decoded to find if they point to the RAM, ROM, or I/O, by way of the address (in the example of BBC Micro) being in the RAM range, user ROM range or OS ROM range (e.g. 0x0000 to 0x7FFF is the range of RAM in the address space). Ad...
For this exercise the pumping lemma should be used. My instructor gave me a tip it should start with $w:= a^{prime(n)}$ where prime is a while program returning the nth prime number. This does make sense to me since a while program always returns an element of the integers. How can I use code in my proof?
I'm trying to prove that the language $L \cup A$ is undecidable, when the language $L$ is undecidable and the language $A$ is finite or decidable. This is confusing me because if $L$ were to be a semi-decidable language, then this would be easy to prove (with either pseudocode or TMs), but as I understand not all undec...
Given a Lambda Expression Term T can it be beta-equal to two different Lambda Terms T1 and T2, both T1 and T2 are in beta-normal form?
I found the following question with an answer here, but I can't understand the steps of the solution. Show that if a language $A$ is in RE and $A \leq_m \overline{A}$, then $A$ is recursive. Solution. Since $A \leq_m \overline{A}$, it follows that $\overline{A} \leq_m A$, and since $A$ is in RE, it follows that $\ove...
Preparing for the next semester, I wanted to give the following as a homework question, yet after a few attempts, I failed to solve it. Given a language $L\subseteq \Sigma^*$ and two words $x,y\in \Sigma^*$, define the language $L_{x,y}$ consisting of all the separating suffixes of the words $x,y$ relative to the Myhil...
I have this graph It shows a graph of a map that has nodes and segments (or edges), with weights, that connect these nodes. Some of these segments have addresses on, and some of these addresses are designated as restaurants. There are two chosen restaurants, and one chosen address. Can someone point me in the directio...
I need to construct linear bounded automaton for the language $L = \{ a^{n!} : n \geq 0 \}$. I know how LBA functions, however, I don't have a thought how it can check the n! that to in the power of a. I might want to hear a few suggestions, as I am experiencing difficulty in developing the specific LBA for it.
How would you go about showing that the language L={⟨M,w⟩ | M moves its head in every step while computing w} is decidable or undecidable? Intuitively speaking I think it is indeed undecidable because there seems to be no limit to the possible configurations, however I am not sure. Thanks a lot in advance!
Let $\ f_1, f_2, ... f_m : \{0, ..., m \} \rightarrow \mathbb Z $ my task is to find an algorithm that find a series of numbers $\ x_1, x_2, ..., x_m \in \{ 0, ..., m \} $ that maximise $\ \sum_{i=1}^m f_i(x_i) $ and subjects to $\ \sum_i^m x_i \le m $ To be honest I can't really wrap my head around this problem. Any s...
The "Superset Existence Problem": Let there be a set $S$, and $x$ subsets of $S$. Does there exist a set of size $y < |S|$, which is a superset of at least $z$ of those subsets? To me, this feels like it should be NP-complete (in $|S|$), since it seems intuitively related to covering problems and minimum $k$-union. But...
Assume that Problem $A$ is polynomial-time reducible to problem $B$. Claim 1: If problem $A$ is NP-hard then problem $B$ is NP-hard. Claim 2: If problem $B$ is NP-hard then problem $A$ is NP-hard. Claim 1 is obviously true, but why the second one is false?
I have a balanced $k$-ary B-tree with $N$ leaves (where N is a power of $k$ for simplicity) and I need to simultaneously locate $\ell$ leaves in it. What is the expected number of nodes I will need to traverse? Obviously for $\ell=1$ we need to traverse $\log_k N$ nodes, but the question becomes less trivial (for me) f...
I've been fiddling with software development for a couple of years and in trying to get into the gist of things I came across SICP, which uses Scheme. Basically what I want to do at this stage is to store exercise/test .scm files for study. Should I use Emac or Dr. Racket ? Or none of those? Thanks!
Let's say you are using a messaging application (Microsoft Team, Skype, Telegram,..) on an operating system (Windows, MacOS, Linux). Does the OS know what you are sending or receiving? If yes, how? Assuming that the computer can be setup for monitoring (e.g. company's computer).
I'm looking at a special version of SAT in which each clause has exactly $n/2$ literals, where $n$ is the number of variables. Can we prove NP-completeness of SAT in this case? I tried reducing 3-SAT to it by expanding, but this introduces $2^{k-3}$ extra clauses per original 3-SAT clause, hence the reduction is not po...
I need to prove that the following recurrence relation is $O(5^n)$: $$ T(n)=5^n+3T(\lfloor n^\frac{2}{5}\rfloor) $$ And $T(n)=\Theta(1)$ for $n\le 9$. I am trying induction, and proving that there exists $c$ such that $T(n)\le c\cdot5^n$, but I am stuck at the induction step: $T(n)=5^n+3T(\big\lfloor n^\frac{2}{5}\big\...
More specifically the problem says: "Let us call the set of decidable languages D. Show that NP ⊆ D" My problem is that I always assumed that NP is decidable, but to prove it, I never thought it Somebody have any idea about how do it? or start resolving it? I think I can prove it saying something like the NP problems e...
I thought to reduce from the halting problem to conclude undecidability, yet I don't know how to do it. Perhaps the problem reduces to other decidable problem, and thus it is also decidable?
https://prototypr.io/post/gpt-3-design-hype/ Has GPT-3 had any effect on the how many humans are hired to do web design yet?
In the question in this video about quicksort luckily picking the median in each recursive call. Tim Roughgarden, the presenter, says at 11:22 Partition needs really linear time, not just $O(n)$ time. What does he mean here? I thought linear time is $O(n)$. Does he mean $\Theta(n)$ or something else? I see how partit...
I am trying to solve the following recurrence $T(n) = 4T(n/2) + n^3$ with substitution method. My guess is $T(n) = \Theta (n^3)$ (I used master theorem) and I tried to show that $T(n) \leq cn^3$. But, when I substitute I got $T(n) \leq c \frac{n^3}{2} + n^3$ and that's it not the exact form of the guess, so it doesn't ...
I have come up with a simple technique of approximating the Levenshtein distance between two binary strings using the fast Walsh–Hadamard transform: given two binary strings $a,b$ with Walsh–Hadamard transforms $\hat{a},\hat{b}$ of length $n_a,n_b$, I propose to approximate the Levenshtein distance by $$ \max \{ |\hat{...
I have a homework question that I trying to solve for many hours without success, maybe someone can guide me to the right way of thinking about it. The problem: We want to find an optimal local alignment of two strings S1 and S2, we know that there exists such an alignment with the two aligned substrings of S1 and S2 b...
A graph with n vertices, no matter directed or not, may have maximally 2^n-n-1 negative cycles (Think about combination of 2 to n elements and you'll figure out why 2^n-n-1. A graph that has no graph loops or multiple edges is my only concern) and I want to find ALL of them if any, not just one of them. There are only ...
Given a list of subsets $S_1, \ldots, S_n$ of the universal set $U = \{e_1,\ldots, e_m\}$, find a subset $S \subset U$ of size $k$ that contains the maximum number of subsets $S_i$. In another words, $$\max_{S \subset U\\ |S| = k} \sum_{i = 1}^n \mathbb{1}_{S_i \subseteq S}$$ Where $\mathbb{1}$ is an indicator function...
Given an undirected graph $G=(V,E)$, describe an algorithm that computes an orientation of $E$ such that each vertex has out-degree at least 3. I know how to check if a vertex $v$ has at least $k$ edge-disjoint paths to any other vertex (using Ford-Fulkerson), so I thought I may use that for $k=3$. Would appreciate y...
I recently solved the basic problem of generating a n-bit Gray Code. The solution I used involved building larger-bit Gray Codes from smaller ones recursively (the solution I've seen on most websites). However, I then had an idea for a Greedy Gray Code Algorithm: Start the Gray Code at 0 and at every step, find and cha...
From a youtube video, this PDA can recognize any palindrom. However, from wikipedia, here is one of the criteria of PDAs. We clearly see that the transition function can't take an empty stack as input, as epsilon is not a part of Gamma. (but it can use it as output, and also epsilon input is allowed as we see in the ...
So I am using A* pathfinding to find a path from a person, to a node on a graph. This person has a few 'must pass' nodes that they must go through. So my solution was to run the algorithm for each of the must-pass nodes, to make sure they always go to each of these. My method for deciding which order nodes come in for ...
In my logic class we started learning about the different complexity classes. In particular, we focused on the NP complexity class. A problem is in NP if it is solvable in polynomial time using a nondeterministic Turing machine. To show that a problem $L$ is NP-compelete, we have to show that: $1)$ $L$ is in NP, and $2...
I have got to write an algorithm programatically using haskell. The program takes a regular expression $r$ made up of the unary alphabet $ \Sigma = \{ a \} $ and check if the regular expression $r$ defines the language $L(r) = a^{*} $. I am looking for any kind of tip, I think I can use a pumping lemma somehow, but I ...