instruction
stringlengths
35
29.1k
$$A_N = A_{N-1} - \frac{2A_{N-1}}{N} + 2\left(1- \frac{2A_{N-1}}{N}\right),\quad \text{for}\ N > 0, A_0 = 0.$$ Probability for 2-node to become 3-node is $\frac{2}{N}$ and for 3-node to become 2-node is $\frac{3}{N}$. 2-node contains 1 element, 3-node contains 2 elements. I think that $A_{N}$ is the number of 2-nodes o...
I’m having a hard time finding anything thorough. I have found some courses with titles like "parallel and concurrent programming in Java", but I'm looking to learn general techniques, not their use in {insert specific technology}.
Suppose for each positive integer $N$, we have a graph $G_N$ with $N$ vertices labelled $1$ to $N$ (so $\log N$ bits are required to specify a vertex). Suppose we have a PSPACE algorithm to determine whether two given vertices in $G_N$ are adjacent (ie the space used is $P(\log N)$ for some polynomial $P$). Consider th...
Non-computer scientist here. Suppose you have a problem of the following general form: There is a class of objects, and a restricted set of moves to pass between objects. It is known that all such objects are related by this set of moves. There's a problem of the form "Given two objects $X_1$ and $X_2$, can you mov...
) Suppose G is a simple graph with n vertices. Prove that G has twice as many edges as vertices only if n ≥ 5. ? Any one can help?
I'm not sure what algorithm to use in the kind of problem described below, any suggestion to put me on the right track, even at any way is desirable. Thank you in advance. You have some 2D field in a form of two dimensional array (full of 0 & 1 values). There are certain rules, that describe how to get from previous a...
In the paper "Tight bounds on the complexity of the Apostoliko-Giancarlo algorithm" by Crochemore and Lecroq authors prove that algorithm performs not more than $1.5n$ comparison of characters in the processing stage. If I understand their proof correctly than there is no dependency on the bad character rule. Is it tru...
I understand that DFAs recognize regular languages, and PDAs context-free languages, but these are a little bit too theoretical. I am wondering if we can implement common functions or solve common problems with DFAs and PDAs instead of Turing machines (or in a Turing-complete language). By "common", I mean either one o...
Wondering if there are any documents, theories, or methodologies for dealing with mutable memory mathematically. Basically a formal algebraic model of how computers manipulate memory. Along the lines of, say I want to model an add operation at a low level, and it writes its output to a register. Then we can model the c...
I once had this question https://math.stackexchange.com/questions/1083338/structural-design-meta-optimization-is-there-mathematical-theory-optimiza about the methods for finding optimal structures, designs and policies (as another kind of structures - set of rules), i.e. optimization of the structure of the models not ...
I am studying this part for a merge sort implementation: void mergeSort(int arr[], int l, int r) { if (l < r) { // Same as (l+r)/2, but avoids overflow for // large l and h int m = l+(r-l)/2; // Sort first and second halves mergeSort(arr, l, m); mergeSort(arr, m+1, r); merge(arr, l, m, r);...
Given an undirected graph $G$ with $n$ vertices and $m$ edges, we build a cut as following. Initially sets (of vertices) $A$ and $B$ are empty. For each vertex $v$ we flip a fair coin and according to outcome we put $v$ either in $A$ or $B$. Let $X$ be a r.v. denoting the cut size, i.e. the number of edges between set...
I was reading (wikipedia) about how the rope data structure might be suitable for a text editor. Within the article it mentions "If only nondestructive versions of operations are used, rope is a persistent data structure. For the text editing program example, this leads to an easy support for multiple undo levels." I...
Given a directed graph and an integer $N$, is it possible to detect a simple negative-weight cycle whose edges sum to $N$ in polynomial time? I thought about modifying the Floyd-Warshall algorithm to check if the diagonals equal $N$ as they get set, but I realized this wouldn't work if a vertex appeared in multiple neg...
I am trying to understand the Hungarian algorithm for the assignment problem. I found this presentation which gives an excellent explanation about the algorithm. However, there is one step I do not understand. Step 3 (pages 13, 16) says "Cover all the zeros of the matrix with the minimum number of horizontal or verti...
In the paper https://web.stanford.edu/~gavish/documents/sipser-pvsnp.pdf , it is mentioned under the Status section that boolean circuits have been used to try and solve P vs NP. Can anyone explain to me in simple terms how boolean circuits are used for solving P vs NP?
Is it possible to efficiently create a bloom filter with 10^12 buckets on a single machine with 32GB of RAM and a hard drive. We can assume that the keys are already on the disk and are small in size?
A common approach to decide whether two given graphs are isomorphic is to compute the so-called canonical label (alternatively, canonical graph) of each graph and to check whether those match or not. Tools such as Nauty compute the canonical graph via search trees that are pruned using some clever ideas that rely, amo...
Call two proper graph colorings equivalent if one can be obtained from the other by a permutation of the colors. In other words, they are the "same" coloring. I'm interested in finding proper non-equivalent colorings. Of course, the decision problem of determining whether or not there is such a non-equivalent coloring ...
If a graph has a unique MST, then its edge weights are distinct. True or false ? Justify your answer.
Let A be an array A[0..n-1]. The array has n items. Each item is labeled with one of these letters: {R,V,B}. For example, A[0].label=V, A[1].label=R, etc. What is the best algorithm for sorting items of A in lexicographic order? What is its time complexity? I don't know if I could apply counting sort, because each elem...
Being able to represent a Boolean circuit is useful in a number of areas of Computer Science, such as Circuit Satisfiability, Zero-Knowledge Proofs and Garbled Circuits. Are there any standards for how such a circuit should be represented in a text file? By a standard I mean very specific instructions about how wires s...
The function $f$ takes two integers and produces one integer $f(a,b) \vdash 3*(b-a)$ The only instructions I can use are +1, -1, and go to loop At a high level, I know how to write $z = 3*(a,b)$
Wikipedia defines the IP complexity class as follows: A language $L$ belongs to IP if there exists $V,P$ such that for all $Q$, $w$, $$w\in L\Rightarrow Pr[V\leftrightarrow P\text{ accepts }w]\geq2/3$$ $$w\notin L\Rightarrow Pr[V\leftrightarrow Q\text{ accepts }w]\leq1/3$$ Note that this definition is asymmetri...
We have given a multiset of $N$ integer, both positive or negative. Consider all $2^N$ subsets, sorted by their sum (the empty subset has sum 0). We want an algorithm that outputs only the first $K$ sums. The problem is that $N$ can be very big number (up to 100000), so we cannot generate all subsets. How to optimize ...
Currently, I am looking for an lossless compression algorithm that is suitable for a large amount of text, that will be further encrypt by AES and use as the payload in steganography. Based on A Comparative Study Of Text Compression Algorithms, it seems that Arithmetic coding is preferable in Statistical compression te...
My question is about how to prove the correctness of this algorithm, I know it is not a good algorithm, it is not efficient and can be improved. How could I prove it still returns the desired value? What are the loop invariant and variant? How to insert assertions between lines? The algorithm goes like following, Algor...
Since languages with recursible first-class functions are Turing-complete, they should be able to express anything expressible in any other programming language. Therefore, it should be possible to model conditional expressions (i.e. if-statements) with first-class functions. Could someone illustrate how to do this?
I was asked the following problem in an interview: Let M be a N X N matrix, such that: M[i][j] >= 0; 1 <= i,j <= N and i != j M[i][j] = 0; if i = j M[i][j] = M[j][i]; 1 <= i,j <= N We are allowed to increase any of the entry in M[i][j] by any positive number, that we can increase the value of any cell in M[i][j] as ...
I am currently reading this paper on library operating systems, more specific on Graphene. I stumbled over the following sentence: "Because multiprocess abstractions, such as signals or System V IPC, tend to be idiosyncratic, an essential problem is identifying a minimal, host-independent substrate upon which to implem...
Can anyone find a map(injection) $h$ from the set of all possible strings $S^*$ to the natural numbers $\mathbb{N}$? $$h : S^* \rightarrow \mathbb{N} $$ Assume $S$ is finite. I would prefer an efficient map. There should be nice applications of this question for perfect hashing, right?
So here's the code:- DECLARE number as INTEGER PRINT "Enter a number" INPUT number DECLARE randomarray [1:number] AS INTEGER Is this possible? i.e whilst declaring arrays, can we use variables? Note:The question is strictly limited to pseudocode or general programming language
An open problem in complexity theory is whether NC equals P. I'm somewhat confused because I would have thought that it's obvious that NC != P because of hash onions. A hash onion is when you start with some input $i$ and repeatedly hash $n$ times: $$H(i), H(H(i)), ..., H^n(i)$$ Given an input $i$ the amount of work to...
Knowing that $C$ is a context-free language and $R$ is a regular language, how to prove that $C / R = \{w| \exists x \in R: wx \in C\}$ is also a context-free language?
I am a CS undergraduate. I understand how Turing came up with his abstract machine (modeling a person doing a computation), but it seems to me to be an awkward, inelegant abstraction. Why do we consider a "tape", and a machine head writing symbols, changing state, shifting the tape back and forth? What is the underlyi...
An indexed file contains at most $2^6$ records. The indexed file is stored in a memory with $2^{14}$ cells. What is the maximum size of the index in bits? If I would like to find the maximum size of the memory in bits I can simply just: $2^{14} \ast 8 \text{ bit } = 131072 \text{ bit}$ I found the solution but no e...
I need an algorithm to calculate number of pair of vertices with at least 2 distinct paths between them in a undirected graph - the graph is connected - distinct paths = distinct edges ex: no. of vert = 3 and no. of edges = 3 and we have (1, 3) (1, 2) and (2, 3) valid paths from 1 to 2 are 1-3-2 and 1-2 - count only p...
I'm trying to prove that $$k\text{-Matching}\le_p k\text{-Disjoint-Triangles}$$ but I was told that the $k\text{-Matching}$ (decide whether a graph has a matching of size $k$ ) can be solve in polynomial time. Then I'm stuck here. Could anyone help me out here?
Here is a question I encountered:- Read this section of program code that inputs 10 positive numbers and then outputs the smallest number input. Identify three changes you would need to make to find the largest number input instead of the smallest number. Small = 1000 Counter = 0 REPEAT INPUT Num I...
My interest is strictly theoretical at this point, but ultimately applied. Is there any problem, theoretically, with defining a byte with m bits, and flipping single bits to connote T/F for a given ordinal value/position? Essentially I'm looking for the most compact method reading/writing ordinal values in an array t...
Suppose we want to find the sum of the $k$ largest elements of $n$-sorted arrays. All arrays are containing $k$ elements. All elements are between 0 and 1, and the the sum of all elements in array $i$ equals to $S_i$. Instead of using a min-heap to find the $k$ largest elements (and thus, deriving the sum of the $k$ l...
In our daily life we use both coding and programming for the same meaning. I want to know the difference between these terms (If any). If they are used for different meanings than please anyone can aware us about it, So we can correct ourselves.
Is there a completeness property for query languages (like SQL, Cypher, Datalog, etc) that is analogous to Turing completeness in programming languages? I wondered if it is something like being able to describe any subset of the facts in the database.
I'm currently programming in an unnamed turing complete language which has support for pointers, primitive data types, structures, closures, and garbage collection, among other things. I'm trying to use this language to implement an object oriented design pattern. So far, I have implemented the following algorithm: mak...
Why the number of (NIL) leaf nodes in n-element red-black trees is n+1?
Boyer-Moore's majority vote algorithms can be used to determine the majority element in a linear time and constant space. The intuition behind finding the majority element is understandable as it has to be greater than the count of other elements in the input sequence if a majority element exists. However, there is ...
How can I design a Turing machine that accepts the language $\{1^{2^n} : n \geq 0\}$? Here is my attempt: [![enter image description here][1]][1]
I am wondering if studying the Theory of Computation/ Computational Complexity theory, specifically Sipser's 'Introduction to the Theory of Computation' will help me do machine learning/statistics/data science better. Are there any connections? I intend to study the book even if there aren't any connections.
I'm trying to understand the theory behind finding the optimal $h$ value for differentiation in this definition: $$ \frac{f(x+h) - f(x)}{h}$$ as $h$ tends to 0. Here is my understanding: Truncation error comes from say approximating the value of $f(x+h)$ using the taylor series. In this case, it could be that: $$ f(x...
All numbers from $1$ to $n = 2^k-1$ are written in unknown way in a full binary tree of height $k$. We say that a number $t$ lies between $i$ and $j$ if after removing $t$ from the tree we obtain that $i$ and $j$ are in different connectivity components. Propose an algorithm for determining a number in the root of tre...
I'm having troubles with this question. If $L\in R$, there there is a turing machine $M$ that decides it. My idea is to build a turing machine $M'$ that somehow goes over all the possible permutations of the input word, in a way that separates it to groups of smaller words for $M$ to test. If there is a permutation tha...
I found out an exercise where you have to prove the correctness of the following CFG: Let $L=\{ 0^i 1^j|2i \leq j \leq 3i \}\:$ and $\: G: S\rightarrow 0S11 | 0S111| \epsilon$ claim: Every string $w \in L$ can be generated by $G$. It says that it's not possible to prove the claim by induction on the length string, an...
It is somewhat confusing to me when to use quantifiers in tuple relational calculus (TRC). I stumbled upon following problem and I am still scratching my head thinking why not TRC query can be constructed without using existential quantifier. The given problem reads like this: Relations: student (rollNo, name, degre...
Suppose I want to make a left derivation tree of an expression, but the expression includes operators that are right-to-left associative. Would I still expand the left-most variable first in my tree? For example, the expression a + b ** c ** d where ** is right-to-left associative, and + is left-to-right associative.
I'm learning BNF, and the text I'm using gives a simple grammar for integer expressions like this: <expression> ::= <number> | <expression> <operation> <expression> <operation> ::= + | - | x <number> ::= <digit> | <digit> <number> <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 This makes sense to me, but then it go...
I am solving an optimization problem using SPEA2, my problem has three cases with decision variables 25, 50 and 100 in each case. I want to ask if there is some relationship between the number of variables and iterations of evolution process. I mean to say I run algorithm fewer times when decision variables are 25 than...
Let L1 = L2 union L3 find values such that L1 is context free and L2 and L3 are not. So far I have: L1 = $a^nb^n$ L2 = $a^*b^*$ L3 = $a^+b^+$ Is this acceptable?? Since L2 covers everything including epsilon and L3 is the same but does not include epsilon? I know L2 is regular so I guess that is also not a CFL. Another...
$H$ is a family of weakly universal hash functions if for two elements $x,y$: $$ P(h(x) = h(y)) \le \frac1m, $$ where $m$ is the size of the domain, and $h$ is chosen at random from $H$. Given a hash family, how could one prove that it is weakly universal. I understand how to prove it isn't (proof by counter-example)...
I have the problem: Show that there exists a real number for which no program exists that runs infinitely long and writes that number's decimal digits. I suppose it can be solved by reducing it to the Halting problem, but I have no idea how to do so. I would also appreciate links to similar problems for further p...
Given a sequence of numbers $l_1, \ldots, l_n$, I want to find for each index $i$ the next possible number to the right of $l_i$ (if any) that is different from $l_i$. What is the best time and space optimal solution to do this? The numbers may be repeating and are in no particular order.
Plz draw. Turing machine if Design a Turing machine in the following three ways of descriptions that decide the language L = {12n+1 : n ≥ 0}, the language consisting of all strings of 0s in given exponential function. 1. The Formal description of Turing machine 2. Implementation level description of the Turing mach...
I believe from common sense that video shape recognition problems (identifying shape of a moving object) is of natural interest in many real world situations. The process of identifying is understood as recognizing/finding one selected changing shape/signal among all the present shapes/signals. Ideally, it should be po...
I am doing research on paging algorithms. While learning about the working set algorithm from several scientific sources I was not really able to figure out where exactly the working set is defined or realized. I can only imagine two ways of realising this. The first is to put it into the page table file with indicatio...
A graph can be expressed as an structure $G = <A,R>$ satisfying the axioms $ \forall xy R(x,y) \rightarrow R(y,x)$ and $ \forall x \lnot R(x,x)$. How to extend the structure and/or axioms to express a 5 colourable graph?
A set $A$ is quasi-reducible to $B$ ($A \leq_Q B$) if there is a recursive function $f$ such that $$x \in A \iff W_{f(x)} \subseteq B$$ Or equivalently $$ x \in \overline{A} \iff W_{f(x)} \cap \overline{B} \neq \emptyset $$ Where $W_{e}$ is the domain of the recursive function of index $e$, i.e. $W_{e} = \{y : \varphi_...
A procedure is a sequence of program instructions that perform a specific task, packaged as a unit (Techopedia). We use block structure to make our code more readable by using indentations and spaces. Now, is one block the same as a procedure and is vice versa true?
We consider two algorithms, Algo1 and Algo2, that solve the same problem. For any input of size n, Algo1 takes time $T_1(n)$ and Algo2 takes time $T_2(n)$. Prove or disprove each of the following statements. To prove a statement, you should provide a formal proof that is based on the definitions of the order notation...
I have a sample that is collected to verify the accuracy of a new random number generator. Applying the goodness of fit test to check if this sample comes from the Standard Normal Distribution and Uniform Distribution, I found out that both of these accept null hypothesis although they are contradicting to each other. ...
I have some experiences with Convolutional Neural Networks before. I have a question regarding the Bilinear Sampler used in "Unsupervised Monocular Depth Estimation With Left-Right Consistency" (the link to it is provided here: https://arxiv.org/pdf/1609.03677.pdf and https://www.youtube.com/watch?v=jI1Qf7zMeIs) I unde...
We all know the partitioning problem: Given a super-set S of integers, can we partition S into 2 subsets with the same sum. And of course this problem is NP-complete. My question is - let's denote M as the sum of all numbers in S. Is O(M) considered to be polynomial in this case? I will clarify: I want to prove that a ...
I am trying to argue that a certain problem is in $\mathsf{PSPACE}$ and my question is, essentially, whether it is ok to have an algorithm that takes an exponential number of steps as long as, overall, the whole thing stays in polynomial space. The context for this is that I have a naive algorithm which, it seems to m...
For example, take the problem "Does M Halt on the Blank Tape?". My approach was to reduce the halting problem to prove this problem is also undecidable. I generated a Mw by Writing w on the tape Moving to the leftmost blank Running M Then, of course there is the M-halt-on-blank function: if(Mw halts) true else fa...
Suppose you have to provide a derivation by natural deduction, e.g. $((A \rightarrow B) \rightarrow A) \rightarrow A$ Is it a good advice to start from backwards on in general? I mean doing the derivation from bottom to top. The required premises or hypothesis should arise by itself.
Is there an algorithm that can find p + stuff within t, where stuff is any set of characters, not just HTML markup? Sample text to search (t): some HTML markup Some text and <span>more</span> text <h3>and some more</h3> text in addition to <strong>more unknown text</strong> Sample pattern to find (p): Some text and m...
I have 10 LDAP systems which contain users and groups in the form of objects. Each user / group is identified by a distinguishedName like name/systemName where name is name of user or group. Group objects store which users are members of the group. GroupA = {UserA, UserB, UserC ....} GroupD = {UserF, UserB, UserK .......
This question is about segment-tree as described in this Wikipedia article. When constructing the tree (inserting the new input-interval), if the input-interval doesn't contain the node-interval we have to recurse into node's child, where child-interval intersects input-interval. But what if both children-intervals int...
I have created an adjacency matrix which looks something like this A B C D E F G H I A 0 0 0 0 0 0 0 0 0 B 1 0 0 0 0 0 0 0 0 C 1 0 0 0 0 0 0 0 0 D 0 0 0 0 0 0 0 0 0 E 1 1 0 1 0 0 0 0 0 F 1 1 1 1 1 ...
Suppose we want to represent some arbitrary Boolean function $f(x_1,x_2,...,x_N)$ on $N$ bits. We can explicitly specify such a representation using the disjunctive normal form. For "most" Boolean functions, this representation will be of length exponential in $N$, and incompressible (as per Shannon). We will assume we...
I am going through the following lecture notes by Frank Pfenning : http://www.cs.cmu.edu/~fp/courses/15317-f17/lectures/02-natded.pdf In page no 5 I cam across the introduction rule . The rule reads that $A$ is contained in $B$ if $B$ is true under the assumption that $A$ is true . But in the text a subtle point ab...
I visit some question but their implementations are slightly different and my doubt is not like theirs. I have this code in Javascript. The code is typical BST implementation with methods to support in-order traversal. The code that is the most relavant for this question is the the inOrderTraverse and inOrderTraverseNo...
Given a sorted $n\times n$ matrix $A$ of real values. That is $a_{ki}<a_{kj}$ and $a_{it}<a_{jt}$, when $i<j$. Propose and algorithm, finding two elements of this matrix with the sum nearest to a given value $q$. The restriction of memory is $\mathcal{O}(n)$. It is not allowed to change a given matrix. The naive appr...
Suppose that we have a family $F=\{a_1,\dots,a_s\}$ of sorted arrays to merge. Our strategy is to choose two of them, say $a_i$ and $a_j$, remove them from $F$, merge them and put the resulting array back into $F$; we keep doing that until there is only one array in $F$. We will use a greedy strategy: at each step, we ...
So i tried turning the following NFA into a GNFA (first attempt). Please don't ask why i chose to do such a complex NFA on my first try, i just like the challenge i guess? ab is the concatenation of a and b, the language consists of a, b and c. $L = \{a, b, c\}$ I calculated the following to be the Regular Expression ...
I have being reading up on complexity classes (in Rieffel & Polak, 2011; pg149). I am slightly confused about something. Does for example $P$ (DTime($n^k$)) include all problems that can be solved faster then polynomial in time (e.g. logarithmic) on a deterministic Turing? And likewise for e.g. PSpace (DSpace($n^k$)) a...
It is my understanding from what I have read that you need to compile separate executables for 32 bit and 64 bit machines. So if I compile a C program for example I need to compile 2 different binaries for 32-bit and 64-bit machines. However, it seems like intuitively a compiler should just be able to compile down to i...
I'm reading the "Art of Assembly" 2nd Edition by Randall Hyde. In the book the author seems uses his own language called High Level Assembly (HLA). Coming from a C Background, I question how useful this is in learning (real x86/NASM for use on Linux) Assembly. But, looking it up there seems to be a term "High Level Ass...
Revised: In my previous question, I was confused about the implications of the diagonalization language. I concluded that it proves there are languages for which there are no recognizable turing machine. However, how is this implication different from the halting problem? Do they both just reinforce the limitations of ...
Given array $A$ of size $n$, we want to calculate $\sum_{i<j<k\leq n} A_i \cdot A_j \cdot A_k$. Is there way to speed this up rather than the standard $O(n^3) $ calculation with 3 for loops. I haven't worked with sums so I don't know their properties, but I was thinking if there is some way to rewrite the formula to ge...
I'm working with trees in a project where I need to test various tree-making algorithms and their outcome. A frequent quantity I look for is the number of branches of a tree. Is there a commonly used name for that aside "number of branches"?
I need to develop algorithm for one task. I have 500 types of object, each type is represented by a group of qualifiers (about 20 for each type, the same qualifier can be used for different types), where qualifier is a simple predicate (but calculation of the predicate can take some time, as you have to check data in ...
Given a graph and an integer $k$ is there an independent set larger than $k$ is INDSET problem and is there a cut larger that $k$ is the MAXCUT problem. Is there standard way to convert to 3SAT from these problems that preserves number of solutions? I have only seen reductions other way in standard texts. Since all the...
Consider following task: we have an input of N+1 lines, where first line contains N ≤ 150000 - number of items, and then we have N lines, each one contains one item, which is a tuple (number id, number m), id ≤ 10^7, m ≤ 100. We have to perform a stable sort on this sequence and print the result. Sample input: 8 1 2 1...
Given a string that consists of only digits, return an integer array (without shuffling sequence of string characters) such that the array elements form a Fibonacci series based on indices. If such an array can't be formed return a new array with -1 as the only element. Fibonacci sequence based on indices means that [e...
From my understanding, a problem amenable to a dynamic programming solution has these two properties: Overlapping Subproblems — The same subcase (a subsection of the overall problem) keeps reappearing. Thus, memoization can be used to boost performance. Optimal Substructure — The problem can be broken down into smalle...
int sumHelper(int n, int a) { if (n==0) return a; else return sumHelper(n-1, a + n*n); } int sumSqr(int n) { return sumHelper(n, 0); } I am supposed to prove this piece of code which uses tail recursion to sum up the squares of numbers. That is, I need to prove that for $n ≥ 1$, $sumsqr(n)=1^2+2^2+\dots+n...
Floyd–Warshall calculates minimum distance between any two vertices in the graph. for(int k=0;k<n;k++){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]); } } } So, it basically calculates distance between every two nodes i,j having 1 inter...
I analized the bubble sort algorithm and I cannot see why they "implemented this way". I wrote down the results as the two loops performed their works and, with my small testing arrays, the outer loop condition to stop was always too much (the array was sorted when "i" was like 2, when the loop conditon to stop was 5....
I have the language $L = \{a^i b^j c^k \mid i+j=3k\}$, however I am struggling to convert it to a CFG. I have made it into a PDA fairly easily, its just now getting this to the CFG which is the issue. I have thought about dividing it into 3 cases then taking the union of them for example: $i=0, j=3k$ $i=3k, j=0$ But th...
In the example below, is this guaranteed to be safe? I see two processes that require the same resource. It's not a direct cycle but it seems to be a possible deadlock where P0 could get held up.
s = n while (s > 4) s = s / 2 else s = s - 1 Let $T(n) = \Theta(S(n))$ where $S(n)$ is number of while-loop runs. $S(n)=1 + S(n/2)$ if $n$ is even $S(n)=1 + S(n-1)$ if $n$ is odd $S(n)=0$ if $n \leq 4$ By converting n to a binary number, and I think if $n < 2^k$, then $S(n) \leq k - 1$ I have come to this relati...