instruction stringlengths 0 29.8k ⌀ |
|---|
The problem concerns finding shortest paths in graph from a single source to a single destination.
So in a general non-degenerate case of a weighted graph, Dijkstra's algorithm runs in O(E+VlogV). A* runs in expected time O(E), because It uses additional information to find the path faster.
Now let's simplify... |
Is there an algorithm that in some cases is an improvement of BFS in the same way A* is an improvement of Dijkstra? |
|algorithms|graphs|shortest-path| |
Here is a simple method to find the parameters with respect to which (the problem whose worst runtime is bounded by) a big $O$-expression becomes fixed-parameters tractable (FPT), i.e., bounded by a product of some polynomial of the input size $n$ and a function that depends only on those parameters.
For example, $... |
I've been stuck on the following assignment taken from [*Cognition and Intractability: A Guide to Classical and Parameterized Complexity Analysis*](https://doi.org/10.1017/9781107358331):
> Imagine that the following big-O expressions correspond to the worst-case running times of different algorithms, where $n$ deno... |
How to find parameter sets for a big-O expression to be fixed-parameter tractable? |
A$^*$ can be an improvement of BFS in some cases, for example when searching a path in a maze.
Coincidently, I am currently working on such graph traversal with my students. Here are some of the results. The first image is done with BFS (yellow are unsuccessfully explored parts of the maze, in green is the solving p... |
A$^*$ can be an improvement of BFS in some cases, for example when searching a path in a maze.
Coincidently, I am currently working on such graph traversal with my students. Here are some of the results. The first image is done with BFS (yellow are unsuccessfully explored parts of the maze, in green is the solving p... |
null |
I've designed an algorithm to find the longest common subsequence. The steps are:
Start with `i = 0`
1. Picks the first letter from the first string start from $i^{th}$ letter.
2. Go to the second string looking for that picked letter.
3. If not found return to the first string and picks the next letter an... |
Algorithm for finding the longest common subsequence using hash table. Why is it slow? |
|algorithms|hash-tables|python|subsequences| |
null |
null |
The design of CPU control is not very well explained in textbooks, and this is partly because it's highly variable, but also because it's not very interesting from a computer science point of view, as opposed to an engineering point of view. There are lots of ways to do it, such designing a control component as a state... |
The design of CPU control is not very well explained in textbooks, and this is partly because it's highly variable, but also because it's not very interesting from a computer science point of view, as opposed to an engineering point of view. There are lots of ways to do it, such designing a control component as a state... |
null |
null |
Given a graph with $V$ vertices and $k$, find a set $K$ of $k$ vertices of $G$. Let $c(v)$ be the distance (in BFS-like) of the vertex $v \in V$ to the closest vertex $u \in K$. How to choose the set $K$ such that the maximum $c(v) \forall v \in V$ is minimized?
This is like a dominating set, but each vertex covers ... |
null |
Say I have a set of documents D in some natural language. Each document is a(n ordered multi-) set of words, Wi.A document is typically 1-2 sentences long.
The set of all words in this language is W.
Say I have some subset of W, K. Then say I have a subset of K, S.
I want to efficiently find all documents in D... |
Efficient search of a large set of documents to find documents that only contain a particular set of words |
|dynamic-programming|search-algorithms|natural-language-processing|search-problem|information-retrieval| |
As per [Wikipedia][1], Algorithm for In-order Traversal of Binary Tree
> 1. If the current node is empty/NULL/None return nothing.
> 2. Traverse the left subtree by recursively calling the in-order function.
> 3. Display the data part of the root (or current node).
> 4. Traverse the right subtree by recursively ... |
|algorithms|data-structures|trees|tree-traversal| |
null |
null |
Say I have a set of documents $D = \{d_1, d_2, \dots, d_n\}$ in some natural language.
Each document $d_i$ consists of a subset of words from a word pool $W = \{w_1, w_2, \dots, w_k\}$. For example, $\text{words}(d_1) = \{w_1, w_5, w_{7}\}$. $\text{words}(d_1)$ is an ordered multiset, but that isn't too important t... |
Say I have a set of documents $D = \{d_1, d_2, \dots, d_n\}$ in some natural language.
Each document $d_i$ consists of a subset of words from a word pool $W = \{w_1, w_2, \dots, w_k\}$. For example, $\text{words}(d_1) = \{w_1, w_5, w_{7}\}$. $\text{words}(d_1)$ is an ordered multiset, but that isn't too important t... |
I saw this question on a test-prep site
>Given a CFG and a string, what is the relation between the number of leftmost derivations, the number of rightmost derivations and the number of parse trees?
and the accepted answer was this
>For any unambiguous grammar,
>LMD and RMD is same and we have only 1 parse... |
Relation between left derivations, right derivations and number of parse trees? |
|context-free|parsers| |
I’ve had this question for several years now but have next to no programming experience, nor good connections to anybody who does. So I decided to see if stack exchange had an answer.
The idea is to make a program that takes some linguistic, grammatically correct set of words (such as a sentence or phrase), substitu... |
Considering definitions as equalities, what would happen if you continually substituted a word’s definition? |
|algorithms|algorithm-analysis|automata| |
You are trying to compute the set
$$E = \{e \in D \mid e \subseteq K \land e \cap S \ne \emptyset\}.$$
There is a naive algorithm. Store $K,S$ in a hashtable (using a hash function that maps each word to its hash value). Then for each $e \in D$, iterate through the words of $e$, look them up in the hashtable fo... |
{"Voters":[{"Id":755,"DisplayName":"D.W."}]} |
Given a tree with a root node $n$ and subtrees $T_1, T_2, \ldots, T_k$, the inorder listing of the nodes of the tree is the list of nodes of $T_1$ in inorder, followed by $n$, followed by the list of nodes of $T_2, \ldots, T_n$, with the nodes in each group listed in inorder. Note that trees are also called ordered tr... |
{"Voters":[{"Id":755,"DisplayName":"D.W."}]} |
Given a tree with a root node $n$ and subtrees $T_1, T_2, \ldots, T_k$, the inorder listing of the nodes of the tree is the list of nodes of $T_1$ in inorder, followed by $n$, followed by the list of nodes of $T_2, \ldots, T_n$, with the nodes in each group listed in inorder. Note that trees are also called ordered tr... |
If a recurrence relation is of the [form][1]
$$ T(n)= aT \left( \frac{n}{b} \right) + {n^k}(\log n)^p $$
then, as per the [Master Theorem][2], we have _six conditions_ depending on
value of $a,b,k$ and $p$
- If $\log_b a>k$ : Answer is $\Theta(n^{\log_b a})$
- If $\log_b a=k$ and $p>1$ : Answer is $\The... |
A *tree* is a finite set of one or more nodes such that there is one specially designated node called the root node of the tree, and the remaining nodes are partitioned into trees $T_1,\ldots,T_k$ (called the subtrees of the root), where $k\ge0$.
Given a tree with a root node $n$ and subtrees $T_1, T_2, \ldots, T_k$... |
null |
A *tree* is a finite set of one or more nodes such that there is one specially designated node called the root node of the tree, and the remaining nodes are partitioned into trees $T_1,\ldots,T_k$ (called the subtrees of the root), where $k\ge0$.
Given a tree with a root node $n$ and subtrees $T_1, T_2, \ldots, T_k$... |
I got an assignment to create a new data structure, with the following rules:
1. Init - O(1).
2. Insert x - O(log(n)).
3. Delete x - O(log(n)).
4. Search for x- O(log(n)).
5. Find max difference between two values in the DS - O(1).
6. Find min difference between two values in the DS - O(1).
I've outlin... |
Find the smallest difference between two numbers in a DS in O(1) time |
|time-complexity|data-structures|runtime-analysis|binary-trees|heaps| |
null |
Quick check:
$$\Theta(n^3)=27\,\Theta\left(\frac{n^3}{27}\right)+n^3\log\log n$$
does not hold. |
I think this can be done using [$(a,b)$-trees](https://en.wikipedia.org/wiki/(a,b)-tree) storing a bit more information in internal nodes:
- the minimum difference between two leaves in the subtree;
- the minimum and maximum values of a leaf in the subtree.
This can yield the wanted complexity:
1. init is ... |
$DVR($uses Bellman-Ford algorithm to reach the next hop e.g., $RIPv_1)$ and Link state$($uses Dijkstra algorithm for finding the shortest path to keep the knowledge of entire topology e. g. $OSPF)$ is the example of dynamic routing protocol.
In dynamic routing routers exchanges the routes (routing database) periodi... |
I think this can be done using [$(a,b)$-trees](https://en.wikipedia.org/wiki/(a,b)-tree) storing a bit more information in internal nodes:
- the minimum difference between two leaves in the subtree;
- the minimum and maximum values of a leaf in the subtree.
This can yield the wanted complexity:
1. init is ... |
I think this can be done using [$(a,b)$-trees](https://en.wikipedia.org/wiki/(a,b)-tree) storing a bit more information in internal nodes:
- the minimum difference between two leaves in the subtree;
- the minimum and maximum values of a leaf in the subtree.
This can yield the wanted complexity:
1. init is ... |
null |
A not completely outdated processor which has at least pipelining won't have a simple "control unit", but various units in different places that control things locally.
For example if you have four pipeline stages, then the second stage will decide whether it is ready to accept fresh data from stage 1; stage 1 will... |
$N$ towns are given, which we can get to by passing through the northern and southern gates. If you enter a town through a gate, you have to use another gate to leave the town. The merchant would like to plan his journey in such a way that starting from any town, he visits all towns exactly once and returns to the star... |
From [1, page 5, Notation and terminology]:
> A graph is complete if all vertices are joined by an arrow or a line. A subset is complete if it induces a complete subgraph. A complete subset that is maximal (with respect to set inclusion) is called a clique.
So, in addition to what was described above, [1] says th... |
I'm assuming that the sets of functions in big-Oh notation refer to the desired worst-case time complexity of the operations.
Your data structure is essentially an AVL tree $T$ plus a min-heap $H$.
The AVL tree stores your collection and also keeps track of the minimum element $m$ and the maximum element $M$ in it... |
I'm assuming that the sets of functions in big-Oh notation refer to the desired worst-case time complexity of the operations.
A possible data structure consists of an AVL tree $T$ plus a min-heap $H$.
The AVL tree stores your collection and also keeps track of the minimum element $m$ and the maximum element $M$ in... |
There is no fundamental reason. They are simply designed that way because adding the extra capability is wasteful. If you want 1TB of RAM, you buy a server system that can handle 1TB of RAM, not a desktop system that can only handle 32GB.
The limitation is more likely to be in the memory controllers which generate t... |
I have started to play around with HTTP3 which relies on QUIC for transport. I have noticed that I very often have a finite number of Web Transport sessions stream data continuously along side burst-y HTTP3 REST calls. At the QUIC level, all of these streams are going over the same connection and are demultiplexed via ... |
Is there a hash-map implementation optimized to favor key lookups based on frequency (if key is referenced the most then it is searched first)? |
|algorithms|search-algorithms|search-trees|hash-tables| |
There is no fundamental reason. It's simply an engineering decision, an implementation detail. If you want 1TB of RAM, you buy a server system that can handle 1TB of RAM, not a desktop system that can only handle 32GB.
The limitation is more likely to be in the memory controllers which generate the electrical signal... |
I'm assuming that the sets of functions in big-Oh notation refer to the desired worst-case time complexity of the operations.
A possible data structure consists of an AVL tree $T$ plus a min-heap $H$.
The AVL tree stores your collection and also keeps track of the minimum element $m$ and the maximum element $M$ in... |
I got an assignment to create a new data structure, with the following rules:
1. Init - O(1).
2. Insert x - O(log$_2$n).
3. Delete x - O(log$_2$n).
4. Search for x- O(log$_2$n).
5. Find max difference between two values in the DS - O(1).
6. Find min difference between two values in the DS - O(1).
I've ... |
I'm assuming that the sets of functions in big-Oh notation refer to the desired worst-case time complexity of the operations.
A possible data structure consists of an AVL tree $T$ plus a priority queue $H$ that supports insertions, deletions, and lookup of the minimum in time $O(\log n)$, $O(\log n)$, and $O(1)$ (r... |
By the definition, in an Interactive Proof systems the verifier is allowed to generate random numbers, which allows the omniscient prover to not fool it in the vast majority of cases for every problem in $\mathsf{PSPACE}$. The verifier is a polynomial time machine, therefore an ability to generate random numbers makes ... |
Assuming $\mathsf{P=BPP}$ would it be possible to derandomize the verifier in Interactive Proof systems? |
|complexity-theory|randomized-algorithms|randomness|interactive-proof-systems| |
If I copy a picture and paste it into Microsoft Word, would there be the difference if I embedded the same picture into another Word file ? Are they both object embedding?(As the object is saved in the document?) |
Is copying and pasting a sort of object embedding? |
|terminology| |
null |
I have started to play around with HTTP3 which relies on QUIC for transport. I have noticed that I very often have a finite number of Web Transport sessions stream data continuously along side burst-y HTTP3 REST calls. At the QUIC level, all of these streams are going over the same connection and are demultiplexed via ... |
$N$ towns are given, which we can get to by passing through the northern and southern gates. If you enter a town through a gate, you have to use another gate to leave the town. The merchant would like to plan his journey in such a way that starting from any town, he visits all towns exactly once and returns to the star... |
Use an AVL tree with each node having three additional entries $\min,\; \max$, and $\text{closest_pair} = (i,j)$, representing the minimum and maximum values of the tree rooted at that node. At the time of insertion and deletion, these values will be updated (Note that only $O(\log(n))$ node updates are needed per inse... |
null |
> Precondition: true <br>
int i = 0; <br>
while (i < a.length && a[i] != x) {<br>
i++;<br>
}<br>
Postcondition: (∀ j : 0 ≤ j < i : a[j] ≠ x) ⋀ (i = a.length ∨ a[i] = x) }
As I read it, the program has no precondition to be established, thus the precondition is always true? Is it like an indicator: "This progr... |
Why is there a 'true' statement as precondition in the following loop invariant |
|loop-invariants| |
null |
null |
I was viewing the solutions of other Leetcode users for the classic ["post-order traversal of a binary tree" question][1], when to my surprise, I found a ton of users simply finding the reverse preorder traversal (because it is considerably easier to implement iteratively), and then reversing the output. To my further ... |
Are reversed reverse preorder traversals equivalent to a postorder traversal? |
|binary-trees|graph-traversal| |
A few days ago, my tutor recommend [Stanford cs265][1] to me. I have read some lectures and watched some videos, I think it's really a great course for those who want to study randomized algorithm.
[1]: https://web.stanford.edu/class/cs265/#classes |
We want to show that the language $L_2 = \{0^n: n=2^k, k \ge 0\}$ is nonregular. By way of contradiction, suppose $L_2$ is regular. Let $p$ be the pumping length. Let $z = 0^{2^p}$. Then, $z \in L_2$ and $|z| \ge p$. Let $z=abc$ be a partition of $z$ such satisfying $|ab| \le p, |b| \ge 1$. Observe that $2^p < |ab... |
One plausible approach is to use integer linear programming. Introduce 0-or-1 variables $x_{q,r}$, where $x_{q,r}=1$ means that room $r$ is assigned to request $q$. Then you can write down linear inequalities that characterize the properties of a valid solution: e.g., $\sum_r \text{capacity}(r) x_{q,r} \ge \text{size... |
This can be proven by induction on trees. I give details on the conjecture 1 here.
- It is clearly true for the empty tree and for leaves;
- Suppose it is true for trees $l$ and $r$. Consider $t = N(l, x, r)$ a node with $l$ and $r$ as left and right children, and $x$ as root. Then, if we denote $Rpre(t)$ the rev... |
null |
If $L$ is a language of $A^*$ and $u, v$ are words, let
$$
u^{-1}Lv^{-1} = \{ x \in A^* \mid uxv \in L \}
$$
It is a well-known fact that if $L$ is regular, then every language $u^{-1}Lv^{-1}$ is regular and the set $\{u^{-1}Lv^{-1} \mid u, v \in A^*\}$ is finite. In particular, the subset $\{u^{-1}Lu^{-1} \mid u \... |
null |
I am a student want to study randomized algorithm. Someone recommend [cs271][1] to me, but it's restricted now.
Can someone recomend a good resource to study randomized algorithm, thank you a lot.
[1]: https://people.eecs.berkeley.edu/~sinclair/cs271/s20.html |
In DOI 10.48550/arXiv.1806.10254 and other CRDT-related publications by Preguiça's group, a dot symbol often appears without definition. What does it indicate, how standard is it as notation, and what field's literature does it come from? For example:
$$\{ v \vert \mathrm{wr}(v) \in O \wedge \nexists \mathrm{wr}(u) ... |
Dot symbol in set-builder expressions in CRDT literature? |
|distributed-systems|concurrency| |
This can be proven by induction on trees. I give details on the conjecture 1 here.
- It is clearly true for the empty tree and for leaves;
- Suppose it is true for trees $l$ and $r$. Consider $t$ a node with $l$ and $r$ as left and right children, and $x$ as root. Then, if we denote $Rpre(t)$ the reverse pre-orde... |
I came across one Big Theta expression:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/kGszp.png
Here I am thinking this expression to be valid. But please correct me as the answer doesn't goes in the same way.
As per definition of Big Theta.. any function f(n) execution time must lie... |
A little confusion with Big Theta time complexity |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.