instruction
stringlengths
35
29.1k
The problem I want to solve is this: Given a list $A$ of $n$ elements, I want to verify that they are all distinct. If I were to do this "myself", I would need $O(n)$ space and $O(n\log n)$ time to solve it, e.g. via a hashmap or binary tree. Luckily, I have an untrustworthy but omnipotent oracle ally who is willing to...
I am currently learning the pumping lemma, and encountered the following question, which I am unable to solve: Prove that $L = \{ 0^n \mid \text{$n$ is power of 2}\}$ is not regular. I considered $w = 0^{2^n}$, where $n$ is the pumping lemma constant. Then I divided $w$ into $xyz$, where $y \ne \epsilon$ and $|xy| \l...
How do you evaluate how many times some loops will run, when you start to complicate the boundaries conditions? For example, take this function: def f(n): s = 0 for i in range(n): for j in range(i, (n + i**2) // (n - i) + 1): s += 1 return s for i in range(10): print(i, "->", f(i)) ...
I was watching a lecture video and the Professor states that it would be very rare to see the order of a Btree to be even. I was hoping for an explanation but he cut it off there and moved on with the lecture.
I'm just getting started with learning about K-nearest neighbor and am having a hard time understanding why standardization is required. Reading through, I came across a section saying When independent variables in training data are measured in different units, it is important to standardize variables before calcula...
I have some basic confusions about the definition of the guarded fragment of first-order logic. Hopefully someone can tell me where I'm wrong. GF in FO is defined by: Atomic formulas, $x=y$ and $R(x_1,...,x_n)$, are guarded formulas. If $\phi,\psi$ are guarded formulas, so are $\neg \phi$ and $\phi \wedge \psi$. For v...
Let's say that a set of natural numbers $S \subseteq \mathbb{N}$ is primitive recursively enumerable if there exists some primitive recursive function $f$ such that $S$ is the range of $f$. That is, we can enumerate $S$ by calculating $\{f(0), f(1) \ldots \}$. What is known about this class of sets? Where does it stand...
Given a set $S$ of line segments (possibly sharing endpoints) and a query point $q$, how fast can we find the closest visible endpoint from $q$? If $p$ is the closest visible endpoint to $q$, then, in this case, it means that the line segment $pq$ does not intersect with any other line segment in $S$. I am trying to im...
I have a solution to the following problem: Given a stairway of $n$ stairs, which you can climb from $1$ to $m$ at the time ($1 \leq m \leq n$), return all the ways you can climb the stairway. E.g. for $n = 3$, $m = 2$, the possible ways to climb are $[2,1], [1,2], [1,1,1]$ // outputs all the ways to react total us...
Consider the algorithm LastMatch below, which returns the offset (shift) of the last occurrence of the pattern P in text T, or -1 if P does not occur in T: LastMatch(T,P) for(s = T.length - P.length downto 0) j = 1 while(j =< P.length and P[j] == T[s + j]) j++ if(j == P.length + 1) return s return ...
Let Fact be the following decision problem. Given two natural numbers $k \le n$ the machine accepts if and only if $n$ has a non-trivial divisor that is less than or equal to $k$. Prove that if Fact $\in$ P then there is an algorithm that given $n$, it produces its decomposition into prime factors in polynomial time in...
Is this statement true? Optimization TSP problems are known to be NP-hard, as we do not have a minimum cost to compare against, and in order to verify a solution is optimal, we need to iterate across the solution space.
Let be $B$ a Busy Beaver function and set $W=\{\langle M \rangle :\text{$M$ stops in less than $B(10^{1000})$ steps on an empty tape}\}$. Is this set computable? I'm not sure how to approach this question. I suspect that this set is computable and have tried to see if it is finite, but haven't reached anything.
Given an array, generate all combinations For example: Input: {1,2,3} Output: {1}, {2}, {3}, {1,2}, {2,1}, {1,3}, {3,1}, {2,3}, {3,2}, {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, {3,2,1} I am practicing Backtracking algorithms and I think I understand the general idea of backtracking. You are essentially running a DFS...
Find pair with maximum Appeal value. Input: Array Output: index {i, j} ( i = j allowed) with maximum Appeal Appeal = A[i] +A[j] + abs(i-j) Example 1: Input: [1, 3, -1] Output: [1, 1] Explanation: Appeal = A[1] + A[1] + abs(0) = 3 + 3 + 0 = 6 Example 2: Input: [1, 6, 1, 1, 1, 1, 7] Output: [1, 6] Explanation 6 + 7 ...
I am trying to find a simple example of a problem that is computable but not in P, I know very well that it would be enough to get one in NEXTIME-complete however the problems that I find in this set are very artificial
A cache has following specifications: Block size = 16 Bytes Set size = 2 way set associative Number of sets = 128 Physical address = 23 bits, byte addressable My Questions are: 1) How many blocks main memory contains? 2) What is the extra memory required for cache? According to me: Total size of physical address = $2...
According to the "Type Theory and Formal Proof" book, Church-Rosser theorem (confluence) is as follow: Suppose that for a given term $M$, we have $M \twoheadrightarrow_\beta N_1$ and $M\twoheadrightarrow_\beta N_2$. Then there is a $\lambda-term$ $N_3$ such that $N_1\twoheadrightarrow_\beta N_3$ and $N_2\twoheadrighta...
I'm reading an OS textbook and it was talking about TLB misses being handled by software. I'm very new to all this by the way. So there's a context switch to some kernel procedure. But surely in this case the TLB is not flushed, and the kernel code doesn't itself use the TLB, since that would defeat the purpose? But th...
I was reading this paper where they mention about undirected networks: "The total connectivity of a network is defined as $C=\frac{E}{N(N-1)}$ where E is the number of edges and N the total number of nodes." However, this is just another way of talking about network density is it not? You could just change the de...
I am trying to understand why $BPP \subseteq EXP$. This question almost gives the answer (simulate $BPP$ machine on all possible toin cosses and then "act accordingly"). However, it is not clear to me what act accordingly means: I am thinking we need to count how many times the probabilistic Turing machine accepts and ...
I have read that a hardware interrupt is handled asynchronously by the CPU, which means that the interrupt signal may arrive at any point of time with respect to the CPU clock cycle. Now, this means that an interrupt may asynchronously hit the processor when it is in the middle of executing some instruction. So, how do...
According to this Wikipedia article, when arithmetic left shift operation is applied to a signed number, the number is multiplied by 2. But there are certain situations where a negative number becomes a positive number when an arithmetic left shift is applied. Eg.: Take a 2's complement signed integer -5 and 5 bits ar...
I wrote a "proof" for this, and though it was enough to convince myself, there are a few things that bother me about it. Primarily I'm not sure about the loose way in which I'm swapping between first-order logic and the Curry-Howard correspondence, and some ancient and brief exposure to first-order logic as an undergra...
While reading through my textbook, I discovered that if you want to access a particular web page, your web browser will find out the IP address of the web server that hosts the web page and try and connect to it. It will then transfer a copy of the web page to your computer so that you may view it. However, my concern ...
Consider the following problem. We are given a set of patterns (strings) $\Pi = \{\pi_i\}$, a text $s$, and a window length $k$. We want a list of all shifts $0 \le i \le |s|-k$ such that every pattern in $\Pi$ is contained in the substring $s[i:i+k]$. Can this be solved in linear- or near-linear-time? It can of course...
In my experience, sometimes a computer boots normally, and in a time span of days, the computer won't boot, then again, it will boot normally again. I am not a computer science expert so I assume that if a computer boots normally one time and then it doesn't, it must be due to any changes made into the computer between...
Suppose there're $N$ weighted balls and $M$ equal weight bins, it's guaranteed at least one placement exists that all the balls can be placed into bins. What's the right algorithm to achieve a well-balanced placement where each bin has almost equal weights of balls? I know if the bins are of different weights, the pro...
I'm trying to determine the maximum memory consumption of the "pending nodes" data structure (stack/queue) for both travelings: BFS and (preorder) DFS. Since BFS and DFS while traveling graphs have node discovery control (no loops), we can analyze the problem by thinking in terms of trees instead of graphs, where your ...
Let $T$ be a function. Is it true that if $\exists f\forall n,m> 0.\\ \frac m {f(n)} \leq T(n,m)\leq m$ Then $\exists g.T(n,m)=\Theta(m\cdot g(n))$? In words: is such a case, is there a function $g$ dependent only on $n$ that satisfies the above? It looks to me true, but I am really stuck and don't know how to prove it...
I'm currently trying to solve a clustering problem. I need to cluster/partition an undirected weighted graph into groups that are restricted to size n. I have ~80000 nodes and ~260000 edges. Each node owns a weight w. The sum of all node weights in one cluster cannot exceed n. The higher the edge weight between each no...
Linear programming can solve only problems with weak inequalities, such as "maximize $c x$ such that $A x \leq b$". This makes sense, since problems with strict inequality often do not have a solution. For example "maximize $x$ such that $x<5$" does not have a solution. But suppose we are interested in finding supremum...
Suppose a shared ethernet link L, in which for nodes T1-T4 and a router R are connected: --------------------------- R | | | | T1 T2 T3 T4 L has bit-rate C=100 Mbps, and propagation delay is PROP = 10 msec. Every node transmits packet with probability Pb = 10%. The mean packet length is P(len...
I have two grammars: L → ε | aLcLc L → ε | aLcLc | LL This two grammars are equals but the first one is regular, so it produces a regular language and a Finite State Automata. Instead, the second one is non regular but it might produces a regular language. To prove it, I want to create two differentes automata: th...
Let $$T(N) = \begin{cases}1 & \text{if } N = 1\\ T(\varphi(N)) + \lg(\varphi(N))^3 & \text{otherwise} \end{cases}$$ where $\varphi(N)$ is Euler's totient function. Can I somehow express $\varphi(N)$ as $N/b$, so I can apply the Master Theorem and resolve this recurrence? You may assume $\varphi(N) = (p-1)(q-1)$, if it...
I have an array of time variables t(1), t(2), ..., t(n). and corresponding variables v(1), v(2), ..., v(n). Given a time tx, I would like to efficiently find between which interval (t(i), t(i+1)] does the number lie. Correspondingly, the variable vx needs to be interpolated which can be done easily afterwards. P.S: The...
I'm currently reading "Engineering a Compiler" book. In the chapter that explanes computing epsilon-closure there is listed the following algorithm: But I couldn't understand what does $E(n)$ and $E(p)$ mean. I know that it has something to do with sets.
This post says Binary Space Partitioning Trees are a generalization to dimensions > 1 of binary search trees which indicates the binary search trees lives in 1d space. Is my understanding right?
Let's say that we have the strings Hello, World, Hello and World. The algorithm I am thinking of would create an immutable buffer that contains Hello, World and the previous three would then become references or slices of that one like buf[0,11], buf[0,4], buf[7,11]. A way to implement this algorithm would be to compar...
Suppose we have a set of variables $V$. We also have a set of equations $E$, which are sets of at least two variables. We don't know anything about these equations, except if we know all but one of the variables in an equation, we can deduce the missing one. Does there exist a set of variables $R \subseteq V$ with $|R...
In computational learning, The NFL theorem states that there is no universal learner. For every learning algorithm , there is a distribution that causes the learner to output a hypotesis with a large error, with high probability. The conclusion is that in order to learn, the hypotesis class or the distributions must be...
I have a large array $A$ that contains something like $[0..1..0..]$. It has a continuous range of $0$'s, followed by a range of $1$'s, and then another range of $0$'s. This array is large and access is expensive, so I want to use a sampling algorithm to estimate the range $(i, j)$, where $A_i$ is the first $1$ and $A_j...
I have an undirected graph which may have 2 edges that connect the same pair of nodes. A group of nodes that don't need any bridges to go from a node to another should be merged into one node in a new tree. That tree should contains such nodes and all bridges in the original graph. What is the algorithm to solve this p...
In their proof of the sparsification lemma, Impagliazzo et. al describe the following operator $\pi$: For a familiy of sets $\mathcal{F}$, let $\pi(\mathcal{F}) \subseteq \mathcal{F}$ be the family of all sets $S$ in $\mathcal{F}$, such that no other set $S'$ in $\mathcal{F}$ is a proper subset of $S$. I am trying to u...
In CLRS there is an exercise for direct address table Suppose that a dynamic set S is represented by a direct-address table T of length m. Describe a procedure that finds the maximum element of S. What is the worst-case performance of your procedure? for this question i have seen a lot of websites indicating the ...
I'm trying to determine, given an unweighted undirected graph, the maximum number of leaves of any travelling of the graph, which means, the maximum number of leaves among all traversals of every spanning tree of the graph. I know that, given a tree of $n$ nodes, an average branching factor $b_f$ and $n_l$ leaf nodes, ...
Going through the EPI book and I need some help understanding this part. There's a problem, 5.7, that deals with buying and selling twice over a single time-series in order to maximise profit. The input is given as a list of ints. The example they give is: [12, 11, 13, 9, 12, 8, 14, 13, 15] So here the maximum profit...
There is a question in Art of Computer Programming by Knuth which needs us to prove that input-restricted deques and output-restricted deques can form the same number of (and possibly individually same) permutations. The solution is By operating backwards, we can get the reverse of the inverse of the reverse of any...
The lemma is: Let $M$ be an LBA with $q$ states and $g$ symbols in the tape alphabet. There are exactly $qng^n$ distinct configurations of $M$ for a tape of length $n$. I want know why LBA has $qng^n$ configurations. Following is the proof: A configuration of $M$ is like a snapshot in the middle of its computati...
Could someone explain the following question - Given the following statement viz. Consider an input array a[1..n] of arbitrary numbers. It is given that the array has only O(1) distinct elements. What does the statement imply ? Thanks.
Suppose we have a graph $G(E,V)$ with a source node $s$. Now for any $t\in V \setminus s$ I can find the maximum flow from $s$ to all possible $t$ by using the Ford Fulkerson algorithm $|V|-1$ times, once for each $t$. I feel like there must be a faster way to compute all $|V|-1$ max flows that makes use of dynamic pro...
Does adding type-in-type to the calculus of constructions lead to (general) recursion? Such that one can write the Y combinator.
I am reading the paper Slightly Superexponential Parameterized Problems at the moment and have two questions about it: First question: The paper gives a proof of the following statement Theorem 2.1: Assuming ETH, there is no $2^{o(klogk)}$ time algorithm for $k \times k$-Clique. They prove this statement by sophis...
given two arrays of integers A and B of size m, with values in the range [-n,n]. I want an algorithm to count how many common values are in A and B , if a value is repeated we only count it once , for example : $A=\{2,2,14,3\}$ and $B=\{1,2,14,14,5\}$ the algorithm should return 2 . Problem is I need to do th...
We know all the above-mentioned sorting algorithms take $\mathcal{O}(\mbox{N log N})$. Merge sort and Heap sort algorithms take $\mathcal{O}(\mbox{N log N})$ time in worst-case where Quicksort takes $\mathcal{O}(\mbox{N}^2)$. So what is the main difference between these algorithms? Which algorithm is preferable for sor...
I have a directed acyclic graph that has uniform edge weights. I would like to extract from this graph a spanning tree (an arborescence) with the property that the total distance between all pairs of leaf nodes (the sum of combined distances from each pair's nearest common ancestor) is minimized. What I'm ultimately tr...
I recently started studying theory of computation. Recusive enumerable language – closed under concatenation. Sir, I have a doubt regarding understanding of this. Please Note - RE shortform i am taking for Recusively enumerative language One way --> If L1, and L2 are RE s then L1.L2 is RE then RE is closed under conc...
Let $$T(N) = \begin{cases}1 & \text{if } N = 1\\ T(\varphi(N)) + 2T(\sqrt{N}) + \lg(\varphi(N))^3 & \text{otherwise} \end{cases}$$ where $\varphi(N)$ is Euler's totient function. My objective is to find an upper bound so that I can apply the Master Theorem and find a closed-form formula.
Are there methods how to convert Turing machine (e.g. neural Turing machine or other rigorous Turing machine) into the source code/program that is written in some industrial programming language like C++, Java, JavaScript? There is a lot of work on Turing machine synthesis reinforcement learning, but it is very importa...
I am curious to know if there is an algorithm that, given an array of decimals and integers, and given an integer, returns a sequence in descending order, composed of those numbers of the input array whose sum is as close as possible to the number of input, or even be identical, but not greater. I wonder if there is so...
There is a way for finding K entries of N given entries using a binary search? I mean, I have N entries, indexed from 0 to $N-1$ and I have to find $K$ of them that satisfy some constraint. The naive way is to iterate one after one and check whether it answers the condition or not. The naive way of Binary Search is usi...
I have a directed, weighted graph $G = (E,V)$. For example, one might be $|E| = 74000, |G| = 725$. I want to divide this graph into two parts/clusters/communities, taking the edge weights into account. I researched several methods, but the problem is that either they automatically detect the number of parts (communiti...
I'm trying to evaluate the time complexity of the following : foo (n) if n ≤ 1 return 1 if n is odd for i=1 to n print i return foo(n-1) + 1 if n is even i=n while i>2 j=1 while j<i j=j*2 i=i/3 r...
I was trying to look for docs and libraries about a cache akin to RFC 5861 where objects can be in three age states, fresh and expired (as usual), and a third where it can be returned immediately (as though fresh), but asynchronously checked (as though expired). Is this a named pattern? What should be searching for to ...
We are given a finite set $V$ and a set of distance $d : V\times V \rightarrow R\ge 0$ and we wish to compute a tour. Suppose we allow each vertex to be visited at most twice in the tour. How can we prove this is NP complete?
I am trying to look for a division-free algorithms which finds square-root using only addition and multiplication operations, with the initial guess as the number itself. Is there any such algorithms ?
In our organization we have various business units that organize their data in different ways. The folder structure can vary, but they abide by business unit practices when making backups etc. I am to make a scraper that locates backups and copies them. I have found a general way to describe the business unit specific ...
I was once asked a question, given a series of units and their ratios, such as inch, cm, gram vs pound, and a lot of potentially cryptic units and ratios, such as A, B, C, D, ... if I am given n times to do the add() to the table, and m time to do lookup() to get the conversion, such as from "mile" to "inch" and to "cm...
Lemma 2 in "Impossibility of Distributed Consensus with One Faulty Process" is as follows: LEMMA 2. P has a bivalent initial configuration. They prove this by showing that the opposite assumption creates a contradiction. As part of that proof, they state: Let us call two initial configurations adjacent if they diffe...
What conceptually are negative weights on graphs? Why might they have them?
Robert Sedgewick mentioned, if a computer can handle 10x data and the processor is also 10x as fast, then a $ O(n^2) $ algorithm actually runs slower than before. Is this the correct idea when a computer has 10x RAM and can handle 10x data all at once, and also have a processor that is 10x faster, then: A $ O(n^2) $ s...
The following is the Problem 1.4 in [1]: Finding an Eulerian path. Show that if a connected graph has two vertices of odd degree and we start at one of them, Fleury's algorithm will produce an Eulerian path, and that if all vertices have even degree, it (Fleury's algorithm) will produce an Eulerian cycle no matter wher...
In cryptography there are two problems which are part of the foundation of modern public key cryptography. Both of them can be solved in polynomial time on quantum computers. I am talking about: FACT Given: A composite number, i.e. a positiv integer which is the product of some prime numbers: $x = p_1 \cdot p_2 \cdot ...
So the problem states: An array of $N (1 \leq N \leq 2000)$ natural numbers is given. Find the cardinality of the largest subset of that array such that for every two numbers $A$ and $B$ either $A|B$ or $B|A$ (or both). I know you don't like it when people post questions without trying anything, but the only thin...
I want to download a streaming file, but I don't know the real address of that file, only the address where the stream is. How can I download that file? Is it possible to know the address of the file by sniffing the connection?
The time complexity of Weighted Union-Find with Path Compression, for M union-find ops and N objects is said to be $$ O(N + M \lg^*N) $$ and the $ lg^*N $ is "log star N" and is iterated logarithm. It can be almost taken to be a constant, as $ lg^*2^{65536} $ is only equal to 5. Why is it $ lg^*N $ and what kind of ope...
Can we represent $\sqrt{2}$ exactly even with infinite bits in mantissa in floating point notation or otherwise. We actually have to prove this is not possible. But why can't we if we have infinite bits? Infinite bits means the binary representation of the mantissa can be indefinitely large. The mantissa is in IEEE 75...
Consider a t-resilient read-write shared memory system (0 < t < N) with initial failures only: faulty processes take no steps. How could one give a consensus algorithm in this system? I don't understand why the proof of the consensus impossibility doesn't work in this case?
I just graduated from my university with a Computer Science Bachelor. Because of this, I have good Python knowledge, coded a reinforcement learning AI, did machine learning ABCs with Iris flower detection and figuring out digits from the MNIST dataset using ANNs and CNNs, but that's the extent of my knowledge with resp...
let as used in programming languages is defined in lambda calculus as per https://en.wikipedia.org/wiki/Let_expression#Let_definition_defined_from_lambda_calculus The simple, non recursive let expression was defined as being syntactic sugar for the lambda abstraction applied to a term. In that definition, $$ ( let...
This homework solution gives a proof that $L = \{G \mid \text{G is strongly connected directed graph}\} \in N\mathcal{L}$. One suggested way to proof that $L \in N\mathcal{L}$ by proving that $\bar{L} = \{G \mid \text{G is not strongly connected} \} \in NL$ and then using the fact $NL = coNL$. The tutorial uses the fo...
For a multiple choice question: What do we call the LSB? (i)Little Endian (ii)Upper bit (iii)Big Endian (iv)Lower Bit I feel ideally none of them is a true correct choice, but my best bet was (iv) Lower Bit. However, our professor claims that the correct choice should be (i)Little Endian. He even said "LSB stands ...
I need some help with the following task: I have to construct a DPDA for $\{1^ky \mid \text{$y\in \{0,1\}^*$ with $|y|_1 \le k$ and $k \in \mathbb N: k\ge1$}\}$. How can I recognize that the new substring $y$ begins? For example: $w=zy$, where $z = 1111$ and $y = 1001$. This is what I have so far:
I have a question about the equivalence of different automata. I looked up the similiar questions but sadly none of them are exactly, what I need or am looking for. I know some of these are equivalent ( or not ) but for which language class pairs does a real inclusion apply? DFA = NFA ⊋ ? DPDA ≠ PDA ⊋ ? LBA = DTM = NT...
While going through the DBMS book by Korth, it was mentioned : " For a set of transactions, there may be conflict-serializable schedules that cannot be obtained through the two-phase locking protocol. Does this imply that basic 2 PL ensures serializability but does not always ensure conflict serializability ?
I've set up an RNN LSTM network in Java using DL4J as the library. I currently have 500 examples of positive text, and 500 examples of negative text. When I fitness the training data by first training all the negatives and then all the positives, my predictions only favor high positive responses even for things that wo...
The type Bool, as in the datatype with just two point constructors true false : Bool and no higher-dimensional constructors, has decidable equality which is easy to prove directly, e.g. via a type family that maps true to Unit and false to Void. Then we can apply Hedberg's theorem to show that Bool is a Set. What is a ...
Is there a more precise term than simply "casting"? "Casting" often includes for example integer -> float or pointer -> unrelated pointer; whereas I'm describing exclusively casting up or down the type hierarchy.
I'm reading an article regarding approximating sums using KD-trees (similar to FMM). As part of the effort I'm trying to make sense of this article , which is cited. I'm having trouble understanding this part: Computing the maximum variation of weights over all points below node ND is easy. We know the location of x...
Consider a problem with two inputs like (P,L) and |P|=n and L is some positive integer. If my algorithm had a complexity of O(n^L), would that still be polynomial? Or is it exponential? I'm not sure if I should view L as a constant or as 'size of input', since it's not a size but just some number (as in, Knapsack for e...
I am new to the idea of invariants and hope to find more information about it. It can make an algorithm or loop show a high level of certainty / confidence that the code is correct, such as in the case of a binary search, as described in the book Programming Pearls, 2nd Ed. Are invariants true at most part of the loop...
In lambda calculus, a recursive function $f$ is obtained by $$ f = Y g $$ where $Y$ is the Y combinator and $g$ is the generator of $f$ i.e. $f$ is a fixed point of $g$ i.e. $f == g f$. In The Scheme Programming Language, I saw an example implementing a recursive function $f$ that sums the integers in a list: (let ([...
Verbose Motivation for this Question Inspired by this paper about how the problem of counting unlabelled subtrees that are unique up to isomorphism is #P-complete, I was thinking about the problem for the specific case of caterpillar graphs. (a caterpillar graph, $C$, will become a path graph, $P(C)$, by removing all t...
The problem is as follows: given black box access to a strictly quasiconvex (or unimodal) function $f$ on an interval, say [0, 1], query $f$ repeatedly at various points to find a subinterval containing the minimum. After $n$ queries to $f$, if the interval's length is reduced by a factor of $t$, the algorithm's score ...
My Turing machine starts with an empty tape. It writes a random word of the set $0^n1^n$ to the tape. Hopefully i made no mistakes. My question is about the productions coming out of state $q_0$: $δ(q_0, blank)=(0,R)$ and $δ(q_0,blank)=(blank,L)$. (see image below). Their purpose is to generate a random amount of $0$ b...
MergeSort has two parts, "divide" and "merge" (arguably three if you include "recurse" as its own part in the middle). I'm interested in the "merge" part, which tends to look like this: consider two priority queues list1, list2 initialize an empty sorted list while neither list1 nor list2 is empty: find lowest elem...
The well-known textbook Introduction to Algorithms ("CLRS", 3rd edition, chapter 3.1) claims the following: $$ \sum_{i=1}^n O(i) $$ is not the same as (I'm not using DNE because the book explicitly says "is not the same as") $$ O(1) + O(2) + \dots + O(n) $$ Why is this? How are we to explicitly represent the first sum...
Let $G$ be an interval graph. For any two vertices $u,v$ in $G$, how many induced paths are between them in $G$? Is it polynomial in terms of the number of vertices in $G$?
I have already solve this problem using forloop. Given an nxn matrix A. Here n is number of row and column. Write a recursive function to find the sum of the diagonal elements of A. Example: 3 2 1 6 3 4 9 8 3 Output 9 #include<stdio.h> void main() { int mat[12][12]; int i,j,row,col,sum=0; pri...
I tried referring a few material (videos on youtube and this link as well), but I still couldn't wrap my head around the concept. My (brief) understanding of the Virtually addressed, Physically addressed and Virtually indexed Physically tagged cache: Virtually addressed cache The virtual address generated by the CPU ...