instruction
stringlengths
35
29.1k
I am looking for a long list of words/terms which are related to aligning one string to another. String Metric Edit-Distance Bioinformatics Needleman–Wunsch Algorithm Sequence Alignment Global Alignment Local Alignment Levenshtein distance Hamming distance Damerau–Levenshtein Jaro distance Did I miss any? What would ...
Is the complexity of $F(n) = n \cdot n^{\log_3 2}$ allowed to be written as $O(n)$, or must you specify and say $O(n^{1.63})$, or even must you write $O(n^2)$ since it is an upper bound?
I was wondering if anyone can point me to a data structure that supports the following operations. Goal is to create a data structure $D$ that stores 64-bit integers and provides the following operations: min() in $O(1)$ worst-case time max() in $O(1)$ worst-case time predecessor($x$) find the greatest element $y \in ...
Faster CPUs solve the same computational problems in shorter time frames. The same applies to faster GPUs. Therefore, replacing with faster components can reduce the computer's power consumption. On the other hand do some components need more electrical power for instance for ventilation. How do you estimate which comp...
I noticed that when you compress data they can compress multiple files and since all files are made up of bytes how do these compression algorithms keep track of them? What seperators do they use? From my understanding it goes like this, for example I have an array [1,2,3] and another array [4,12,6] and I store them in...
I'm required to describe an implementation of a data structure that holds key,value pairs, which can be signed integers. We need to be able to init() in O(1), insert(x) in O(logn), delete(x) in O(logn) and sumPrevious(x), which returns sum of values of the keys that are smaller than key 'x', in O(logn). An AVL rank tre...
I am trying to understand how (n-m+1) (n being the string and m being the pattern) is derived. As in, how could you determine a formula for the number of comparisons in the worst case of a brute-force string matching algorithm. Here is a look at (n-m+1) being mathmatically derived (where I'm at), that I found: In the ...
Let $\mathcal{A} \subseteq \mathcal{B}$ given as a collection of arrays. The degree of an element $a \in \cup \mathcal{A}$, is the number of sets of $\mathcal{A}$ that it contains - that is, $d_{\mathcal{A}(x)} =|D_{\mathcal{A}}(x)|$, where $D_{\mathcal{A}} =\{A \in \mathcal{A} \mid a \in A\}$. The algorithms is as fol...
I am currently experimenting on compression algorithms, I am using proven algorithms and I am just trying to see if I can make some things more efficient, so I am very sorry if this is a stupid question. I am trying to decode an array from a string for example I have [123, 4, 12, 7, 51] so if I turn this into a string ...
I want to analyse the time complexity for Unsuccesful search using probabilistic method in a Hash table where collisions are resolved by chaining through a doubly linked list. And the doubly linked list is kept in sorted order (Ascending). I proceeded in the following way: We will stop if the element in the linked list...
We know that if $T_1 = \{e_1, \dots, e_n\}$ and $T_2=\{f_1, \dots, f_n\}$ are MST then if we order the edges such as $$w(e_1) \le w(e_2) \le \dots \le w(e_n)$$ $$w(f_1) \le w(f_2) \le \dots \le w(f_n)$$ then $w(e_i)=w(f_i)$ for all $i\in [n]$ This also (trivially) implies that $w(e_1) \le w(f_i)$ for all $i\in [n]$ Doe...
In relational databases, what are the practical or theoretical ways to reduce the size and spatial complexity of intermediate indexes or tables* at execution time (so for example to reduce the size of intermediate indexes when running a join on a time series data with millions of entries). Additional research papers or...
In the comparison sort model of sorting, the fastest possible algorithm is order $n \log(n)$, where $n$ is the number of input numbers. What is the time complexity of sorting a list of natural numbers, each represented as a string of ones and zeros, and separated by commas? For example, the input $11,1,10$ would be sor...
I'm reading Algorithm Design and Application, by Michael T. Goodrich and Robert Tamassia, and sometimes the pseudo-code in this book doesn't make sense at all. At chapter one they show us 3 solutions for the famous maximum subarray problem. I understood completely the first and second solutions, but the third one (the ...
A post claims 5 of the trees shown in the following figure are all binary search trees I guess the author's making a mistake, since the 2 trees on the right ARE NOT binary search trees. As an example, in the last tree pointed out by red rectangle, the key 1 is in 2's right subtree, which doesn't satisfy the binary-sea...
What is the time complexity of the best-known algorithm to search for the largest complete bipartite subgraph (not induced subgraph, since not all edges have to be considered) in a given graph? A complete bipartite graph $G = (V, E)$ can be partitioned into two subsets $V_1$ and $V_2$ such that each vertex of $V_1$ is ...
In order to show that Lambda calculus and Turing machines are equivalent it is sufficient to show that you can simulate one in the other [both ways]. We can observe it in action. Can one do the same on general recursive functions [ie mathematical functions as defined by Godel] Are there any reference reading materials?...
How to determine if an integer x > 0 can be represented as 20n + 50m + 100k, where n,m,k >= 0 and are integers.
Given some ordered list of $n$ items, I obviously have $n!$ possible arrangements. However, as a heuristic in some larger algorithm that needs to find the optimal order, I want to do some quick local exploration. One option is to walk through all possible removal & insert operations at $O(n(n-1))$. A similar option is ...
This video claims that the Mersenne-Twister is based on the Linear Congruential Generator. The math in the Mersenne-Twister original paper is a bit too much for me. I have not seen that claim explicitly made in the wikipedia article for Mersenne-Twister or in some of the other sources I consulted. Is the Mersenne-Twist...
Is this language context free? $L = \{a^kb^lb^ka^l \ | \ k,l \in \mathbb{N}\}$ Using Pumping Lemma and $z = a^nb^nb^na^n$ I find it contradicting PL. If $z = uvwxy$ and $|vwx| \leq n$, follows: $vwx$ is in either $a^n$ or $b^n$, second $b^n$, or second $a^n$. After pumping form of the word changes and thus pumped wor...
I'm trying to optimise (to a certain precision) a monotonic function for many points (100+). I know a-priori that the function is continuous, with some parts zero derivative. I know that all points lie within a range [a, b]. My current approach is to sample the range [a, b] with N points, and then find the closest init...
We know that computer programs are either AOT compiled, JIT compiled or interpreted And we also know that AOT compiled programs usually get compiled from its high level source code into machine code Now the question is, if machine code is so hard to understand and write, why the idea of compilers wasn't to translate pr...
I understand that if f(n) ∈ O(g(n)) and f(n) ∈ Ω(g(n)), we can conclude that f(n) ∈ Θ(g(n)). But what if we have an algorithm where the Big-O and Big-Ω are different? For example f(n) ∈ O(n^2) and f(n) ∈ Ω(n). Then what would be its Big-Theta notation? To me, it seems that both f(n) ∈ Θ(n^2) and f(n) ∈ Θ(n) would be te...
There are many posts here and elsewhere asking for algorithms to simplify simple arithmetic expressions. For example, this question asks how to simplify the expression $axc + byc + ayc + bxc$. Symbolics and xcas are two examples among many of Computer Algebra Systems (CAS) that can do this. But Symbolics and xcas perfo...
Let's assume I have the following regular language: L = {1,0}*{010}{1,0}* I would like to convert this to regex for a program. Would the equivalent regular expression for this be: ((0+1)*(010)(0+1)*) or ((0+1)*(010)(0+1)*)* Or is it something else completely?
Consider the reduction $A_{TM} \le_m \overline{E}_{TM}$, where $$A_{TM} = \{\langle M, w \rangle \mid \text{TM $M$ accepts $w$}\}\text{, and}$$ $$\overline{E}_{TM} = \{\langle M \rangle \mid \text{TM $M$ accepts some string}\}$$ Then define the mapping reduction, $f(\langle M, w \rangle)$ as follows: Construct a new TM...
consider $g$ and $f$ and $h$ as $ \begin{align*} g(m) &= \begin{cases} 1 & if\;program\;m\;halts\;on\;input\;m \\ 0 & otherwise \\ \end{cases} \end{align*} $ $ \begin{align*} f(m,n) &= \begin{cases} undefined & if\;m=n \\ 1 & if\;program\;m\;halts\;on\;input\;n \\ 0 & otherwise \\ ...
We want to show that the following function $F$ is primitive recursive (using the primitive recursion scheme) : For all $x,p,a\in \mathbb N$, $F(p,a,0)=g(\eta^{p}(a))$ $F(p,a,x+1)=h(\eta^{(p-(x+1))}(a),x,F(p,a,x))$ where $\eta, g : \mathbb{N}\to \mathbb{N}$ and $h: \mathbb{N}^3 \to \mathbb{N}$ are primitive recursive ...
I designed this FSM graph to demonstrate a DFA that would accept any string that is of length 5, must contain a d, can only have as and/or bs before the d, and can only have bs and/or cs after the d. Here is what I came up with: I was wondering if there is any way to improve the graph, by, for example, using fewer s...
a formulation on an example: let's have on a grid: a position of a bee queen Q (source node), a set of positions of free cells to lay an egg E (destination nodes), and a set of positions with worker bees W (moveable obstacles). the queen and workers can move to 4 orthogonally neighboring cells (left, right, up, down)...
Here is a problem inspired by the game Across the Obelisk. 4 players have decks of cards. Each card has an integer value between 0-9 on it. The decks can be any size, and there's no other restriction on the card values - each possible card-value can be represented any number of times, including 0. The game chooses an ...
I recently was constructing boolean logic for all sorts of examples from Morris Mano's "Digital Logic and Circuit Design". I noticed that it is possible to construct a boolean logic wrt the inputs which depends on the current state. My question is that is it possible to construct a boolean logic which depend on the pre...
Problem is to decide if it is possible to partition a given array nums into k partitions. I've written a brute force backtracking algorithm. How do we analyse this algorithm to calculate average runtime (average over all possible inputs -input may be such that it ends up "back-tracking" multiple times or possibly none)...
I have system of two polynomial two variables, second order; monomials are {${1,x,y,x^2,xy,y^2}$} I want find special systems of polynomials: two or more roots in specified range, two root close to each other, roots on boundary search range, etc. I can set one root to specified position by setting first term of polynom...
Suppose we want to create a priority queue with 2 operations: insert and extract almost min. Extract almost min operation selects either the first minimum or a second minimum item from the structure randomly, removes that item from the structure and outputs that item. How can we prove that both of these operations cann...
Let $P$ be a indexable set(array) of points in $\mathbb{R}^3$ s.t. $P = \{p_0,p_1,p_2,...,p_n\}, p_i \in\mathbb{R}^3$. I want to sort $P$ so that every 4 consecutive points forms a non-coplanar tetrahedra/3D-simplex/triangular pyramid (whatever you personally call it), I know there will be left over points, so I want t...
I am reading an algorithm book. Any comparison sort must make $\Omega(n\log(n))$ comparisons in the worst case to sort $n$ elements. Can we create a decision tree for any comparison sorting algorithm even if it is very complicated for $n$?
I have a list of values: [value1, value2, value3], and I am trying to generate all combinations of replacements with some default value (DEFAULT). Basically, result like this. [value1, value2, value3] [DEFAULT, value2, value3] [value1, DEFAULT, value3] [value1, value2, DEFAULT] [DEFAULT, DEFAULT, value3] [value1, DEFAU...
According to this, a weighted schedule is considered NP-complete (not solve-able in polynomial time) if it has groups of 3 or more intervals: https://en.wikipedia.org/wiki/Interval_scheduling#NP-complete_when_some_groups_contain_3_or_more_intervals But I don't understand the explanation at all. Why are 3 grouped interv...
I'd like to know if there's a non-recursively computable language that can be accepted by the Turing machine. From the following definition of the recursively enumerable language: and from the fact that recursively enumerable = Turing recognizable (from wiki) I think the answer is non-recursively enumerable language c...
In the ideal world, systems are designed using immutable data structures. However, when you dive deeper into lower levels of abstractions, you realize that at some point a library written in C is being used to performs some tricks that merge the unmutable with the mutable. Now, I am not intrested in whether or not I sh...
It is known that the complexity class P is equivalent to the class of problems decided by polynomial-time uniform familiy of circuits. When stating the complexity of algorithms as this family of circuits, this complexity is usually stated in terms of the depth and size of the circuit. What I have not understood well is...
Someone who was explaining to me the master theorem said that for the case 1, we compare the $n^{\log_b(a)}$ and $f(n)$. If the growth rate of $n^{\log_b(a)}$ is greater than the growth rate of $f(n)$ then we subtract an epsilon to have this equality: $$f(n) = O(n^{(\log_ba) - \epsilon})$$ My question is, doesn't the n...
I think that I have found an issue with the proof of the halting problem, which would cause the entire proof to be invalid. To ensure I understand, here is Turing's proof of the halting problem being unsolvable. Proof: Assume the function $h(x,y)$ determines whether the function $y(x)$ halts on input x, $h(x,y)$ retur...
I have two non-convex polygon which intersect one another. I have written program years ago to find union polygons. I described that I has been used algorithm Weiler-Atherton. But in Wikipedia I found that Weiler–Atherton algorithm is for clipping - is Weiler-Atherton for polygon union or I have mistaken the name? This...
I have been on this problem for very long time, Lets assume we have a shopping list eg:{milk,bread,coke,orange,apple,..} and the shop only sells pack of thing and not individual things eg: [{milk, bread}, {bread,orange} , {orange,apple} ...]. Given the cost of each package. Is there any algorithm to minimize the cost s...
Is there any proof or reference or intuition for the following theorem related to AAD: Any function f of n variables f(x1,...,xn) can be differentiated with respect to every variable xi at a computational cost that does not exceed 4 times the complexity of one computation of f. Thank you
If K = {<<M>> | L(M) has at least 1 word}, then does K belong to the class of recursive enumerable (RE) languages or its complement? I'm a bit confused, because if it is RE, then we'd have a TM W that semidecides it, but even for some language, L(M), that does halt for at least a word, we don't know which word it is an...
I have a matrix with three possible elements: A, B and C. The size of the matrix could be a maximum of 15x16. $$ \begin{bmatrix} A & A & C & A\\ A & C & B & C\\ A & C & B & C\\ A & A & C & A \end{bmatrix} $$ I need create a second matrix with the same size but different types. I need to cover all Cs with a "group", but...
The question is to convert the following regular expression to an NFA: $\emptyset^*$. I know that the symbol phi in Theory Of Computation means an empty set. But what does phi^* mean?
I read this article, mentioning that either here, or StackOverflow would be the best places to ask generic machine learning questions, however, if the question isn't programming specific with a minimal reproducible example, the mod's at S.O. can't wait to shut you down pretty quick, so figured I'd try here first. I'm d...
$A$ is an array of length $n$ $B$ is an $n\times n$ matrix \ I want to return an array C of size n such that: $$C_{i} = \sum_{j=1}^{n} \max(0, a_i - b_{ij}) $$ In pseudocode it could be like below for i = 1 to n: C[i] = 0 for j = 1 to n: C[i] += max(0, a[i] - b[i,j]) this runs on O(n^2) but it is pos...
$A$ is a $m*n$ matrix $B$ is an $n*n$ matrix I want to return matrix C of size m*n such that: $C_{ij} = \sum_{k=1}^{n} max(0, a_{ij} - b_{jk}) $ In pseudocode it could be like below for i = 1 to m: for j = 1 to n: C[i,j] = 0 for k = 1 to n: C[i,j] += max(0, a[i,j] - b[j,k]) this runs on $O...
The node weighted Steiner Tree Problem as found in this compendium: $\textbf{Instance}: \text{Graph } G = (V, E)\text{, set of terminals } S \subseteq V \text{ and a node weight function } w:V \to \mathbb{R}^+$ $\textbf{Solution}: \text{A tree } T = (V_T,E_T) \text{ in } G \text{, such that } S\subseteq V_T \subseteq V...
Given a DFA with m number of input alphabet and n number of states. What is time complexity to check DFA accepts infinite language (i.e infinite length of strings)?
I have run $k$-means on a large set of high-dimensional data, and now I want to find the distance from a point $x$ to the Voronoi cell associated with one of the $k$ centroids. (In a previous version of the question, I called this cell a "cluster", but that terminology might be confusing since one might think of a clu...
I have been struggling with this contest problem for awhile now which is found at this link: https://people.eecs.berkeley.edu/~hilfingr/programming-contest/pacific-northwest/2009/b.pdf Short summary of problem: Given an n×m board (3 ≤ n≤6, 5≤m≤50) move a Blenjeel sand worm (of length n) from the left column to the rig...
Here is the puzzle I was asked in an interview There's a List of Employee objects. Update all the objects in the list to be eligibleForHike if at least one employee exists whose salary is less than x; otherwise update all of them in-eligibleForHike in a single iteration/loop Requirements/Restrictions: Streams should n...
I'm preparing some material for students about greedy algorithms, and there is one point that confuses me: how Dijkstra's algorithm fits into the greedy framework. I would like to say that we have some optimization problem $\min_{S \in D} f(S)$. E.g.: For MST, $S$ is a spanning tree and $f(S) = \sum_{e \in S} w(e)$ Fo...
I'm wondering about the optimal complexity - or at the very least, some way of achieving non-terrible complexity - of a particular stack variant, that I'm calling a 'nonrepetitive stack'. A nonrepetitive stack is like an ordinary stack, except that a push that would result in a repeated subsequence fails, not updating ...
As is well-known (and easy to prove), carrying out a sieve of Eratosthenes on the first $N$ integers takes a number of word operations in the order of $N \sum_{p\leq \sqrt{N}} 1/p \sim N \log \log N$, whether one uses it for finding the primes up to $N$ or for factoring the numbers up to $N$. It is also well-known that...
I am thinking about the problem of storing traces of games like Chess and Othello in an information-theoretic minimal number of bits. My idea was to think of a game as an ordered tree of possible moves that could be taken. Let's say in one game there are 20 moves available initially, then 8 on the second turn, then 5 o...
According to the computer organization and design RISC-V 2nd edition 2020, section 1.5, the following table states that ISA affects clock rate. Hardware or software component Affects what? How? Algorith instruction count, CPI The algorithm determines the number of source program instructions executed and hence ...
I have a grammar which is mostly LL(1), save for the fact that some tokens may be promoted to larger integer types. For example, let take the following grammar S ::= terminal1 S1 S1 ::= integer_16 S2 | integer_32 S3 where S2 and S3 can share a common prefix but we assume the above grammar can be rewritten as LL(1), sa...
I am running into a problem in which I have names with different romanization methods, and I need to correctly compare them to see which names match. An example is romanized Korean variants: Seong vs Sung vs Song are all romanized variants of the same Korean character. A Levenshtein ratio would say that these are all d...
Also known as CMU 15-455, Spring 2017, Homework 2.4. Before I ask the main questions, let me first give a sketch of my idea. First, recall the definition of big-$O$ and time complexity class $TIME(t(n))$. Definition: Let $f$ and $g$ be functions $f$, $g$: $\mathbb{N}$ $\rightarrow$ $\mathbb{R}^+$. Say that $f(n)$ = $O...
Suppose $l=[a[0],a[1],a[2],,a[n]]$ be a list of numbers. I need to calculate $$ \sum a[j]a[k]a[j']a[k'] $$ such that $j+k=j'+k'$ .Obviously we can implement it in $O(n^4)$ time complexity by the exhaustive search method.Can we do it better?It is pertinent to mention the number of tuples satisfying $j+k=j'+k'$ are app...
The Coin Change problem is stated as: Given an integer array coins[ ] of size N representing different denominations of currency and an integer sum, find the number of ways you can make sum by using different combinations from coins[ ]. Note: Assume that you have an infinite supply of each type of coin. So for exampl...
I have a dataset of billions of points (stars) scattered on a two dimensional plane (sky), each with its corresponding (brightness) value. How can I efficiently find locations for a fixed size rectangle (corresponding to a telescope field of view) for which the point values sum up to a minimum?
I am doing some research for a paper that I am writing and one of the papers that I have come across that has some interesting results talks about an "almost tight bound". I am not a computer scientist and I feel like I understand the actual math of the bounding. However, I don't know what it means by "almost tight". I...
Background I'm looking to replicate (as closely as possible) the graphs depicted in this question (in MetaPost). Overview The green edges and large green nodes in the following image depict a graph (the grid and small nodes are irrelevant): The graph's properties include: Connected Uniformly random (or nearly so) Mul...
Given the programming language C#, how would I be able to write the BNF and EBNF grammar syntax of its while loop? After trying to search and understand more, I got this as my BNF grammar for while loops < while-statement > :: = < do-statement >< while-statement > | < do-statement > though I don't think it's quite righ...
I have to find the context-free grammar of this language: $ L=\{a^nb^m, n\neq 2m\} $ So I did: $ S \to a \mid aYb \mid \epsilon$ $Y \to aSb \mid X \mid \epsilon$ $X \to bX \mid \epsilon $ is it correct?
I couldn't search much about a problem I have. There is a 1D array of zeros and ones. The objective is to pack all ones with the least number of containers. Each container is variable in length but has a maximum length limit. Items in array cannot be moved. For example, if the max length limit is 5, I would pack ones l...
I was looking into complexity theory and disappointed by the fact that a problem as simple as sorting an array isn't in the class $P$. This is because the class is defined only for decision problems (ones that have a binary answer). I know that any optimization problem can be turned into a decision problem by imposing ...
I encountered many articles on max-flow problem that do not go beyond simple graphs in which two nodes are either connected with a single directed edge OR two nodes are connected with a single undirected edge, therefore making the capacity symmetric. When two nodes are connected with more than one edge, they use "trick...
If we find a problem we know for sure is in NP but not in NP-complete or P, we'll have proved P!=NP. One approach then is to identify problems in NP (but not P) we haven't been able to show to be NP-complete so far and try to prove they aren't in that set. Any examples of such problems? Preferably one problem per answe...
Let's say number of elements are a power of 4. Now if we break the array in parts of 1/4 and 3/4, how do we calculate the time complexity in this case?
R C Lacher's definition: A binary tree is complete iff the only vertices with less than two children are in the bottom two layers. Paul E. Black's definition: A binary tree in which every level (depth), except possibly the deepest, is completely filled. At depth n, the height of the tree, all nodes must be as far le...
Sometimes we need some prime number with certain minimum size for modular algorithm. For practical purposes we can precompute (using fast randomized algorithms) table of some primes for range which makes sense in application. However I'm interested how fast theoretically (in terms of time complexity on $n$) we can find...
From Wikipedia on $\mathrm{NP}$-completenes: "a [decision] problem is NP-complete if it is both in NP and NP-hard." [link] I think we can paraphrase this as the first statement: An $\mathrm{NP}$-hard (decision) problem $\Pi$ is $\mathrm{NP}$-complete if and only if $\Pi \in \mathrm{NP}$. $\#\mathrm P$-complete (count...
if a BFS is applied on a graph is it necessary that the resultant BFS tree contains all the edges that are in the original graph ?
I have a constraint system which I seek to find solutions for. The constraints consist of lesser/equal inequalities which have a difference of two minimum expressions on their right side, for example: $x_1 \leq min((x_2),(x_5 + x_6)) - min((x_3),(x_7 + x_8 + x_9))$ $x_2 \leq min((x_3 + x_4), (x_7)) - min((x_5 + x_8), (...
This is the first concept in The Little Typer to give me quite a bit of trouble, and it appears I am not alone (1 2), so perhaps it would be beneficial to ask here. Hopefully this can be connected with more general concepts to expand the audience for this question beyond people reading the book. The textbook The Little...
Well, I know that I'm going to ask too much. So, I really want to ask you a totally (powerful (!)) free completely off-line code to generate prompt-based images like midjourney. I want to run with my graphics card and memory without any restrictions of time or number of images and completely private. My question is: do...
Our professor has solved an example for us. They taught us it's incorrect to use a quantifier (exists or forall) with a variable that's already bound on the left side of the pipe (|, meaning "such that"). They've done that in their example solution. Can quantifiers be used on variables bound on the left side of the pip...
Given a list of integers NUMS and an integer k (buckets), we must allocate every integer from NUMS to some bucket such that maximum of sum of integers across all buckets is minimised. A simple algorithm which first sorts NUMS and then allocates integer to smallest bucket so far doesn't work. Eg. 5,5,4,4,4 for k=2. Outp...
Not sure if this is the right StackExchange site, but back in college (20 years ago) I took a Digital Systems Design class where we learned how to reverse engineer a boolean function to meet the requirements set forth in a logic table. If I recall correctly, the logic table looked something like this: Input A I...
This is a quote from the book, "The Three-Body Problem" (page 112 in the paperback): He remembered taking a class in information theory as a third-year student in college. The professor had put up two pictures: One was the famous Song Dynasty painting Along the River During the Qinming Festival , full of fine, rich de...
Given a sequence $a_1,\ldots,a_n$, we want to compute $$\prod_{\ell=1}^{n-1} \prod_{r=\ell+1}^n (\max(a_\ell,\ldots,a_r) - \min(a_\ell,\ldots,a_r)).$$ For example, given $1, 2, 4$, the result should be $6$, which is $(2-1)\cdot (4-1)\cdot (4-2)$. I know how to solve this in $O(n^2)$ by computing the inner product in ti...
Suppose that we have a set of paths that all of them strat from the source "I" and end to the destination "O". The paths might have shared nodes. We are allowed to change the sequence of nodes on paths. Now, I would like to create a DAG such that the number of merging edges (converging paths) are minimized. The number ...
Given $x \leq y$, find a sum $y_1+y_2+...+y_n$ where $y_i \leq x$ and $y_{i-1} \geq y_i$ for $1 \leq i \leq n$ and $y_n$ is maximised. For example, given $x = 5$ and $y=17$, an optimal solution would be $17=5+4+4+4$
Given is a prime signature $S$ and an integer $x$. The task is to count how many integers $n$ exist such that $n \leq x$, and if $n = p_1^{k_1}p_2^{k_2}p_3^{k_3}p_4^{k_4}...$ then $S = (k_1,k_2,k_3,...)$. Let $C(S,x)$ be that count. For example, if $S = (3,1,1)$ and $x=1000$ then there are $21$ such integers, being $$1...
I have a large list of strings with associated values. I need to do a fast lookup into the list by the string prefix, but also by the string's ordinal within the list. For example, string,value,ordinal -------------------- alice, 10, 0 bob, 99, 1 carol, 32, 2 search_by_prefix("bo") -> [("bob", 99),] search_by_ordina...
I have a randomized recursive algorithm which expected running time is $T(n)$. In particular, the recursion looks like this: $$ T(n) \leq \mathcal cn + R ,$$ where $R$ is a recursive term that depends on $T(n-i)$ for some values of $i$, and $c$ is some constant. I want to add a procedure to this algorithm that samples ...
Let $P(X,Y)$ and $Q(X,Y)$ be two bivariate polynomials of degree at most $n$. Using $O(n^2)$ FFTs, we can compute the product $PQ$ in time $O(n^3\log n)$. Q: Is there a faster algorithm to compute $PQ$?
moorse_string[] = {".-", // 0 = A ('A' = ASCII code 65; 'a' = ASCII code 97) "-...", // 1 = B "-.-.", // 2 = C "-..", // 3 = D ".", // 4 = E "..-.", // 5 = F ...
Is it possible to create a some programming language compiler that will perform the composition of primitive functions with optimization? In fact, the maximum possible optimization in the context of function composition. In this case, primitive means that the code consists only of while, if, break, continue statements,...
IIUC, category theory only applies to immutable objects, and mutability is modelled within that using e.g. functors, monads. Is that true? If so, why doesn't category theory include immutability? Has no-one got round to adding that, or is it impossible? I'm asking because I've never seen category theory applied to, or ...