instruction
stringlengths
35
29.1k
It looks like most of today's algorithm analysis is done in models with constant-time random access, such as the word RAM model. I don't know much about physics but from popular sources I've heard that there's supposed to be a limit on information storage per volume and on information travel speed, so RAMs don't seem t...
I tried to solve this problem but could not do it better than $O(n^2)$. My Algorithm: 1. Calculate prefix sum 2. for i in 1..n: for j in 1..i: if presum[i] - presum[j-1] > k: ans = max(ans, i - j) Edit: I have found a solution which works in $O(n\log n)$. This solution does a binary search on th...
From wikipedia on lock convoy: A lock convoy occurs when multiple threads of equal priority contend repeatedly for the same lock. Unlike deadlock and livelock situations, the threads in a lock convoy do progress; however, each time a thread attempts to acquire the lock and fails, it relinquishes the remainder of its s...
Say I have an array a[1..n], and I want to output an array s[1..n] with s[i] = a[1]+...+a[i]. What is the best (or at least standard) way to do so in parallel? The way I can think of doing it, given m processors, is to split the array a into m blocks of equal size M, compute b[j] = a[floor((j-1)/M)*M+1]+...+a[j-1]+a[j]...
Given a co-graph like the one attached as an input what are the steps that I have to follow in order to generate its co-tree? Is there a step-by-step algorithm to do that?
I read a few years ago in this book that NP problems are tractable in the space of cellular automata in the hyperbolic plane. What does this mean? Does P = NP according to these books/papers? Some excerpts from the paper: It is well known that if we have binary trees at our disposal “for free”, it is possible to solve...
I have a robot with two motors A and B connected to wheels 21.6mm in diameter. The motors move in steps, and there are twenty steps for each complete revolution of the wheel. To make the robot move forwards, I turn on A and B in the forward direction and have it rotate a number of steps. To make it move backwards, I tu...
The task is to record a histogram from a streaming data source. One data point is, say, a 16 bit integer. The maximum multiple of one data point before the stream ends, is < 2^32. The main restriction is that there isn't enough memory to have an array of counters which completely covers the range of the data points (65...
So, I'm currently studying Newton method used for finding the 0's of a function, however my professor has only announced that the speed of this algorithm can be more than quadratic, however I'm wondering when this happens, since in the demonstration used by him to explain the quadratic case, there is no evidence about...
It's my first time to make a question here. I have a curious problem about algorithm, in the center of Cartesian plane (0,0) I need to go to another point (x,y) -x and y are belong to Z numbers - but I only can use horizontaly and verticaly steps and this steps increases one by one units, a unit is a distance from (0,0...
I am just reading about perceptrons in more depth, and now onto Sigmoid Neurons. Some quotes: A small change in the weights or bias of any single perceptron in the network can sometimes cause the output of that perceptron to completely flip, say from 0 to 1..... That makes it difficult to see how to gradually modify t...
Suppose that there are a set $P$ of $n$ points on the plane, and let $P_1, \dots, P_k$ be distinct subsets of $P$ such that all points in $P_i$ fits inside one unit disk for all $i$, $1\le i\le k$. Moreover, each $P_i$ is maximal, i.e., no unit disk can cover a subset of $P$ that is a strict superset of $P_i$. Visually...
I have been studying a streaming algorithm to determine if there is a majority element in a stream. But am confused by a proof for it. The algorithm works as follows. You keep one counter $c$ and a store for one item called $a^*$. When a new item arrives, first you check if $c == 0$. If so you set $c=1$ and $a^*$ store...
I was familiar with the approach of first coming up with an algorithm, and then proving the loop invariant to come up with an algorithm as elucidated in CLRS (Introduction to algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein). Lately, on reading Udi Manber's introduction 'A creati...
Formulating standard Sudoku as an exact cover problem is easy and well documented. All of the constrained groups contain every digit which makes it natural to express the problem this way. Wikipedia claims without citation that: Although other Sudoku variations have different numbers of rows, columns, numbers and/or d...
I'm trying to solve this problem, but without success. Problem: You're given a binary string where some of the bits are replaced by ?. You're also given several intervals [$l_i$, $r_i$] ($l_i < r_i$). Find a binary string S with ? replaced by 0 or 1, such that in each interval [$l$, $r$], s[$l..r$] includes both 0 and...
Pardon my ignorance, but after just learning about Sigmoid and Tanh activation functions (and a few others), I am wondering why they choose functions that always go up and to the right? Why not use all kinds of crazy input functions, those that fluctuate up and down, ones that are directed down instead of up, etc.? Wha...
I have a fixed array: [a,b,c], I wanna loop through this 3-items-sized array for 7 times in order to find what I would get at that exact step. The "value stack" for 7 would look like a b c a b c a. Question is, how can I find what value would be at step 10, for example? Input: getValueForStep( [a,b,c], 7 ) Output: a
I'm trying to analyze Bubble Sort runtime in a method similar to how to it's done in "Introduction to Algorithms 3rd Ed" (Cormen, Leiserson, Rivest, Stein) for Insertion Sort (shown below). I haven't found a line by line analysis like the Intro to Algorithms line by line analysis of this algorithm online, but only mul...
This article says the following: Deciding between the sigmoid or tanh will depend on your requirement of gradient strength. I have seen (so far in my learning) 7 activation functions/curves. Each one seems to be building on the last. But then like the quote above, I have read in many places essentially that "based on...
I am curious as to the overhead cost of spawning child processes using fork in a Linux environment. Suppose I have a C program such as void run_computation(int x); int main() { for (int k=0; k<10; k++) { if ( fork() == 0 ) { run_computation(k); break; } } return 0;...
During burst mode in a DMA access, the DMAC has control over the bus for the whole transfer session which includes DATA PREPARATION time as well as DATA transfer time, after the transfer is over, the DMA relinquish the system bus. So in the mean time, the cpu can neither fetch any instruction from the MAIN MEMORY, nor ...
I have the following two CFL: $A =\{a^m b^n c^n\}$ and $B = \{a^m b^m c^n\}$. I don't understand why the intersection of this languages is $\{a^n b^n c^n\}$: can anyone explain to me why the power is to the $n$ and not to the $m$ or something else? Thank you in advance.
I'm looking to minimize the length of an expression in boolean algebra that has been given in disjunctive normal form and is free from redundancy. To remove redundancy from the original expression I have applied the Espresso Hueristic Logic Minimizer as implemented through the PyEDA library. Now, I would like to expres...
My question is the following: Is it possible to compute a string given that after applying a SHA256 function the result is the same string? Edit for clarification: If my string A is a neutral element of SHA256, then: A == SHA256(A) is true. Does A exists?
I need help with the following question - There is a set S of n integers. Given a black box which returns three integers a,b,c in S such that a+b+c = 0 if they exist. One needs to devise an algorithm that makes only one call to the black box to find out if S contains three integers such that a+b=c The question also had...
I have a computational problem that I want to solve. I'm not sure if it has already been studied in literature, or if so under what name. I'd appreciate any pointers to literature or suggestions for an algorithm. Input: A connected, undirected graph G = (V, E) in which certain edges are labelled "bad". Output: The mini...
I'm reading "Introduction to Algorithms" 3rd edition by Cormen, Leiserson, Rivest, Stein Page 46. The authors place formal upper and lower bounds on a function which is quadratic. Can anyone explain where the values for $c_1$, $c_2$ and $n_0$ are taken? I'm also confused why the $max$ function is used and it's para...
I am new to theoretical cs and am working through it slowly. I have completed a simple question and was wondering if my answer is correct or not. Thank you kindly for any feedback. The question is: Given the alphabet $\{a, b\}$ Construct a regular expression that defines the language $M$ containing all words beginning ...
ALL_TM = { TM | A valid TM } This was a question on my exam. As my choice of answer I went with yes, since the set of all Turing Machines is countable, ( you can produce a binary string for each and every new Turing Machine ) my take on the answer that yes it does contain all Turing machines. But apparently my answer ...
This question is sequel from How to understand quantifier without predication " ∀(λφ. (φ x m→ φ y))"? which further explains the notation and context. So - I have anonymous Boolean-valued function F(y)=λx.Φ(x) (of course, y and x point to the same variable, I just used different syntactic names, to point out, that x is...
Let $O$ be an optimisation problem and $P$ its decision variant. I know that $O$ is said to be NP-hard if $P$ is $NP-$complete. However, what to say about $O$ when the decision problem $P$ is no more in the class $NP$, and thus it's no more $NP-$complete(the algorithm of deciding is pseudo-polynomial and there is no be...
What are they and what are their differences? Unbanked access Banked access Common memory access [EDIT] This question is originated from my reading of MPLAB XC8 PIC Assembler User's Guide where the latest XC8 compiler requires a preprocessor directive to contain or wrap assembly codes in sections called PSECT. I hav...
Most of the discussion about RNN and LSTM alludes to the varying ability of different RNNs to capture "long term dependency". However, most demonstrations use generated text to show the absence of long term dependency for vanilla RNN. Is there any way to explicitly measure the time dependency of a given trained RNN, mu...
I am trying to understand Kempe's algorithm to $k$-color a planar graph. This is what I understand till now: Trying to 6-color a planer graph ($k=6$) Find a vertex of degree <= 5 ($k-1$) Remove this vertex Color the rest of the graph using a recursive call Put the vertex back, since its degree was at most 5 ($k-1$), w...
Consider the methods used by processes P1 and P2 for accessing their critical sections whenever needed, as given below. The initial values of shared boolean variables S1 and S2 are randomly assigned. Method used by P1 while (S1 == S2); Critical Section S1 = S2; Method used by P2 while (S1 != S2); Critical Section S2...
I know this is a similar question to this post, but I want to further clarify my understanding. In the picture from wikipedia: I understand that every problem that's in $P$ is also in NP. does this mean that everything from MergeSort, to linear search is in NP [though not NP-HARD]? Or does this only apply to decision ...
Consider the following code sequence that is executed on a processor that doesnt supports stalls and only supports ALU-ALU forwarding : I1: lw $1, 40($6) I2: add $6, $2, $2 I3: sw $6, 50($1) I4: lw $5, -16($5) I5: sw $5, -16($5) I6: add $5, $5, $5 Now the only way to run this code on this processor is to insert nops ....
I implemented logical expressions using a binary tree in C++. Now I want to be able to simplify such an expression using rules like e.g. but have issues with the commutativity. Assuming the expression is then the tree would look like this: xor /\ xor b /\ xor true /\ true a The expressi...
If I have a router that has a vulnerability that allows an attacker to gain full control it, does using a VPN on the network with the said router prevent an attacker from being able to snoop on the connection? In other words, does using a VPN secure the connection from a device to a router? And would a VPS make a diffe...
I try to show that this language is regular: $L = $ { w $\in \ (a,b) ^ * $| for every u substring of w, $-5\le|u|_a−|u|_b\le5\}$ If I build a NFA and run on it every substring of w (skip other letters every time) - and only if they are all accepted (follows the condition) then accept w. Is it possible in NFA? Is there ...
I have a bit of experience with loop invariants but I'm not really clear on them. I'm trying to learn them through an Algorithm I have. Reverse(X,Y) n = X.length for(i = 1 to n) Y[n - i + 1] = X[i] return Y This copies values in array X into array Y in reverse order, and returns array Y. If X and Y bo...
I have to write some algorithm in pseudocode for a paper. For this I have the "$\leftarrow$" to assign a value. $x \leftarrow y^2$ now I want to write a method which adds to the variable. In normal Python code I would write x += 1 for this. Is there a style convention how to layout this in pseudo-code in a paper? I don...
I've been working on a binary tree optimization problem with two choices of loss function (let's call them A and B). I'm fairly certain that the problem of minimizing either A or B individually has the optimal substructure property. That is, if I have a set U and I construct the A-minimizing tree T out of all the eleme...
Are GPUs or CPUs capable of selecting n elements from an array in sublinear time using indices? If so, what would be some good alternatives to achieve this? Lets say I have an array A = {1, 5, 6, 3, 6, 2} and indices I = {2, 5, 2, 4, 1, 0}. The resulting array should be: B = {6, 2, 6, 6, 5, 1}. The time complexity for ...
While a basic algorithm to check for primality of a number 'n' [checking if a divides n for all a less than n] would take O(n), AKS test was the breakthrough after which it was placed in P complexity class.
Functional programming is said to be superior in many ways to imperitive programming. But I am struggling to find a simple functional way of writing: x = f(y); g(x,x) Since in functional language this would be g(f(y),f(y)) thereby calling the function f twice. Whereas in imperitive language this seems more efficient. ...
The wikipedia article mentions: For graphs of bounded clique-width, the longest path can also be solved by a polynomial time dynamic programming algorithm. However there are no references and I wasn't able to find anything relevant in literature. Nor was I able to come up with a naive algorithm that would achieve thi...
When we quantify infinite sums, we do so by taking the limit as $i$ goes to infinity. For example, we look at $\lim_{n\rightarrow \infty}\sum_{n\in \mathbb{N}}n$, and then we say that this diverges and does not have a sum. When we do diagonalization, we iterate over an infinite list while indexing each list item by a n...
I have the following data: A set $V$ of tasks, the starting time $s_j$ of each task and the duration $p_j$ of each task. A set $K$ of resource, each resource has an availability function $R_{k}$ that is piecewise constant.That is, for each $t = 0, .., T-1$, we precise $R_{k}(t)$ the number of units available at $t$. ...
There are $n$ sets of distinct positive integers, $S_1,\ldots,S_n$. There is a set of recipes that allows us to construct tuples of integers from these sets. For example, the recipe {1,2} allows us to construct tuples of two integers: one from $S_1$ and one from $S_2$. Each integer can be used in at most one tuple. Wha...
Background I once implemented a datatype representing arbitrary real numbers in Haskell. It labels every real numbers by having a Cauchy sequence converging to it. That will let $\mathbb{R}$ be in the usual topology. I also implemented addition, subtraction, multiplication, and division. But my teacher said, "This does...
I have been reading this tutorial on time complexity, and I am a bit puzzled on its explanation of big $O$ notation. It writes: $O(g(n)) = $ { $f(n)$ : there exist positive constants $c$ and $n_0$ such that $0 \leq f(n) \leq c*g(n)$ for all $n > n_0$. The way I understand it, $c*g(n)$ denotes $c$ multiplied by $g(n)$...
Exercise G in Chapter 6 of Richard Bird's Thinking Functionally with Haskell asks the reader to prove foldl f e . concat = foldl (foldl f) e given the rule foldl f e (xs ++ ys) = foldl f (foldl f e xs) ys There's no mention whether the given rule applies to infinite lists, nor does the answer in the book mention ...
This appears to be a very basic question for this Stack Exchange, but hopefully still welcome. I am a math teacher and wanted to write a program to demonstrate normal distributions. I wrote a simple code in Processing that essentially flips a coin a certain number of times and makes a histogram of the results: int pile...
Is there an efficient classical algorithm that generates samples from the uniform distribution (or a distribution that is close to the uniform distribution in total variation distance), over the set $\{0, 1\}^{n}$, for a fixed $n$? We can easily express the uniform distribution in terms of a formula: $Pr(X = x) = \frac...
I've been doing lot of programming challenges lately (such as on leetcode.com) and often find myself in a situation when I cannot pick a method for solving a problem. I stuck with questions like - should I use brute force or greedy search would work better or maybe dynamic programming would do the job? Then I start cod...
I'm struggle on this practice question from this site.... Calculate the number of bits required in the address for memory having size of 16 GB. Assume the memory is 4-byte addressable. MY QUESTION IS: what is the difference between an "address" and "the memory is 4 byte addressable"? I understand an address would be ...
In CLRS the author said "Technically, it is an abuse to say that the running time of insertion sort is $O(n^2)$, since for a given $n$, the actual running time varies, depending on the particular input of size $n$. When we say “the running time is $O(n^2)$,” we mean that there is a function $f(n)$ that is $O(n^2)$ such...
I'm attempting to develop from scratch a simple regex engine. I would like for my engine to have the ability to report, "The regex matched on a substring of this line starting at index and ending at index ." It makes sense to me how to accomplish this using recursive backtracking. However, I'd like my implementation ...
Inorder traversal of BST is always sorted.But can we say Binary tree is BST if and only if inorder is sorted?I mean if inorder is sorted,can we conclude it is always BST?
Regarding the post Which combinatorial problem is similar to this problem?, it is quite hard to believe that, in the absence of information on the cost function, there is no algorithm better than exhaustive search to tackle this apparently easy-to-understand problem. I surfed the Internet and found something called the...
A problem is said to be NP-hard if every problem in NP is reducible to that problem in polynomial time. Hence, if P=NP, wouldn't that imply that every problem in NP is reducible to every possible problem, in polynomial time? However the diagram above seems to imply that if P=NP, there exist problems outside of NP-hard...
I am completing a final year project for hand gesture recognition using Hidden Markov Models I have a fair understanding of Hidden Markov Models and how they work using simple examples such as the Unfair Casino and some Weather examples. I am looking to implement multiple Hidden markov models where each model correspon...
Consider the following eqautions used in LSTM ( taken from Andrew ng's course on Sequential model) In an LSTM model, LSTM Cell has three inputs at any time step t Input($X_t , a^{(t-1)}, C^{(t-1)})$, Here $X_t$ is the input vector, $a^{(t-1)}$ is the previous hidden state and $ C^{(t-1)}$ is the previous cell state ...
Suppose we have 7 vertices, each of which corresponds to a different integer modulo seven. The edge exists between two vertices x and y if x + 3 ≡ y mod 7. For example, there is an edge between 0 and 3, and an edge between 5 and 2. What is the length of the shortest path between 0 and 1? My method to get the answer is ...
As I understand, the term "NP-hardness" is applicable when we also talk about optimization or search problems (i.e. return the satisfying assignment for 3-SAT). How do we formally define NP-hardness for such problems? The standard definition: The problem is NP-hard when any problem from NP is polynomial-time reducible...
Consider a turing machine with infinite states. This machine is identical to a regular machine. Only that number of states could be infinite. Does this machine has more computational power than a regular machine ? If yes - Then show that a machine with infinite states can recognize languages that cannot be recognized w...
I have permutations: 4 1 2 5 3 4 3 2 5 1 numbers can be order magnitude of 1000 (fits in two bytes) I want compute 32 bit (or better 64 bit) hashes, it should be non cryptographically secure but evenly distributed in 32 or 64 bits. This second permutations is derived from first by swap 1-st and 4-th element (count for...
I ask this question because of some statements in the question "What is the 'continuity' as a term in computable analysis?" making me suspicious. I'm engineer, not computer scientist, so I don't have the Turing machine but logic gates in mind when I'm thinking about algebraic operations performed with devices. I read t...
Main I am confused about the motivation behind the need for a separate notation for П-types, that you can find in type systems from λ2 on. The answer usually goes like so - think about how one can represent a signature of identity function - it can be λa:type.λx:a.x or λb:type.λx:b.x. The subtle part, they say, is that...
I have the following recurrence relation: $$T(n,k) = T(n-1,k)+T(n-1,k+1)$$ With the following base cases (for some given constant $C$): For all $x \leq C$ and for any $k$: $T(x,k)=1$ For all $y \geq C$ and for any $n$: $T(n,y)=1$ I want to get a formula for $T(n,0)$. I think that it can be seen that after $i$ iteration...
I'm trying to understand the definition of Transition point of a BST, as given in Demaine, Erik D., et al. "Dynamic optimality-almost." SIAM Journal on Computing 37.1 (2007): 240-251 Define the transition point for [a node] y at time i to be the minimum-depth node z in the BST Ti such that the path from z to the root...
what would be the time complexity of DBSCAN algorithm if we use it for graph(sparse) clustering $O(n^2)$ or $O(n \log{n})$?
Hey I would like to find a answer for b. for a look to the picture that is my answer for it. But I dont habe any Idea how i can solve this. Thank you guys. (I had to translate it to english maybe it will be hard to understand it sorry about that).
The main question asked me to build a certain turing machine such that given a word w over {0,1}* the turing machine accepts all such words and ends in accept state with the tape string = the word apended with the number of zeros in it. I built the state diagram of this turing machine.. But now there is a question next...
I'm trying to show $L^2 \in \mathsf{REG} \implies L \in \mathsf{REG}$ with $L^2 = \{w = w_1w_2 \mid w_1, w_2 \in L\}$ but I cant seem to find a proof that feels right. I first tryed to show $L \in \mathsf{REG} \implies L^2 \in \mathsf{REG}$, by constructing an machine $M$ that consists of two machines $A=A'$ with $...
Been mulling over this one for hours, my initial thought was { w ε {a,b}* | w is empty, or ends with either ab or ba} but that's clearly wrong as neither aba nor bab are accepted by the automaton. If anyone has any idea what language this automaton accepts it would really put my mind at ease.
I'm a complete beginner. Please forgive my ignorance.Trying to learn about CSP online, I noticed a lot of the focus on search methods and heuristics which tell you which variable to expand next (e.g. most constrained variable) and those that tell you which value to try first (e.g. least constraining value) but I've yet...
Consider some problem $P$ and let's assume we sample the problem instance u.a.r. from some set $I$. Let $p$ be a lower bound on the distributional error of a deterministic algorithm on $I$, i.e., every deterministic algorithm fails on at least a $p$-fraction of the instances in $I$. [Edit: For a given instance $s \in I...
I have encountered the following question in my homework assignment in Data Structures course: "Does a function $f$ exists such that: $f(n-k) \ne \Theta(f(n))$ for some constant $k\geq1$ ?" I think no such function $f$ exists, but I do not know how to prove it (or give a counter-example if one exists).
Imagine a set of two to six squares within 3D-space. The goal is to generate a convex hull around these squares as efficiently as possible. The following constraints are known: Each of the two to six squares consists out of 4 vertices (a vertex being a 3D-vector). The vertex-data are stored in such a way, that every v...
I have problem of inferring a rooted tree out of a connected simple graph. The inference can be done by finding its minimum spanning tree, but the result is restricted by additional two types of condition: There is a known root, which is s in the following example. We know directions of some edges if they are chosen. ...
Now that many computers use UEFI instead of BIOS to boot the computer, and UEFI instructions are usually stored in a hidden hard disk partition, does this mean the newest computers do not need to have ROM, which is used to store BIOS program in the old days? Or, was ROM unnecessary long ago even before UEFI existed, as...
I recently came across a function called the strawman algorithm which the pseudo code looks like this: StrawmanSubarray(A): Initialize bestsum = A[0] For left=0 to n-1: For right = left to n-1: Compute sum A[left] + . . . + A[right] If sum > bestsum: bestsum = sum The time comple...
I am trying to work through this programming problem but I can't progress because I genuinely don't understand what it is that its asking me. New Students are arriving at college. Initially the students don't know each other, and each has a circle of friends limited to themselves. As the semester progresses, groups of...
While making name-tags for a dinner seating, I stumbled upon a problem which I can't find any algorithm to solve, and I'm not sure where to begin. The goal is to write the name of each dinner guest on a card, completing one name at a time. The names are written with old-fashioned rubber stamps, so only 6 letters can be...
While solving a few CSPs by hand, I noticed that I don't actually need to check for arc consistency after each assignment. All I needed to do was to formulate the CSP in such a way that I'm adding extra constraints based on the nature of initial constraints in an attempt to predict arc inconsistency. After assigning a ...
Given a weighted simple undirected connected graph $G = (V, E, w:E \to \mathbb{R})$, let $\tau(G)$ be the set of all its spanning trees. Is there an efficient algorithm to determine or estimate with high probability the number $W = \sum_{\mathcal{T} \in \tau(G)} \sum_{e \in E(\mathcal{T})} w(e)$ without actually enumer...
What is the complexity of the following algorithm in Big O: for(int i = 2; i < n; i = i^i) { ...do somthing } I'm not sure if there is a valid operator to this type of complexity. My initial thought was as follows: After $k$ iterations we want: (using tetration?) ${^{k}i} = n \implies k=\log\log\log..._k\log{n}\im...
I know that this question is asked a lot of time but I don't understand or I think, I got lost when I was reading Introduction to algorithms They said, "It is not contradictory, however, to say that the worst-case running time of insertion sort is Omega(n^2), since there exists an input that causes the algorithm to tak...
I have two postal codes (fixed size of 6 digits) to compare and return the mismatch score. where the mismatch weight of initial indexes is higher, then keep reducing. Example postal code 123456, with index[0] ==> 1 is northern region, and if index[0] ==> 2 is southern region. so it should have very high mismatch score...
I'm a physics student wondering how I can mathematically show the largest possible value of a 64-bit double. I don't want to know just the answer, since that is freely available. The equation I was shown by a professor says a machine number is represented as $s\times m \times 2^{E-e}$ with $m$ the mantissa and $e$ the ...
Are there any efficient algorithms to find the shortest homotopy between two paths in a $2$-complex?
I have a DAG which I would like to do a topological sort on but there is a catch. I also have a relation NotBetween(X,Y,Z) which means that in the sort the node Y cant come "in between" node X or node Y. In other words, Y < X OR Z < Y. I've thought about several approaches to this, but can't find a solution. Maybe I ca...
So, I have been solving problems in Google Foobar for the past two weeks or so ans has reached Level 4. The first problem is as stated below and I have come up with a solution which is able to pass all test cases except one. I have been stuck on it for the past 3 days and hasn't been able to made any progress so far. C...
Given a probability $p$ and an integer $N$, I would like to generate a sample $S$ of the population $P=\{0,1,...,N\}$ such that integer $m\in P$ is sampled with probability $p^m$. It is trivial to do this in time $O(N)$. I am looking for an algorithm that can perform this sampling in (expected) time proportional to the...
This is a general question and one that has bugged me for a long time. I want to start working on an artificial universe, not something too ambitious but more of a basic concept. What I have in mind is a simulation that has a sense of time, has physics rules, some beings that interact with each other and are able to le...
Average case complexity for linear search is (n+1)/2 i.e, half the size of input n. The average case efficiency of an algorithm can be obtained by finding the average number of comparisons as given below: Minimum number of comparisons = 1 Maximum number of comparisons = n If the element not found then maximum number of...
It is known that any power of cycle on even vertices is in Class 1, that is, can be edge colored in $\Delta$ colors, where $\Delta$ is its maximum degree which equals twice the power. But, I wish to know a specific algorithm to edge color the powers of cycles of even order. Say, I have the square of a $18$ cycle. Now, ...