instruction
stringlengths
0
29.8k
⌀
If we consider the class fair division problem where we have a set of $n$-agents and a set $M$ of $m$-items, where each agent has a valuation function defined on the set of items $$v_i : 2^m \rightarrow \mathbb{R}$$ The problem is to find an allocation across the $n$ agents $(A_1, ..., A_n)$ such that no agent envie...
We have two integers, $n$ and $d$. They are coprime (the only positive integer that is a divisor of both of them is $1$). They may be implemented as something that fits in a machine register, or they may be "big integers". Together, $n$ and $d$ represent the numerator and denominator of a rational number. The goal i...
Convert a rational number to a floating-point number exactly
|algorithms|floating-point|number-formats|real-numbers|
In the paper, it says: > Specification 1. > - a) The domain of tickets is the set of integers > modulo mN for some integer m ≥ 3. > - b) At any time, the set of tickets > that are active is confined to some interval of fewer than mN/2 > consecutive integers modulo mN. According to their specification, the ac...
Big floats are nothing but big ints with a scaling factor, which you can handle by yourself. If the two numbers are given as big ints and you are only allowed integer division, multiply the numerator by a power of $2$ large enough that the quotient has at least $24$ (resp. $53$) significant bits. Then normalize the ...
Reading a paper, I have found an algorithm that uses binary search to find a number between $0$ and $n\in\mathbb{N}$. The stopping criterion for this binary search is that $t_2-t_1<\frac{1}{k^2}$ where $k>=1$ is a natural number and $t_2>t_1$. Then, it is said that the number of iterations of the binary search is at mo...
Number of steps of binary search given a stopping criterion
|algorithms|algorithm-analysis|binary-search|
Consider n-dimensional linear classifiers, that is, subsets of R n that have the form {(x1, x2, . . . , xn)| a1x1 + a2x2 + · · · + anxn ≥ b} for some real numbers a1, . . . , an and b. Given as input two sets X and Y of polynomiallymany points in R n , show that there is a polynomial-time algorithm to decide whether th...
Construct polynomial-time algorithm to decide whether there is a linear classifier containing all points in X and no points in Y
|automata|np|
[![graph][1]][1] I get the residual graph by Ford-Fulkerson Algorithm: [![2][2]][2] I get that the minimum cut can be found by the residual graph, and when traversing this residual network from the source to all reachable nodes, these nodes define one part of the partition. Call this partition $S$, the rest ...
Why do we need the main function and can't we execute the code without it? Can't we just execute our code outside the main function by making our own function?
Why do we use main function in almost all the programming languages?
|programming-languages|
Given N integers L1, L2, ... , Ln ,we have a robot that starts at (0,0) moves north on integer grid for L1 steps, then it either continues in its current direction or makes 90 degrees right turn then moves L2 steps and repeats for all Li. Problem: Can the robot return to the origin?
Is this path planning problem NP-complete?
|complexity-theory|np-complete|
null
Consider the following "DOUBLE-PARTITION" problem: given a set of $m$ positive integers $X = \{ x_1, x_2, \dots, x_m\}$, can you partition $X$ into four sets $A,B,C,D$ such that $\sum_{a \in A} a = \sum_{b \in B} b$ and $\sum_{c \in C} c = \sum_{d \in D} d$? There is a Karp reduction between DOUBLE-PARTITION and you...
Consider the following "DOUBLE-PARTITION" problem: given a set of $m$ positive integers $X = \{ x_1, x_2, \dots, x_m\}$, can you partition $X$ into four sets $A,B,C,D$ such that $\sum_{a \in A} a = \sum_{b \in B} b$ and $\sum_{c \in C} c = \sum_{d \in D} d$? There is a Karp reduction between DOUBLE-PARTITION and you...
null
Well, there needs to be somewhere your code starts executing(apart from the necessary initialisation and cleanup, which isn't readily visible to the programmer in the form of code). Let's take reference to the C language, which influenced almost every other programming language. [Documentation for `main()` in C][1] ...
This is a design decision in the C language. Besides making `main` a reserved name, this is quite harmless and you can always implement the main function as a mere call to your favorite function. Without this convention, you would need to tell the linker what is the entry point in the executable by some external met...
This is a design decision in the C language. Besides making `main` a reserved name, this is quite harmless and you can always implement the main function as a mere call to your favorite function. Also note that `main` has a fixed prototype, that allows to interact with the OS. Without this convention, you would need...
null
Let us consider m clauses containing 3 variables each i.e. **A<sub>1</sub>**,**A<sub>2</sub>**,**A<sub>3</sub>**...**A<sub>m</sub>** . Let the total literals in consideration be n. Then each clause : **A<sub>i</sub>** = (**x<sub>r</sub>** $\lor$ **x<sub>s</sub>** $\lor$ **x<sub>t</sub>**) where 1 $\le$ r,s,t $\...
Finding a Polynomial Time algorithm for the 3-SAT Problem
|complexity-theory|satisfiability|
Let us consider m clauses containing 3 variables each i.e. **A<sub>1</sub>**,**A<sub>2</sub>**,**A<sub>3</sub>**...**A<sub>m</sub>** . Let the total literals in consideration be n. Then each clause : **A<sub>i</sub>** = (**x<sub>r</sub>** $\lor$ **x<sub>s</sub>** $\lor$ **x<sub>t</sub>**) where 1 $\le$ r,s,t $\...
Let us consider m clauses containing 3 variables each i.e. **A<sub>1</sub>**,**A<sub>2</sub>**,**A<sub>3</sub>**...**A<sub>m</sub>** . Let the total literals in consideration be n. Then each clause : **A<sub>i</sub>** = (**x<sub>r</sub>** $\lor$ **x<sub>s</sub>** $\lor$ **x<sub>t</sub>**) where 1 $\le$ r,s,t $\...
Let us consider m clauses containing 3 variables each i.e. **A<sub>1</sub>**,**A<sub>2</sub>**,**A<sub>3</sub>**...**A<sub>m</sub>** . Let the total literals in consideration be n. Then each clause : **A<sub>i</sub>** = (**x<sub>r</sub>** $\lor$ **x<sub>s</sub>** $\lor$ **x<sub>t</sub>**) where 1 $\le$ r,s,t $\...
Let us consider m clauses containing 3 variables each i.e. **A<sub>1</sub>**,**A<sub>2</sub>**,**A<sub>3</sub>**...**A<sub>m</sub>** . Let the total literals in consideration be n. Then each clause : **A<sub>i</sub>** = (**x<sub>r</sub>** $\lor$ **x<sub>s</sub>** $\lor$ **x<sub>t</sub>**) where 1 $\le$ r,s,t $\...
Let us consider m clauses containing 3 variables each i.e. **A<sub>1</sub>**,**A<sub>2</sub>**,**A<sub>3</sub>**...**A<sub>m</sub>** . Let the total literals in consideration be n. Then each clause : **A<sub>i</sub>** = (**x<sub>r</sub>** $\lor$ **x<sub>s</sub>** $\lor$ **x<sub>t</sub>**) where 1 $\le$ r,s,t $\...
|complexity-theory|np-complete|np-hard|np|satisfiability|
How to remove left recursion in the following Grammar: S→Bb/a B→Bc/Sd/e Im new to this, below is the way I'm doing it: S-> Sd/a B-> Bc/Bb/e I replaced the values of S and B with Bb and Sd to make the grammar easier to deal with. Then: S-> aS' S'-> dS' / ε Is this the correc...
How to Remove Left Recursion from this Grammar?
|context-free|formal-grammars|compilers|recursion|
null
I recently got onto the following problem: we consider the following array: A = [2, 3, 6, 1, 6, 4, 12, 24] we need to count the number of times these two conditions are satisfied within the array: A[i] * A[j] * A[k] = A[l] so that 0 <= i < j < k < l < len(A) for this example the result should be 8. ...
Speed up counting the number of A[i] * A[j] * A[k] = A[l] where i < j < k < l
|algorithms|dynamic-programming|memoization|
{"OriginalQuestionIds":[159989],"Voters":[{"Id":755,"DisplayName":"D.W."}]}
Given points $p_1,\ldots,p_n$ in $\mathbb{R}^2$, the task is to find an axis-aligned unit square containing the maximum number of points. I came up with and $O(n^3)$ algorithm as follows. Observation 1: For $n\geq 2$, there is an optimal solution containing at least two points on the boundary not lying on a line par...
Find a unit square containing most of the points
|algorithms|optimization|computational-geometry|check-my-answer|
I recently discussed DMA and non-DMA with my OS professor. Here is my current understanding: - disk controller has its own CPU, maybe own ISA, tiny program that simply handles reading from the disk (firmware) - it is sort of "client-server" in that the main CPUs are the clients and the disk controller is the server...
How does non-DMA transfers really work?
|computer-architecture|distributed-systems|computer-networks|memory-management|memory-hardware|
null
I need to efficiently find the intersections between a set of vertical line segments and a set of horizontal ones. The segments in both families can overlap (but there are no duplicates). Presumably this is done in time $O(n\log n+k)$ for $n$ segments and $k$ intersections. Can someone describe an ad-hoc solution or...
Red-blue orthogonal line intersection algorithm
|computational-geometry|
null
I want to give another concrete example. The set of encodings of halting Turing machines $R$ is countable (since there are only countably many Turing machines, halting or non-halting). But $R$ itself is not computably enumerable. Assume $R$ were computably enumerable. Then we can enumerate the encoding of each halt...
null
As settled in the Question's comments: The residual graph, as presented, is incomplete. The residual graph must include the non-zero reverse flow arcs. Then anything reachable from the source $S$ in that residual graph forms one part of the partition of the min cut.
This is partly to do with the grammatical structure of the language. Consider Java for example: - At the top level, each file is a **compilation unit**, - A compilation unit contains **type declarations** (classes, interfaces or enums), - A type declaration contains **member declarations** (fields, methods, constr...
Let us consider m clauses containing 3 variables each i.e. **A<sub>1</sub>**,**A<sub>2</sub>**,**A<sub>3</sub>**...**A<sub>m</sub>** . Let the total literals in consideration be n. Then each clause : **A<sub>i</sub>** = (**x<sub>r</sub>** $\lor$ **x<sub>s</sub>** $\lor$ **x<sub>t</sub>**) where 1 $\le$ r,s,t $\...
If we consider the complexity classes **RP** and **BPP**, then to show **RP<sup>BPP</sup> = BPP<sup>RP</sup>**, then my first thought is we need to use some kind of majority voting to amplify our success probabilities. The issue is I don't necessarily see how we can get from a two sided error to a one sided error. How ...
**RP<sup>BPP</sup> = BPP<sup>RP</sup>**
|complexity-theory|turing-machines|complexity-classes|oracle-machines|probabilistic-turing-machines|
Yes, the algorithm is correct. It can be sped up by using implementing the 'count number of points within a box' using smarter data structures. In particular, a running time of $O(n^2 \log n)$ is achievable. Let $N(x_\ell,y_\ell,x_u,y_u)$ denote the number of points within the box $[x_\ell,x_u] \times [y_\ell,y_u]...
Relativizations/Oracles for the BPP and RP complexity classes
If we consider the complexity classes **RP** and **BPP**, then to show **RP<sup>BPP</sup> = BPP<sup>RP</sup>** my first thought is we need to use some kind of majority voting to amplify our success probabilities. The issue is I don't necessarily see how we can get from a two sided error to a one sided error. How would ...
Hello everyone i'm from Turkey and i'm 18 years old. I'll get university exam after a month. I want Computer Science department. But there is only one department for it and this department's score is very very higher than i can do. I wanna carier about Quantum Engineering and according to my research i need get Compute...
Computer Science Education
|education|
If we let a language *L* in {0,1}<sup>*</sup> be dyadic if for each x in *L*, and each index i with x<sub>i</sub> = 1, i is a power of 2, then consider the class of languages recognized by a polynomial time oracle machine with a dyadic oracle. Is this the same as the class **P/poly**? If we start with some language L i...
P/poly and dyadic oracle
|complexity-theory|turing-machines|complexity-classes|circuits|oracle-machines|
After $m$ iterations, the interval size is $$\frac{t_2-t_1}{2^m}=\frac{n+1}{2^m}.$$ This becomes smaller than $k^{-2}$ when $$\frac{n+1}{2^m}\le\frac1{k^2}$$ or $$m\ge\log_2(k^2(n+1))=2\log_2(k)+\log_2(n+1).$$
The problem is implementation of specific halftone circle pattern algorithm, which should generate a bitmap image composed of **black** and **white** **circles** reflecting the halftones of the original image. When viewed from a distance, the image should display smooth shading, but up close, it should consist of only ...
Halftone Circle Pattern Algorithm Implementation
|algorithms|computer-graphics|
Consider the surface of equation $z=(1-x^2)(1-y^2)$ in the domain $[-1,1]\times[-1,1]\times[0,1]$. The cross-section by the plane $z=0$ is a square, and when you move it up, it progressively turns to a circle. [![enter image description here][1]][1] Now you can rotate the coordinates and work with $x=u+v,y=u-v...
How to remove left recursion in the following Grammar: S→Bb/a B→Bc/Sd/e Im new to this, below is the way I'm doing it: S-> Sd/a B-> Bc/Bb/e I replaced the values of S and B with Bb and Sd to make the grammar easier to deal with. Then: S-> aS' S'-> dS' / ε Is this the correc...
"A window" will also mean "an axis-aligned unit square". As observed in the question, there is an optimal window such that - either the bottom left corner is a given point. - or the left side contains a given point not on the bottom side and the bottom side contains a given point not on the left side. Hence w...
"A window" will also mean "an axis-aligned unit square". As observed in the question, there is an optimal window such that - either the bottom left corner is a given point. - or the left side contains a given point not on the bottom side and the bottom side contains a given point not on the left side. Hence w...
null
Hy everyone. I'm trying to write the SJF (short job first) algorithm NON-PREEMPTIVE for scheduling processes in C. I want to implement an algorithm that orders some processes by the burst of the processes. I get in input a list of "n" processes where I have the id, arrival time, and burst time for each process. It se...
Problems with writing short job first algorithm(for scheduling of processes) in C language
|algorithms|programming-languages|operating-systems|process-scheduling|c|
**Two nodes u, v are said to be incomparable if there are no paths from u to v and from v to u.** I can't see a linear solution to this. We can do a DFS for each pair (u,v) and (v,u) as in [here][1]. The fact that it is a DAG hints topological order but is this useful? Can this be solved with linear complexity...
Linear algorithm to decide whether a DAG contains at least one incomparable pair of nodes
|dag|directed-graphs|topological-ordering|
Observe that if there exists a vertex $u$ that is incomparable with another vertex $v$ in a DAG, then $u$'s order in a topological sort can be changed with respect to $v$. Equivalently, $u$'s position in the topological order is not fixed. Hence, to answer your problem, you just have to find if there is a vertex with n...
Compute a topological ordering $(v_1, v_2, …, v_n)$ of the DAG. Now consider the recursive following algorithm: - if $n = 1$, then there are no incomparable pairs of vertices; - if $(v_1, v_2)\notin E$, then $v_1$ and $v_2$ are incomparable (by definition of a topological ordering); - otherwise, assume $n\geqslant...
null
I did not find a class of decision problems that is equivalent to FPTAS, but I think FPTAS can be used to answer the following *partial* decision problem: > Given a number $r$ and an approximation-accuracy $\epsilon>0$: > * If $OPT \leq r$, return "yes"; > * If $OPT > r\cdot(1+\epsilon)$, return "no"; > * Otherwi...
null
Let $A$ be a sorted array of integers and $w$ - some integer number. Let integers from $A$ be points on a real line $\mathbb{R}$. Imagine a window of width $w$ moving from $-\infty$ to $\infty$. At each possible position of this window you can count total number of points from $A$ within a window. Let's call this numbe...
Querying rolling total maximum
|algorithms|data-structures|arrays|
null
Here is an $O(|V|+|E|)$-time algorithm that decides whether a DAG contains at least one incomparable le pair of nodes. 1. Do a topological sorting. 2. For each pair of adjacent nodes in the topological order obtained, check if there is an edge between them. If there is none, return True. 3. Return Yes. This alg...
null
null
Here is an $O(|V|+|E|)$-time algorithm that decides whether a DAG contains at least one incomparable le pair of nodes. 1. Do a topological sorting with a linear algorithm. 2. For each pair of adjacent nodes in the topological order obtained, check if there is an edge between them. If there isn't, return TRUE. 3. R...