instruction
stringlengths
35
29.1k
Having a hard time formulating the proof for this. The professor kinda breezed through the problems and I just want an explanation on how best to tackle this and how one would prove what it's desiring: "Consider the following heuristic for building an approximate TSP cycle for a graph that satisfies the triangle inequ...
An algorithm is a finite sequence of operations on an abstract machine. (Correct me, if I am not correct). If two algorithms can take the same set of inputs, and for each input, they generates the same sequence of intermediate and final results/output, are they the same algorithm? What I am thinking is if an algorithm ...
I have a set of numbers S of cardinality N, and a collection of sets each containing some subset of S. The cardinality of each of these sets can be anywhere from 1 to N. The number of sets is variable, but is necessarily at least N. e.g. $S = \{1, 2, 3, 4, 5, 6, 7, 8, 9\}$ Sets: $\{3, 6\}$ $\{1, 2, 5\}$ $\{5\}$ $\{2,...
An algorithm on an abstract machine is a finite sequence of operations of the machine. (Correct me if I am not correct.) However, there are different kind of algorithms, such as deterministic, non-deterministic, and randomized algorithms, and possibly others. Are these algorithms running on deterministic Turing Machine...
I have an arbitrary 2d area on the xy plane. I want to cover it with N discs such that all points in the area have at least one disc overlapping it. A disc with center (xc, yc) placed inside this area has a radius r that is a function of (xc,yc). I am looking for references or algorithms that can help me to minimize N ...
Given a Bayesian network, say a -> b -> c, all binary random variables (I won't show the CPTs, assume they are given). You are told b and c are true. How do you calculate the P(a=True)?
Given a sequence of numbers $a_1, a_2, ..., a_n$, a number $a_i$ is called the $k$ local maximum $\iff i > k$ and $a_i$ is the largest number among the $(k+1)$ numbers $a_{i-k}, a_{i-k+1}, ..., a_i$. Given a sequence of $n$ numbers $a_1, a_2, ..., a_n$, and an integer $k$, I am requested to find all $k$ local maximums ...
I am trying to classify the Differential Evolution algorithm according to the framework in the book: Introduction to Evolutionary Computing The authors classify the field of evolutionary computation into 4 paradigms: Evolutionary programming Genetic programming Evolutionary strategies Genetic algorithms I have rule...
in one of my algorithm courses i'm studying the FM-Index. In one of the exercise I'm trying to do I was asked to give a procedure to search patterns of the form w* (where * indicates any character) using backwards search (see here). How could this be possible? It seems to me that the algorithm already returns all the p...
If the runtime of a recursive algorithm could be expressed as $T(n) = \begin{cases}O(1) & n \leq c \\ k * T\left(\frac{n}{k}\right) + \left(k + n * k \right)\end{cases}$ what would be the result of the asymptotic analysis (the Landau class)? $k \in \mathbb{N}, k \neq 0 $ is a constant value. I would say that $k$ even ...
We want an algorithm that, given an array of length $n$ of integers, find the minimum difference between two integers in the array. One such algorithm is to sort the array and check adjacent pairs of numbers. This takes time $O(n\log n)$. Is there a faster way, e.g., an $O(n)$ algorithm?
Looking for Newton's method in Wikipedia, I read the following: In numerical analysis, Newton's method (also known as the Newton-Raphson method), named after Isaac Newton and Joseph Raphson, is a method for finding successively better approximations to the roots (or zeroes) of a real-valued function. After desc...
I'm aware of prime decomposition and parallel approaches to calculating one factorial; however, if I want the factorials of all numbers up to $n$, is there anything more efficient than the naive approach? As far as I can tell, at least the prime decomposition algorithms aren't any more useful here than the naive approa...
We want an algorithm that, given an array $A$ of length $n$ of integers (indexed by $A[0],A[1],\ldots,A[n-1]$, determine values $i<j$ that maximizes $j-i $ subject to $A[j]>A[i]$ (if such values $i,j$ exist.) One possibility is as follows: First check whether the array is non-increasing. If so, no such $i,j$ exist. Els...
Assuming we have an array with $n$ Elements and want to find an unique element by randomly (uniformly) choosing. What would be the average case runtime? My thoughts so far: The chance to find the element is $\frac{1}{n}$ in every step. Thus, to find the element after $k$ steps is $(\frac{1}{n})^k$. Now we can calculate...
In one of his conference talks Jim Weirich derives the applicative form of the y-combinator by refactoring a partial definition of factorial. The starting point in his talk is different than what follows here but the ideas are all the same. Let's start with the following function # partial definition of factorial f = \...
I know how to calculate the CPI or cycles per instruction from the hit and miss ratios, but I do not know exactly how to calculate the miss ratio that would be 1 - hit ratio if I am not wrong. I know that the hit ratio is calculated dividing hits / accesses, but the problem says that given the number of hits and misses...
In computation theory, when talking about the computability and complexity of a problem, what is the definition of a problem? How specific should a problem be? For example, can the followings all be function evaluation problems? evaluate $f$, where $f(x)=x^2, x \in \mathbb R$ evaluate any function in $\mathbb R^{\ma...
My definition of an algorithm is a finite sequence of operations provided by an abstract machine, where the operations are executed one after another in the order specified by the sequence. Different machines may provide different sets of operations, so the definition of an algorithm depends on the abstract machine an...
Let $x$, $u$, $v$, $w$, $y$, $x'$, $u'$, $v'$, $w'$, $y'$ be words. If $y'x' = xy$ $y'u'x' = xuy$ $y'v'x' = xvy$ $y'w'x' = xwy$ $y'v'u'x' = xuvy$ $y'w'v'x' = xvwy$ all hold, then I need to prove that $y'w'v'u'x' = xuvwy$. I'm a little confused how to prove this, How can I form $y'w'v'u'x'$ from the equations above?
Is there a generalization of maximal satisfaction (MAX-SAT) based on infinitely many variables? One natural occurrence of such problem is the general Ising model in material science.
I am trying to understand what hamming distance of a code is needed to detect a d-bit error, or to correct a d-bit error. This is what I have found around the web: If two codewords are Hamming distance $d$ apart, it will take $d$ one-bit errors to convert one into the other. To detect (but not correct) up to $d$ er...
I need some help with the following recursion: $T\left(n\right)=T\left(\log_{2}n\right)+O\left(\sqrt{n}\right)$ More specifically I wish to find and prove the upper bound on it. I have a hunch it is $O\left(\sqrt{n}\right)$ but have gotten stuck proving it really is this. Any help is appreciated Thank you!
I want to normalize elements in an array. The solution I found is to take the sum of the elements and divide each element with this total. Can you find more efficient way of doing this? The runtime I achieve is 2N. Any better idea? normalize(array) { sum = 0; for i = 0 to array.size() do sum += array[i]; ...
What is the lower bound for finding the third largest in a set of $n$ distinct elements? For the case of finding the second largest, we have the tight lower bound of $n + \lceil \lg n \rceil -2$. The adversary argument can be found in this lecture, which also provides an optimal algorithm using the "Tournam...
What is the difference between the LZW and Huffman's coding of text compression ? I've read this and this , but I'm not able to distinguish ?
Background Information I am currently doing research for my final year project in college. I am planning on building an ambulance booking system that will ease the process of booking an ambulance for patient transfer - that is to transfer a patient from one hospital to another. A subsystem of the overall booking system...
In the second edition of the book of Cormen "Introduction to Algorithms" appears the following example (in the left part is the residual network while in the right part shows the flow results): I have a problem understanding the part (c). The augmenting path is $s\rightarrow v_2\rightarrow v_1\rightarrow v_3\rightarro...
In the Paxos consensus protocol, a fact that follows from its construction is "any two majority sets of acceptors will have at least one acceptor in common". This observation can be extended to any N majority sets of acceptors having either at least one acceptor in common, or acceptors that are distinctly present in ea...
This question repeats one that was closed. Let $x, u, v, w, y, x', u', v', w', y'$ be words satisfying $y'x' = xy$. $y'u'x' = xuy$. $y'v'x' = xvy$. $y'w'x' = xwy$. $y'v'u'x' = xuvy$. $y'w'v'x' = xvwy$. Show that $y'w'v'u'x' = xuvwy$.
This is an extension of a previous question asked by a different user earlier: Let $x, u, v, w, y, x', u', v', w', y'$ be words satisfying $y'x' = xy$. $y'u'x' = xuy$. $y'v'x' = xvy$. $y'w'x' = xwy$. $y'v'u'x' = xuvy$. $y'w'v'x' = xvwy$. Then $y'w'v'u'x' = xuvwy$. Now, using the above result, show that a regular la...
Note that this is not shuffle but perfect shuffle, defined as follows: Let $w = a_{1}a_{2} \ldots a_{n}$ and $x = b_{1}b_{2} \ldots b_{n}$ be two strings of the same length. Then the perfect shuffle of $w$ and $x$ is defined as $a_{1}b_{1}a_{2}b_{2} \ldots a_{n}b_{n}$. So the question is: are context free languages clo...
I don't know what is meant by "decision version of integer programming". I know ILP, but this terminology has me confused.
Define $FH(L) = \{x \in \Sigma^* : \exists y \in \Sigma^* \text{ with } |x| = |y| \text{ such that } xy \in L\}$. In other words, $FH(L)$ is the set of first halves of even length strings in $L$. Given this, if $L$ is context-free, must $FH(L)$ be context-free? Here's my attempt at a proof: Since $L$ is a CFL, the...
Suppose we are given a collection of $n$ strings, $S_1,\dots,S_n$. I would like to know whether any of those strings is a substring of any other string in the collection. In other words, I'd like an algorithm for the following task: Input: $S_1,\dots,S_n$ Output: $i,j$ such that $S_i$ is a substring of $S_j$ and $i\n...
I'm taking an introductory quantum computations class and I am attempting to solve the following question(s), but we haven't touched on black box algorithms like this in class, and I honestly don't know how to solve the question at all. Would it be possible to help me through the steps? Question. Consider the set of ...
I am aware that as the number increases in Digits the process of locating the two prime numbers that when multiplied produce the given number is increased as well. I also know that is it somewhat exponential or even more and with current machines it is rendered impossible to do in less than a year to find it for numbe...
Given a set A consisting of all possible solvable mazes on an n by n square grid, what is the average running time to solve the mazes in A using a standard backtrack algorithm with no optimizations? The algorithm checks each ajacent space clockwise for a channel, then visits each channel and either marks it off if it e...
There are lots of technologies supporting semantic information markup even as wiki software. I am wondering if there is any kind of broad information collection project like Wikipedia which features semantic markup of those information. Google didn't bring up a project like this (only for very specific topics like soft...
You have a set of line segments and you want to find all intersections. First sweep line approach: Use a priority queue Q for the events as they come, where each event is just an end point of a line segment. Use an unordered list L for the status of the sweep line, that is, all the segments that are currently intersec...
I am brand new to DFA's and my first exercise requires me to create a DFA instance such that the number of a's in the string is a multiple of 3. We only have two types of symbols: a, b. To my understanding something like "aaabbaaa" would work but "aabbb" would not. Any help or hints would be greatly appreciated
Say you were given a black box that solves a clique problem in constant time. You give the black box an undirected graph G with a bound k and it outputs either "Yes" or "No" that the graph G has a clique with at least k vertices. How would you use this black box to find the vertices of a maximum clique in polynomial ti...
For two proposition logical formulas $\phi$ and $\chi$ so that $\phi\implies\chi$ is generally valid. How can I prove that there is a formular $\psi$ with $var(\psi )\subseteq var(\phi )\cap var(\chi )$ so that $\phi\implies\psi$ and $\psi\implies\chi$ are generally valid?
Does anyone know a way of showing an encoding of integer arithmetic counting using Lambda Calculus? Any references related to this would be much appreciated.
In Chapter 3 of "Approximation Algorithms for NP Hard Problems" edited by Prof. Dorit S. Hochbaum, there is such a sentence that "Maximum Coverage Problem is clearly NP-hard, as Set Cover is reducible to it" in p.135. Given a set system G and a parameter k, Maximum Coverage Problem is to find k sets such that the elem...
I have homework from recursion tree and despite my search for hours I could not find the answer to this problem. I appreciate if you can help. Draw a recursion tree and give a tight asymptotic bound on the solution of the recurrence $T(n) = 2^{n/2}T(n/2) + 2^n$. You need not prove your answer.
I have to create a CFG which generates $$\{a^n (ab)^n c^m d^\ell e^k \mid n>0, k, \ell, m\ge0, k<m, m=\ell+k\}$$ The first part is easy enough, I came up with $$\begin{align*} S &\to aS_2abS_3 \\ S_2 &\to aS_2ab \mid \epsilon \end{align*}$$ However, the second part is very confusing. So far I have $$S_3 \to S_4...
Is it ever the case that two decidable languages $L_1$ and $L_2$ that cannot be reduced to one another (in either or both directions)? Intuitively, I would not expect there to be, but rigorously, are there extreme examples that prove otherwise?
I have the following DFA transition table for the regular expression ab. I don't understand these hyphens.As we know DFA is a deterministic automata and each state is defined for both a and b. However, if we look at state 1, we know that if 'b' comes we will move to state 2 but while standing on state 1 if 'a' then t...
In any complicated system, there is always some scope for error. When I program on my computer, the system computes perfectly each time. 1+1 always turns out to be 2. We take reliability of the computer almost for granted. What gives modern computers it's reliability? Are there no errors in computation, or errors, if a...
I want to prove the following case of Weighted Maximum Coverage problem with special weights is NP-hard. But I have no idea. So I am here seeking for help. The Weighted Maximum Coverage problem is formulated as follows (known to be NP-hard): Given a set I of m elements with each element ej has a weight w(ej), a collec...
Shannon's source coding theorem states the following: $n$ i.i.d. random variables $X_1,\dots,X_n$ each with entropy H(x) can be compressed into more than n⋅H(x) bits with negligible risk of information loss, as n→∞; conversely if they are compressed into fewer than n⋅H(x) bits it is virtually certain that information ...
How would one be able to tell whether or not a function has an Inverse? I've got a question in my discrete mathematics/ combinatorics class that asks whether or not the following function has an Inverse and if so give the Inverse. {(p, q) | q =¬p} where p and q are elements of the set {T, F} where T is tautology an...
Since you are free to chose any formula for the SAT problem, doesn't the choice of a formula that requires a test for each subset of the group of variables force it to perform $2^N$, essentially making SAT unsolvable in polynomial time in respect to the number of variables on the input?
I hope you can help me right now, I am working on lexical analyzer for C language, I am bit confuse bout the regular expression of C style comments. a regex which can handle both single and multiline comments.
I have a Stack1 which has the entries a,b,c ( with a on the Top) and Stack2 which is empty.The condition is. An entry pooped out of the stack1 can be printed immediatly or pushed to stack2. An Entry popped out of the stack2 can only be printed. In this Arrangement, which of the permutation of a,b,c is not possible...
Bits are usually stored linearly in space. We can say, thus, that the length of a memory chip, for example, is linearly proportional to the number of bits it can hold. Since signals must travel at finite speed in our universe, the time it takes to read the last element an array will always be proportional to the length...
How do i generate grammar for Prefix of Langauge L, SupposeG=(V,,P,S)is a context-free grammar generating a CFL L then pref(L) is defined as pref(L)={x∈∗ : ∃ y such that xy∈L}. I understand for Suffix(L) we would do something like this .. Can someone here help me how do we do for the Prefix(L) if L is CFL. For each v...
Is it possible to implement an exponential-time algorithm using iteration, as opposed to recursion? I didn't have any particular algorithm in mind, I was just thinking theoretically. The way I was thinking was to iterate not by adding 1, but by adding a small number j at the end of each loop. So the 3rd parameter in th...
Is the following problem polynomial ? Or NP-Complete ? Problem: Bin packing with 2 types of objects. Input: $C$, the capacity of each bin, $N_a, N_b$ the numbers of objects $a$ and $b$, $w_a,w_b$ the weight of the objects, $k$, the maximum number of bins. Output: Yes if all objects fit in the $k$ bins without exceeding...
The definition of Turing machine says that the number of states is finite. However, I do not get how this can be true. Is the number of states in a Turing machine actually not fixed, that is not bounded? If not, can anyone explain how this is possible?
I'm a beginner in the coq proof assistant, so sorry if my question is silly. I would like to prove properties of a mathematical object. For clarity I will describe an over-simplified version of my object. Intuitively, the object has three sets A, B, C. The list A is of the form $$A= \{(0,x_1) (0,x_2), ... ,(0,x_n)\}$$...
Suppose I have an algorithm that reads lines in a file(linear) and for each line in the file, it sorts each word(nlogn). This algorithm is mnlogn, where m is the number of lines and n is the number of characters in a word. Asymptotically, as the file gets longer the number of lines becomes small in comparison to the n...
Consider four points $i,j,k,l$ and their pairwise Euclidiean distances $d(ij)$ $d(ik)$ $d(il)$ $d(jk)$ $d(jl)$ $d(kl)$ Say that, we know the coordinates of the points $j$, $k$ and $l$. However, we do not know where $i$ is and the measured distances to $i$ are erroneous depending on an error rate $e\%$. That means, gi...
Let's say a procedure called 'decision(x,q)' is available as a 'black box' X is the input set and Q is a real number Q. I need to design an algorithm that reports "yes" if there exists a subset of X whose total sum is = Q otherwise, it reports "no". Running time is not an issue, it just needs to have all actual numbe...
Question: You are given an input , which is a sequence of positive integers $w_1, w_2, . . . , w_n$ with parameters $W, ∆. $We wish to find $S ⊆ \{1, 2, . . . , n\}$ such that $\sum_{j \in S} w_j$ is as large as possible, subject to the constraints that (a)$\sum_{j \in S} w_j≤ W$, and (b) for all $i, j ∈ S$, if $i \ne...
When illustrating what states are in Turing machine, often the examples of programs, like a checker that checks an input number is even number, are given. But different programs seem to have different number of states - if so, how can Turing machine be described with the set of finite number of states, along with other...
I'm implementing the Betweenness Centrality algorithm proposed by Brandes (first algorithm on this paper - also below), and I'm running into a very weird issue: it seems to be ignoring some paths (i.e. for vertexes v-w, it may count the path v-e-w, but not the inverted path w-e-v). I'm not sure how to prove or debug th...
How would I solve the unbounded knapsack problem, only this time aiming to maximize the weight instead of the value?
The set equality problem in 2 party communication complexity is known to require $n$ bits of communication between Alice and Bob, for $n$-bit inputs $X$ and $Y$. Suppose that we promise that the symmetric difference of $X$ and $Y$ is $\le 1$. Is the required communication for a deterministic protocol still $\Omega(n)$?...
I see that Σ* is claimed to be decidable in many documents, but I have never seen an example or easy demostration that it is decidable. What is the proof that Σ* is decidable?
Consider a Turing machine that cannot write blanks. How does one show that such a machine can simulate a standard Turing machine?
Assuming $\Sigma = \{ 0, 1\}$.. Given a language $L$, such that for each $n\in \mathbb{N}$ we have $n$ words of length $n$ in $L$ and assuming $L\in NP$, can we prove also that $L\in Co-NP$? So it is the same as showing that $\overline{L}\in NP$, but I'm not really sure on how to prove this. Does anyone have an idea?...
trying to figure out how to approach this problem. Suppose a sender in a network wanted to communicate the length n of the block it will be using in a subsequent transmission. If there were not limits on the value of n, there would be a problem to simply send the number in binary, since the receiver would find it diff...
I have a circuit that is represented as a netlist (specifically, an and-inverter graph). The desired outputs of this circuit are known. We can assume that some combination of the primary inputs will result in the desired outputs. If it makes it easier, you can assume that there's only one combination of inputs that ...
I have read the answer found here which considers the size of integers when doing comparisons and how that affects on the basic cost of comparison. I am trying to understand why each basic operation takes $O(1)$ time. For example branches in general are considered to run in $O(1)$ time when they usually don't. In compu...
JLS defined a concept called "constraint formula". There is a formal definition: Constraint formulas are assertions of compatibility or subtyping that may involve inference variables. The formulas may take one of the following forms: ‹Expression → T›: An expression is compatible in a loose invocation context with...
Does the concurrent language CSP (or CCS, $pi$-calculus) model interacting machines? Is CSP (or CCS, $pi$-calculus) Turing-equivalent to other programming languages like C?
Can someone enlighten me why a recursive descent parser with backtracking that tries the productions $S \rightarrow aSa$ and $S \rightarrow aa$ (in that order) does not recognize the language formed by the grammar $S \rightarrow aSa\ |\ aa$. It appears to only parse words from the language $\{a^{2^n}\ |\ n \ge 1 \}$. I...
Let $f(n)$ be a function s.t $f(n)\geq 1 $ for every $n$. I want to disprove that if $f(n) = \omega (f(f(n)))$ then it means that $f(n) = O(1)$. I thougt of 2 approaches to show that this statement is incorrect: Give an Example of a function that $f(n) = \omega (f(f(n)))$ for it, for example: $f(n) = \sqrt n$ and ...
I need help with a question. Prove or disprove the following claim: Let $f\colon \Sigma^* \to \Sigma^*$ be the identity function, i.e., $f(w) = w$ for all $w \in \Sigma^*$. Let $L_1$ and $L_2$ be two languages such that $L_1 \subseteq L_2$. Then $f$ is a many-to-one reduction from $L_1$ to $L_2$. In particular, if $L_...
If I have the expression: 1011 0000 1110 -1000 1110 0001 ---------------- Then, I find the twos complement of the second number: 0111 0001 1110 +0000 0000 0001 --------------- 0111 0000 1111 I then add this to the first number: 1011 0000 1110 +0111 0000 1111 --------------- 0010 0001 1101 But the answer given ...
I'm having trouble getting started on this proof, and I was hoping you guys could give me a couple hints/point me in the direction of where to start? Here's the problem: Consider a multijump Turing machine, which is like an ordinary Turing machine except the transition function is δ : Q × Γ → Q × Γ × {LL, L, R, RR} In ...
I'm studying Real Time Systems, and in the textbook most of the focus is on scheduling algorithms. (Textbook: Real-Time Systems by Jane W. S. Liu) In the algorithms that involve priorities, it is said that smaller integer represents higher priority (e.g. a process with priority 1 has more priority than one with 3). The...
The diameter of a graph is the largest of all shortest-path distances in it. How can we find a tree of maximum diameter within an undirected unweighted graph? Note that the tree does not have to be a spanning tree.
To my best knowledge, these are the sound and complete algorithms for boolean satisfiability Variations of DPLL algorithm (e.g. CDCL, Look-ahead solvers) Stalmarks method Binary Decision Diagram (BDD) I am looking for other sound and complete algorithms for boolean satisfiability?
The time complexity of computing $MK\bmod P$ is $O((\log n)^2)$. What is the time complexity of computing $MK^2\bmod P$? Is it $O(2(\log n)^2)$ or $O((\log n)^2)$?
I have been posed a question by my lecturer and I'm trying to figure the right way to go about it. They want me to ensure mutual exclusion for n processes. The code provided is as follows: Process Pi while(true){ while(#taken == 5){} #taken := #taken+1; // enjoy a non-alcoholic ...
I was studying the product with floating point and I saw this example. I made the translation, sorry if something is not grammatically correct. ![enter image description here][1]
In my CS course, we are covering things from one topic to another in sort of a sensible manner. For example, binary search tree -> 234-tree -> red-black tree -> heap -> greedy algorithms -> dynamic programming. And all the sudden, bam, there is this whole chapter on the knapsack problem. How is this problem different f...
The algorithms using the "divide and conquer" (wiki) design strategy often have the time complexity of the form $T(n) = aT(n/b) + f(n)$, where $n$ is the problem size. Classic examples are binary search ($T(n) = T(n/2) + O(1)$) and merge sort ($T(n) = 2T(n/2) + O(n)$). Do you know any algorithms (probably using "divid...
I want to prove L is not regular:$$L={\{www|w \in \Sigma^*\}}$$ $$\Sigma=\{a,b\}$$ I am sure I can do so using pumping lemma. I used $$ab^pab^pab^p$$as my chosen string but I am stuck. I do not know how to handle different cases of y in pumping lemma.
I'm having a hard time understanding what is mean't by the aggregrate rate $\lambda$ and what it means for throughput in unslotted and slotted Aloha protocols. The more I seem to read about poission process the more confused I get. I understand that the probability a packet is transmitted in a time interval $\delta t$ ...
In Is concurrent language CCS or CSP turing-equivalent in language power?, the answer says that CCS or CSP is Turing-complete. But that does not seem to answer whether CCS or CCP is Turing-equivalent. According to my understanding, Turing-equivalence and Turing-completeness is a different thing, but I may have been co...
Consider a directed graph in which some edges are marked as "optional". A graph with $N$ optional edges induces a family of $2^N$ graphs depending on which edges are removed. In some cases, some of these graphs may be acyclic while others contain cycles. For example, consider the graph with vertices $\{1, 2, 3, 4\}$ an...
I'm studying the bakery algorithm. do { choosing[i] = true; number[i] = max(number[0], number[1], …, number [n – 1])+1; choosing[i] = false; for (j = 0; j < n; j++) { while (choosing[j]); // while ((number[j]!= 0) && (number[j],j)<(number[i],i))); } critical secti...
I was playing around with Shannon-Fano (SF) entropy encoding when I ran into this issue. I am aware that the compression that can be achieved with SF is sometimes inferior to that of Huffman encoding, but I just though it meant that code lengths were sometimes sub-optimal in the sense that an encoding exists, which yi...
Given the set $X=\{1,2,\ldots,n\}$; $\,\,$ $n=mp=kq$ where $m,k,p,q$ are positive integers. Please help me to programme an algorithm that realizes random generation of the following two partitions of $X$: $$ \mathcal{D}_{1} = \big\{A_{i}\big\}_{i=1}^{p}; \quad \bigcup_{i=1}^{p} A_{i} = X; \quad A_{i_{1}} \cap A_{i_{2}}...
I was binary indexed trees and I came across this article. One part of the justification was the following: Given that the (binary search tree) tree is perfectly balanced, a node N will have exactly $2^{i}-1$ children on each side, where $i$ is the position of the first 1-bit in N, starting from 0, and counting fr...
I'm working on a problem which to me, seems very similar to a knapsack problem: A furniture store is having sale: Purchase two items at the price of the more expensive one. David went to the store and bought $2k$ items: $f_1, f_2, ...f_{2k-1}, f_{2k}$. The items are priced: $p_1, p_2,...p_{2k-1}, p_{2k}$ respectively....