instruction stringlengths 0 29.8k ⌀ |
|---|
I can suggest a simple algorithm. The psuedocode is below.
```
for (i=1; ((i*i) < n); i++); // this for loop will exit when i*i becomes >= n
if ((i*i) == n) {
return 1; // true
} else {
return 0; // false
}
|
{"Voters":[{"Id":683,"DisplayName":"Yuval Filmus"},{"Id":79440,"DisplayName":"Nathaniel"},{"Id":1329,"DisplayName":"Andrej Bauer"}]} |
For data structures you need to learn - stack, queue, linked list, and binary search tree. These 4 should be enough for interviews. You can google them and you will know what they are and how to implement them.
For algorithms, I would advise you to read the following book: The Design and Analysis of Computer Algor... |
Because $n$ and $m$ are given in binary, the length of the input is $O(\log n + \log m)$. Looping from 2 to $m$ will in this case require time not linear, but exponential in the size of the input. |
For data structures you need to learn - stack, queue, linked list, and binary search tree. These 4 should be enough for interviews. You can google them and you will know how to implement them.
There are some other data structures as well - set, multiset, map, multimap, etc. but I doubt if you will be asked to writ... |
It depends on exactly what you try to do.
Inserting at the start of the list or deleting the first item is O(1). The same if you are given a pointer to one element of the list and want to insert after that item or delete the next item.
Inserting at the end of the list or before a given item, or deleting the las... |
i have an idea of enhancing the heapsort by finding the max and min simultaneously and then swapping the max into the last node, and then the min will be swapped into the second to the last node, and then they will be removed or pop. and then they will be sorted in the array, the max will be at the last element, and th... |
Idea for Improving Heapsort |
|algorithms|heap-sort| |
One way to prove this is to show that the base language $L'=\{w∣|w|$
is prime $\}$ is regular. If it is, you can apply the known result that the $A^*$ of a regular language $A$ is regular. |
If data is coming continuously then if the writing speed is greater than the reading speed then obviously the buffer will become full.
However, it will not stagnate.
What will happen is that if the buffer is full then writing is stopped but reading will continue and then when some space becomes available in the b... |
null |
The pruning consists of 5 procedures:
1. Unit propagation.
2. Pure literal elimination.
3. Unique resolution*: if $l_i$ and $\overline{l_i}$ both occur in the formula just once each, merge the clauses they appear in and remove the literals.
4. 2-XOR clauses detection and substitution: if there is a pair of clau... |
Is it possible to perform the following kind of SAT pruning in $o(n^2)$ time? |
|algorithms|time-complexity|polynomial-time| |
The pruning consists of 5 procedures:
1. Unit propagation.
2. Pure literal elimination.
3. Unique resolution*: if $l_i$ and $\overline{l_i}$ both occur in the formula just once each, merge the clauses they appear in and remove the literals.
4. 2-XOR clauses detection and substitution: if there is a pair of clau... |
Is it possible that an AI bot behave as a human being in the long term?
I would like to know what people think but according to me it is not possible.
One example is - Many times humans know what is the right thing to do but they don't feel like doing it. In humans, there is a tussle between heart and mind many t... |
Is it possible that an AI bot behave as a human being in the long term? |
|artificial-intelligence| |
Is it possible that an AI bot behave as a human being in the long term?
I would like to know what people think but according to me it is not possible.
One example is - Many times humans know what is the right thing to do but they don't feel like doing it. In humans, there is a tussle between heart and mind many t... |
I have been struggling with the understanding of why this problem is in $coNP$.
**Problem:**
CNF-Equivalence, denoted as C, takes as input a pair of CNF formulas ($\phi, \sigma$) both are defined over the same set of $n$ variables $x = (x_{1}, x_{2}, ... x_{n})$. The goal is to decide whether these two formulas a... |
Why is this problem in $coNP$? |
|complexity-theory| |
|algorithms|time-complexity|satisfiability|polynomial-time| |
People have already explained that the time complexity is O(n^2). I will add something extra to this.
In real life, array storage is not incremented by the size of 1 element.
What happens is that if you have K items in the array and then when the time comes for allocation of new storage (for new elements) then ... |
> Non-Equivalence:
>
> In this case we will be checking for certificates until we find one for which the output is different.
To show that the formulas are not equivalent, it suffices to show just a single certificate $c$ for which $\phi(X\vert c)\neq\sigma(X\vert c)$. Clearly, checking a single certificate is po... |
The pruning consists of 5 procedures:
1. Unit propagation.
2. Pure literal elimination.
3. Unique resolution*: if $l_i$ and $\overline{l_i}$ both occur in the formula just once each, merge the clauses they appear in and remove the literals.
4. 2-XOR clauses detection and substitution: if there is a pair of clau... |
null |
You are correct, using the claims found in the book, we can obtain the time complexity by finding that $O(AUW) \times O(VA) = O(A^2VUW)$.
But, a time complexity of $O(V^2AUW)$ could be considered when we look at the SPFA algorithm to find a negative cycle in $O(E) = O(V^2)$ time on *average*, yielding a time complex... |
I think it is possible to solve almost this problem in $\mathcal O(n \log n)$, the difference being that $i \ne j$ is not required.
First, observe that the $\max\{a_i b_j, a_j b_i\}$ is unnecessary: It can be replaced by $a_i b_j$, since we get the other result by swapping $i, j$.
This leaves us with finding this... |
I think it is possible to solve almost this problem in $\mathcal O(n \log n)$, the difference being that $i \ne j$ is not required.
First, observe that the $\max\{a_i b_j, a_j b_i\}$ is unnecessary: It can be replaced by $a_i b_j$, since we get the other result by swapping $i, j$.
This leaves us with finding this... |
I think it is possible to solve almost this problem in $\mathcal O(n \log n)$, the difference being that $i \ne j$ is not required.
First, observe that the $\max\{a_i b_j, a_j b_i\}$ is unnecessary: It can be replaced by $a_i b_j$, since we get the other result by swapping $i, j$.
This leaves us with finding this... |
I think it is possible to solve almost this problem in $\mathcal O(n \log n)$, the difference being that $i \ne j$ is not required.
First, observe that the $\max\{a_i b_j, a_j b_i\}$ is unnecessary: It can be replaced by $a_i b_j$, since we get the other result by swapping $i, j$.
This leaves us with finding this... |
You're raising a critical question about the future of AI: whether it can genuinely mimic human behavior, not just in its actions but also in its internal decision-making processes. It's a complex topic with no easy answers, and there are strong arguments on both sides.
**Arguments for AI mimicking human behavior:**... |
We know that SAT is in NP. We now consider the complement of this problem, deciding whether two CNF formulas differ for at least one argument. We show that this is equivalent to SAT, and thus in NP. Therefore, the original problem will be in co-NP:
Reducing this problem to SAT:
-----
Given two formulas $(\phi, \... |
null |
null |
We know that SAT is in NP. We now consider the complement of this problem, deciding whether two CNF formulas differ for at least one argument. We show that this is equivalent to SAT, and thus in NP. Therefore, the original problem will be in co-NP (even co-NP-complete):
Reducing this problem to SAT:
-----
Given ... |
I think it is possible to solve almost this problem in $\mathcal O(n \log n)$, the difference being that $i \ne j$ is not required.
First, observe that the $\max\{a_i b_j, a_j b_i\}$ is unnecessary: It can be replaced by $a_i b_j$, since we get the other result by swapping $i, j$.
This leaves us with finding this... |
The question is about CNF-equivalence. This answer, however, chiefly is about CNF-not-equivalence, the complement problem of CNF equivalence. Two formulas $(\phi, \sigma)$ are not-equivalent if they differ on at least one assignment (i.e. if they are not equivalent). In this answer, we will see that CNF-not-equivalence... |
We know that $\mathsf P$ is low for itself. It's also low for $\mathsf{NP}$, $\mathsf{RP}$, $\mathsf{UP}$ and some other complexity classes that contain $\mathsf P$ and are contained in $\mathsf{NP}$. Does that actually hold for all such classes? |
Is $\mathsf P$ low for every complexity class between itself and $\mathsf{NP}$? |
|complexity-theory|time-complexity|np|oracle-machines| |
The question is about CNF-equivalence. This answer, however, chiefly is about CNF-not-equivalence, the complement problem of CNF equivalence. Two formulas $(\phi, \sigma)$ are not-equivalent if they differ on at least one assignment (i.e. if they are not equivalent). In this answer, we will see that CNF-not-equivalence... |
null |
null |
> Let $L = \{<M, W> | M \text{is a Turing machine, w is a string and some Turing Machine } M1 \text{ exists such that w does not belong to } L(M) \cap L(M1)\}$
I am unsure of how to deal with the TM *M1*. One idea I had was to let $L(M1) = \phi$ such that $L(M) \cap \phi = \phi$. So when we simulate *w* on *M* we ca... |
How to check whether a given language is decidable when the definition contains some predetermined machine |
|turing-machines|automata| |
> Let $L = \{\langle M, W \rangle \mid M $ is a Turing machine, w is a string and some Turing Machine $M_1$ exists such that w does not belong to $L(M) \cap L(M_1)\}$
I am unsure of how to deal with the TM $M_1$. One idea I had was to let $L(M_1) = \phi$ such that $L(M) \cap \phi = \phi$. So when we simulate $w$ on ... |
null |
Let $\varphi(X)$ be a boolean formula in CNF over a set $X$ of boolean variables $x_1,x_2,...,x_n$. Let $c_i$ denote $i^{th}$ clause in $\varphi(X)$.
$\varphi(X)$ is considered clause-pair minimal if $\forall i\forall j\neq i$ the CNF $c_i\land c_j$ consisting of two clauses can't be replaced with an equivalent CNF ... |
Is it possible to perform clause-pair minimization on a CNF instance in $o(n^2)$ time? |
We know that $\mathsf P$ is low for itself. It's also low for $\mathsf{NP}$, $\mathsf{RP}$, $\mathsf{UP}$ and some other complexity classes that contain $\mathsf P$ and are contained in $\mathsf{NP}$. Does it actually hold $\forall\mathcal C:\mathsf P\subseteq\mathcal C\subseteq\mathsf{NP}$ that $\mathcal C=\mathcal C^... |
we are looking into sampling nodes in a 2D map where new nodes can be inserted efficiently, without having to rebuild the complete tree and it is less costly to extract nodes from a built tree structure. Our requirements:
1. Sampling in a 2D map of road networks, so not a simple open map
2. Efficient new node ins... |
We are looking into sampling nodes in a 2D map where new nodes can be inserted efficiently, without having to rebuild the complete tree and it is less costly to extract nodes from a built tree structure. Our requirements:
1. Sampling in a 2D map of road networks, so not a simple open map
2. Efficient new node ins... |
We know that $\mathsf P$ is low for itself. It's also low for $\mathsf{NP}$, $\mathsf{RP}$, $\mathsf{UP}$ and some other complexity classes that contain $\mathsf P$ and are contained in $\mathsf{NP}$. Does it actually hold $\forall\mathcal C:\mathsf P\subseteq\mathcal C\subseteq\mathsf{NP}$ that $\mathcal C=\mathcal C^... |
We are looking into sampling nodes in a 2D map where new nodes can be inserted efficiently, without having to rebuild the complete tree and it is less costly to extract nodes from a built tree structure. Our requirements:
1. Sampling in a 2D map of road networks, so not a simple open map but a dense road network ma... |
I think it is possible to solve almost this problem in $\mathcal O(n \log n)$, the difference being that $i \ne j$ is not required.
First, observe that the $\max\{a_i b_j, a_j b_i\}$ is unnecessary: It can be replaced by $a_i b_j$, since we get the other result by swapping $i, j$.
This leaves us with finding this... |
Let $\varphi(X)$ be a boolean formula in CNF over a set $X$ of boolean variables $x_1,x_2,...,x_n$. Let $c_i$ denote $i^{th}$ clause in $\varphi(X)$.
$\varphi(X)$ is considered clause-pair minimal if $\forall i\forall j\neq i$ the CNF $c_i\land c_j$ consisting of two clauses can't be replaced with an equivalent CNF ... |
{"Voters":[{"Id":6553,"DisplayName":"Pseudonym"}]} |
It's provable that any $e$-deletion code is usable as an $e$-insertion code, but the proof is nonconstructive and doesn't necessarily give you an efficient decoding process that would work. (There is a generally applicable brute-force approach – deleting each element individually to see which one gives you a valid code... |
Given two boolean functions f1 and f2, are there any tools available that could be used to automate the process to represent f1 in terms of f2? I understand the process of this doing this by hand quite well, however, the process gets quite tedious with more variables. Are there any tools that are readily available onli... |
Expressing Boolean Functions In Terms of Another Function |
|computer-architecture|logic|boolean-algebra| |
null |
we are looking into a 2D sampling of points for our robot's planner. By sampling, I mean taking an initial point in our map and growing the tree structure through the 2D space by adding more points with a minimum radius approach. We need a graph or tree data structure with the following requirements:
1. Sampling an... |
I have read a book ‘Men of Mathematics’ by Eric Temple Bell, which includes the development of mathematics through ages and the biography of famous mathematicians . I am looking for such an history oriented book about computer science and the computer scientists. Can anyone suggeste me any such books and I am unable to... |
Good books about the history of computer science and its pioneers? |
|history|books| |
Disclaimer: I haven't read that book.
I don't think it's quite the book you're after, but Herman Goldstine's *The Computer from Pascal to Von Neumann* might be a good start. |
Disclaimer: I haven't read that book.
I don't think it's quite the book you're after, but Herman Goldstine's *The Computer from Pascal to Von Neumann* might be a good start. It's specifically about computing *machinery* rather than computer *science*, but talks about many of the main players such as Charles Babbage,... |
I'm working on a problem from my textbook (not homework, just an example), and it asks us to calculate the 'best case' scenario of reading a 1MB file from the hard drive.
I don't know why the right way to calculate the total time involves the max time for a single rotation. Also in the answer they said that a 1MB f... |
Why when calculating how long it would take to read a file from a harddrive do I not use transfer speed per sector? |
|computer-architecture|memory-hardware| |
I'm working on a problem from my textbook (not homework, just an example), and it asks us to calculate the 'best case' scenario of reading a 1MB file from the hard drive.
I don't know why the right way to calculate the total time involves the max time for a single rotation. Also in the answer they said that a 1MB f... |
The following question is related to finding the size of the original datagram. The formula for original datagram siz is: Data length of first packet + (Total lengths of subsequent packets * no. of subsequent packets. Do I also need to consider the header size for the first packet sent?
And what if the MF for the f... |
Do I need to consider the header size to calculate the original datagram? |
|computer-networks| |
For some reason they say the file has 10,000 sectors instead of 2,000 which may explain the difference.
They also forget that the file is most likely stored over three tracks so you need to add a bit of time twice to get to the next track. |
The following question is related to finding the size of the original datagram. The formula for original datagram size is: Data length of first packet + (Total length of subsequent packets * no. of subsequent packets. Do I also need to consider the header size for the first packet sent?
And what if the MF for the f... |
The following question is related to finding the size of the original datagram. The formula for original datagram size is: Data length of first packet + (Total length of subsequent packets * no. of subsequent packets. Do I also need to consider the header size for the first packet sent?
And what if the MF for the f... |
Let $\varphi(X)$ be a boolean formula in CNF over a set $X$ of boolean variables $x_1,x_2,...,x_n$. Let $c_i$ denote $i^{th}$ clause in $\varphi(X)$. $x_j^0$ denotes $\overline{x_j}$ and $x_j^1$ denotes $x_j$.
$\varphi(X)$ is considered clause-pair minimal if $\forall i\forall j\neq i$ the CNF $c_i\land c_j$ consist... |
null |
null |
We are looking into a 2D sampling of points for our robot's planner. By sampling, I mean taking an initial point in our map and growing the tree structure through the 2D space by adding more points with a minimum radius approach. We need a graph or tree data structure with the following requirements:
1. Sampling an... |
We are looking into a 2D sampling of points for our robot's planner. By sampling, I mean taking an initial point in our map and growing the tree structure through the 2D space by adding more points with a minimum radius approach. We need a graph or tree data structure with the following requirements:
1. Sampling an... |
Optimal graph data structure for 2D sampling of points that allows dynamic updates |
We are looking into a 2D sampling of points for our robot's planner. By sampling, I mean taking an initial point in our map and growing the tree structure through the 2D space by adding more points with a minimum radius approach. We need a graph or tree data structure with the following requirements:
1. Sampling an... |
We are looking into a 2D sampling of points for our robot's planner. By sampling, I mean taking an initial point in our map and growing the tree structure through the 2D space by adding more points with a minimum radius approach. We need a graph or tree data structure with the following requirements:
1. Sampling an... |
The outline of the exercise is this:
Describe two non-regular L1 and L2 languages on A = {a,b} such that L1∩L2 is infinite and regular.
The proposed solution to this exercise is:
**L1 = {a^n b^n | n > 0}**
**L2 = {a^n b^m | n != m AND word length is even}**
**L1∩L2 = {words of even length}**
What I do... |
Can the intersection of 2 non-regular languages be a regular and infinite language? |
|regular-languages|finite-automata| |
The outline of the exercise is this:
Describe two non-regular L1 and L2 languages on A = {a,b} such that L1∩L2 is infinite and regular.
The proposed solution to this exercise is:
**L1 = {a^n b^n | n > 0}**
**L2 = {a^n b^m | n != m AND word length is even}**
**L1∩L2 = {words of even length}**
What I do... |
The intersection of the languages $L_1$ and $L_2$ given is indeed empty.
To built a very simple example, let's do the following:
$$A := \{aaa^nb^n \mid n \in \mathbb{N}\} \cup \{bw \mid w \in \{a,b\}^*\}$$
$$B := \{aba^nb^n \mid n \in \mathbb{N}\} \cup \{bw \mid w \in \{a,b,\}^*\}$$
Now we have that $A \cap B... |
The machine $M_1$ is not a predetermined machine, but we rather find that $M_1$ is within the scope of an existential quantor. As you have observed, for all $w$ and $M$ there is some $M_1$ such that $w \notin L(M) \cap L(M_1)$, namely some $M_1$ which always answers "no".
Thus, we can simplify the definition of $L$ ... |
The machine $M_1$ is not a predetermined machine, but we rather find that $M_1$ is within the scope of an existential quantor. As you have observed, for all $w$ and $M$ there is some $M_1$ such that $w \notin L(M) \cap L(M_1)$, namely some $M_1$ which always answers "no".
Thus, we can simplify the definition of $L$ ... |
$\mathrm{MFVS} \leq 1$ is a concise way of writing the following decision problem:
> Let $G = (V, E)$ be a directed graph. Is there a $v \in V$ such that every cycle in $G$ passes through $v$?
(More generally, $\mathrm{MFVS}$ stands for _minimal feedback vertex set_, the problem of finding the smallest set of ver... |
Can we solve $\mathrm{MFVS} \leq 1$ in linear (or subquadratic) time? |
|algorithms|graphs|time-complexity| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.