instruction stringlengths 0 29.8k ⌀ |
|---|
PRNG with output of constant length |
|algorithms|pseudo-random-generators| |
Haskell supports immutable arrays in the obvious way. This is an extremely useful data structure when used in conjunction with lazy evaluation, because you can store unevaluated thunks in the array which get evaluated at most once when you read them.
Many dynamic programming algorithms become much simpler when you i... |
$\mathrm{PPAD}$ is a class of search problems, not of function problems. The notion of search problem is more general than that of function problem, which in turn is more general than a decision problem.
For a decision problem, we get an input and we need to answer *yes* or *no*.
For a function problem, we get an... |
In a directed, weighted graph with non-negative weights we are asked to find a path from a starting node s to node t that weights $\leq W$. In our given graph there is no such path but we have the ability to skip as many edges as we like.
How can I create an algorithm that calculates the number of minimum skips nee... |
Minimum number of skips needed for shortest path |
|algorithms|graphs|shortest-path|dijkstras-algorithm| |
Your answer is partially correct.
In case of recursive dfs algorithm, the time complexity will be **O(m)** as the system stack will only contain all the parent node states which will not be affected by the branching factor.
But, in case of iterative dfs algorithm, the stack we create must store all the first child ... |
The WHILE statement as described in the paper linked by OP has these features:
> It is a simple imperative language, with assignment to local variables, if statements, while loops, and simple integer and boolean expressions
Specifically, it has neither memory storage nor stack nor recursion nor any other unbounde... |
The WHILE statement as described in the paper linked by OP has these features:
> It is a simple imperative language, with assignment to local variables, if statements, while loops, and simple integer and boolean expressions
Specifically, it has neither memory storage nor stack nor recursion nor any other unbounde... |
The setting is the following: There are **n** players that want to compete in a specific game over the course of an event. A game is played between 2 teams of 2 players each (so a 2v2). Each player as a general rating value based on the [ELO-System](https://en.wikipedia.org/wiki/Elo_rating_system) and it is assumed tha... |
How to schedule ELO-based, fair games with n players and dynamic teams? |
|algorithms|optimization| |
null |
Category theory is not a good basis for understanding Haskell. Category theory has certain but limited use for learning functional programming and in actual practice of functional programming. I recently made a presentation to answer the question "What did category theory ever do for us (functional programmers)". See h... |
Well, the answer from Codeforces is still correct, you just need to find a suitable upper bound for how many layers you will need. An obvious upper bound would be the number of vertices, but a better estimate can be made by just running BFS in order to find the shortest unweighted path from $s$ to $t$; if there is a $(... |
Use additonal "state" information to the variable $S$ that specifies the number of terminal symbols generated, mod 3.
So we have three variables $S_i$, $i=0,1,2$, each keeping track of derivations for a string of length that remainder after division by three.
One example of a new production would be $S_1 \to aS_2... |
You have $n$ questions in an exam. Question $i$ is answered correctly with probability $p_i > 0$. If question $i$ is answered correctly, you get $R_i$ marks. You can choose to answer
the questions in any order. As long as you are giving correct answers, you can
accumulate all the marks. However, whenever your answer ... |
Dynamic programming: optimal order to answer questions to score the maximum expected marks |
|algorithms|optimization|probability-theory|greedy-algorithms| |
null |
Category theory is not a good basis for understanding Haskell. Category theory has certain but limited use for learning functional programming and in actual practice of functional programming. I recently made a presentation to answer the question "What did category theory ever do for us (functional programmers)". See h... |
Category theory is useful only in a few places in functional programming:
- Implementing libraries that work with arbitrary type constructors. Category theory is good for this kind of highly abstract code. For example, one can define a product of arbitrary endofunctors, a co-product of arbitrary endofunctors, etc., ... |
null |
Recently, I’ve been interested in the console of the Source game engine, more specifically, its `alias` command, which allows one command to invoke others. It may allow recursion (i.e. running “alias freeze freeze” will cause inputting “freeze” to crash the game.), but does not allow parameters (i.e. running “alias def... |
What extension of a finite-state machine is modeled by aliasing inputs? |
|finite-automata| |
Recently, I’ve been interested in the console of the Source game engine, more specifically, its `alias` command, which allows one command to invoke others. It may allow recursion (i.e. running `alias freeze freeze` will cause inputting `freeze` to crash the game.), but does not allow parameters (i.e. running “`alias de... |
Recently, I’ve been interested in the console of the Source game engine, more specifically, its `alias` command, which allows one command to invoke others. It may allow recursion (i.e. running `alias freeze freeze` will cause inputting `freeze` to crash the game.), but does not allow parameters (i.e. running “`alias de... |
Recently, I’ve been interested in the console of the Source game engine, more specifically, its `alias` command, which allows one command to invoke others. It may allow recursion (i.e. running `alias freeze freeze` will cause inputting `freeze` to crash the game.), but does not allow parameters (i.e. running “`alias de... |
Recently, I’ve been interested in the console of the Source game engine, more specifically, its `alias` command, which allows one command to invoke others. It may allow recursion (i.e. running `alias freeze freeze` will cause inputting `freeze` to freeze the game.), but does not allow parameters (i.e. running “`alias d... |
There are many plausible approaches, but one that would be easy to implement would be to formulate this as an instance of integer linear programming (a classic technique in operations research, which your problem could be considered an example of).
Introduce zero-or-one variables $x_{a,i,t}$, with the intended meani... |
Recently, I’ve been interested in the console of the Source game engine, more specifically, its `alias` command, which allows one command to invoke others. It may allow recursion (i.e. running `alias freeze freeze` will cause inputting `freeze` to freeze the game.), but does not allow parameters (i.e. running “`alias d... |
Recently, I’ve been interested in the console of the Source game engine, more specifically, its `alias` command, which allows one command to invoke others. It may allow recursion (i.e. running `alias freeze freeze` will cause inputting `freeze` to freeze the game.), but does not allow parameters (i.e. running "`alias d... |
_Note: this answer assumes one more rule on the WHILE language (which is not in the paper linked by OP), which is that the variables within are limited to a certain size. It does not matter which size, but they are bounded by some arbitrary number (which could even be specific for each program, and itself arbitrarily l... |
null |
I had asked a question here about this before but it was too obscure and had a lot of vagueness to it, so I'll rephrase the entire thing.
I'm trying to create a PRNG that would replicate Borge's Library of Babel, i.e. 3200 characters made of 29 individual characters (26 alphabets, space, comma and period). Yes, I kn... |
Creating a PRNG to replicate the LIbrary of Babel |
|algorithms|pseudo-random-generators| |
I had asked a question here about this before but it had a lot of vagueness to it, so I'll rephrase the entire thing.
I'm trying to create a PRNG that would replicate Borge's Library of Babel, i.e. 3200 characters made of 29 individual characters (26 alphabets, space, comma and period). Yes, I know libraryofbabel.in... |
Good question! It is possible using only natural numbers and arithmetic to implement a stack, due to [Gödel numbering](https://en.wikipedia.org/wiki/G%C3%B6del_numbering).
What's the basic idea? Well, a stack is basically a nested sequence of pairs: the stack $(1, 2, 3)$ (with $1$ on top) can be thought of as $(1, (... |
null |
|probability-theory|information-theory|entropy| |
The setting is the following: There are **n** players that want to compete in a specific game over the course of an event. A game is played between 2 teams of 2 players each (so a 2v2). Each player as a general rating value based on the [ELO-System](https://en.wikipedia.org/wiki/Elo_rating_system) and it is assumed tha... |
On top of the other answer, the reason why any data structure tends to be preferred by databases over any other data structure (e.g. B+-trees over anything else) usually boils down to two factors:
- Disk I/O performance. You want to minimise the number of disk accesses needed to use or modify the data structure, wh... |
In Boolean Satisfiability of CNF formulae we have $k$-SAT where each clause has at most $k$ literals. It is well known that $k$-SAT is polynomial time reducible to $3$-SAT. It is also well known that $2$-SAT is solvable in polynomial time whereas $3$-SAT is NP-Complete (and therefore $k$-SAT is NP-Complete by Cook's Th... |
Modified DPLL for 3-SAT by reducing to 2-SAT |
|reference-request|satisfiability|heuristics|3-sat|sat-solvers| |
In Boolean Satisfiability of CNF formulae we have $k$-SAT where each clause has at most $k$ literals. It is well known that $k$-SAT is polynomial time reducible to $3$-SAT. It is also well known that $2$-SAT is solvable in polynomial time whereas $3$-SAT is NP-Complete (and therefore $k$-SAT $(k \gt 2)$ is NP-Complete ... |
{"Voters":[{"Id":755,"DisplayName":"D.W."}],"SiteSpecificCloseReasonIds":[]} |
For an Algorithms course we are studying propositional calculus. As an excercise we are given formal statements which we are to explain in natural language first and then evaluate with specific values. As a very simple example, which will serve us to clarify matters of notation, statements are of the form
$$\langle ... |
Application of a formal definition of $max, min$ to evaluate an expression |
|algorithms|logic|propositional-logic| |
There are many plausible approaches, but one that would be easy to implement would be to formulate this as an instance of integer linear programming (a classic technique in operations research, which your problem could be considered an example of).
Introduce zero-or-one variables $x_{a,i,t}$, with the intended meani... |
In Chapter XIII: BlooP and FlooP and GlooP, Douglas Hofstadter states that:
> This puts us in the uncomfortable position of asserting that people can calculate Reddiag[N] for any value of N, but there is no way to program a computer to do so.
How come this is true? What if `Reddiag[N] = 1 + Reddiag[N]`? I underst... |
Reddiag being a calculable function |
|computability| |
The Wikipedia article on temporal logic [lists many varieties of temporal logic](https://en.wikipedia.org/wiki/Temporal_logic#Temporal_logics), such as LTL (linear temporal logic), CTL (computation tree logic), CTL*, and others. Which of these is the logic described in Manna & Pnueli's textbook *The Temporal Logic of R... |
Which temporal logic is the one described in Manna & Pnueli's "The Temporal Logic of Reactive and Concurrent Systems: Specification"? |
|temporal-logic| |
I came across the following problem in the book "Elements of Programming Interviews in Python".
>Given an array A of n objects with Boolean-valued keys, reorder the array so that objects that have the key false appear first. The relative ordering of objects with key true should not change. Use O(1) additional space ... |
Partition an array in two groups while keeping the relative order within groups |
|algorithms|mergesort|ordering| |
In [Gödel, Escher, Bach](https://en.wikipedia.org/wiki/G%C3%B6del,_Escher,_Bach) Chapter XIII: BlooP and FlooP and GlooP, Douglas Hofstadter states that:
> This puts us in the uncomfortable position of asserting that people can calculate Reddiag[N] for any value of N, but there is no way to program a computer to do ... |
Reddiag being a calculable function (Gödel, Escher, Bach) |
I came across the following problem in the book "Elements of Programming Interviews in Python".
>Given an array A of n objects with Boolean-valued keys, reorder the array so that objects that have the key false appear first. The relative ordering of objects with key $true$ should not change. Use $O(1)$ additional sp... |
Yes, there is such an algorithm. Hint:
>! Scan from right to left (from the end of the array towards the front). |
null |
**Does the Linz Ĥ applied to ⟨Ĥ⟩ correctly transition to its final reject state?**
A simulating halt decider correctly predicts what the behavior of its input would be if this simulated input never had its simulation aborted. It does this by correctly recognizing several non-halting behavior patterns in a finite num... |
**Does the Linz Ĥ applied to ⟨Ĥ⟩ correctly transition to its final reject state?**
A simulating halt decider (SHD) is any Turing Machine that correctly predicts what the behavior of its input would be if this simulated input never had its simulation aborted. It does this by correctly recognizing several non-halting ... |
Just for the record, the actual quote uses the word "arithmetic" rather than "deterministic" and is from John von Neumann in ["Various Techniques Used in Connection With Random Digits"](https://mcnp.lanl.gov/pdf_files/InBook_Computing_1961_Neumann_JohnVonNeumannCollectedWorks_VariousTechniquesUsedinConnectionwithRandom... |
Just for the record, the actual quote uses the word "arithmetic" rather than "deterministic" and is from John von Neumann in ["Various Techniques Used in Connection With Random Digits"](https://mcnp.lanl.gov/pdf_files/InBook_Computing_1961_Neumann_JohnVonNeumannCollectedWorks_VariousTechniquesUsedinConnectionwithRandom... |
The passage in question has a **standing assumption that `RedProgram` enumerates all computable total functions.** Since `Reddiag` is total and different from every function enumerated by `RedProgram`, we conclude that it is not computable. The text continues to reach the conclusion that the standing assumption is fals... |
null |
With recursive-descent parsing, direct/indirect left recursive rules do not allow top-down parsing.
How would this grammar be converted to be non-left recursive?
S-> Aa | b, A -> Ac | Sd | epsilon
I have gotten this far but I am not sure if it is correct.
```
S-> bS'
S'-> epsilon | AaS'
A-> SdA'
A'-... |
How would this grammar be converted to a non-left recursive rule? |
|formal-grammars|left-recursion| |
null |
Could someone help explain the logic of the ms .
The question is
[![enter image description here][1]][1]
The RandomChar() module is to be modified so that alphabetic characters are generated
twice as often as numeric characters.
Describe how this might be achieved.
and the marking scheme says
[![enter im... |
As level computer science paper 2 question |
|pseudocode| |
null |
null |
Suppose given two sets $\{a_1,a_2,\dots,a_n\},\{b_1,b_2,\dots,b_n\}$ of positive real numbers.
We try to find a subset $I\subseteq\{1,2,3\dots,n\}$ such that:
$\sum_{i\in I}b_i$ maximized and $\sum_{i\in I}a_i\leq 5$.
I think this problem is NP-hard but I can't reduce from famous problem like partition problem. An... |
NP-hardness of particular problem |
|algorithms|np-complete| |
null |
This is the optimization form of the 0-1 Knapsack problem ([Wikipedia][1]).
In a 0-1 Knapsack problem, you have a set of items, each item having a weight and value. You have to select a set of items such that the sum of the values is maximized, but that the total weight of the items does not exceed the total capacit... |
null |
null |
PMar's answer is correct. Having said that, there are several language classes "between" $P$ and $NP$.
An example is $RP$, the class of languages accepted in randomised polynomial time. A language is in $RP$ if it is accepted by an $NP$ machine with these properties:
1. If the answer is "yes", at least $\frac{... |
The subset sum problem can easily be solved in polynomial time in the number of items, and the sizes of the items. However, to be in NP, the solution must be in polynomial time in the problem size. Say all items are <= 9999, then I only need 4 digits to write down a number. If all items are less than a billion billion ... |
I have seen this C code showing an implentation of Peterson's Critical Section algorithm. It is obviously skeletal and hardwired for two thread but the logic is supposed to be correct in detail.
[![enter image description here][1]][1]
Despite reading and talking I remain with a grain of doubt about this:
[.
With the basic atomic awaits, the code could look like this
```
#include "critical3.h"
bool wantp = false, wantq = false, last = 1
active ... |
For starters, one could model this in one's favourite model-checking language such as Promela and explore the model with [spin](https://spinroot.com/spin/whatispin.html).
With the basic atomic awaits, the code could look like this
```
#include "critical3.h"
bool wantp = false, wantq = false, last = 1
active ... |
LTL.
PS The very book you mention has a historical note section discussing various other temporal logics near page 271. |
More broadly, the issue of repairing Reed-Solomon codes currently employed in industry has been discussed in the literature. It is important to find algorithms with low-bandwidth repair schemes for codes of short lengths with typical redundancies.
A recent paper is a good place to start since it has tables of curr... |
Nowadays people don't want their stolen computers to be used by a thief, and they don't want a thief to boot from an external hard drive and somehow manage to access their secrets on an internal drive.
So it is quite possible that an alternative boot drive has to be created on the original machine. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.