instruction stringlengths 0 29.8k ⌀ |
|---|
|algorithms|complexity-theory|parameterized-complexity|treewidth| |
null |
I encountered an exercise in which I am struggling to understand the solution provided even though I spent a lot of time trying to figure it out.
The exercise is the following and was taken from the book "The art of computer programming - Volume 1 by Donald Knuth"
[![Reference: The art of computer programming Vol... |
Question about stack permutations |
|combinatorics|permutations|stacks| |
Consider a logical address space of 4096, page size = 1024
physical memory = 8192
$\begin{array} {|c|c|}
\hline
\text{Page No} & \text{Frame No} \\
\hline
0 &7 \\
\hline
1 &4 \\
\hline
2 &2 \\
\hline
3 &3 \\
\hline
\end{array}$
What is the physical address corresponding to logical address 500, 1000, ... |
null |
Suppose towards a contradiction that $L$ is regular and let $p$ be a prime number larger than $L$'s pumping length. Since $a^{p^2} \in L$, by the pumping lemma we know that there is some $1 \le k < p$ such that $a^{ki+p^2} \in L$ for all $i \ge -1$.
Since $k$ cannot have $p$ as a prime factor, $k$ and $p^2$ must be ... |
Without arrays, $\Omega(\log n)$ time is needed. Without arrays, the memory address you access is entirely determined by the control-flow path, i.e., the sequence of control-flow decisions (if construed appropriately) made during the execution. At each step, you can only choose between one of two (or a fixed finite n... |
Let $k$ be the parameter. Is an algorithm has a running time of the form $O(f(2k+1) \cdot \text{poly}(n))$ for a suitable function $f$, then it also has a running time of $O(g(k) \cdot \text{poly}(n) )$ for $g(k) = f(2k+1)$. |
@D.W. what if at each step, there is not a fixed finite number of choices, rather some $k$ choices. In that case, there would be $O(k^t)$ different control-flow paths. By properly tuning, $k$ and $t$ , we can get $t^t \geq n$ or $t \geq W(n)$. Here $k$ is [Lambert's W-function][1]. @D.W. I think a little more explanati... |
If you only want to count the number of comparisons then you can achieve $O\left(n\log(1+\frac{m}{n})\right)$ comparisons as follows:
Let $k_1$ denote the index of $a_1$ in the final array $c$ and for $1<i\leq n$ let $k_i$ denote the difference between the indices of $a_i$ and $a_{i-1}$ in the final array $c$.
T... |
@D.W. what if at each step, there is not a fixed finite number of choices, rather some $k$ choices. In that case, there would be $O(k^t)$ different control-flow paths. By properly tuning, $k$ and $t$ , we can get $t^t \geq n$ or $t \geq W(n)$. Here $k$ is [Lambert's W-function][1]. @D.W. I think a little more explanati... |
**1. Assignment problem.**
**2. Hungarian algorithm.**
Python code:
```python3
# pip install hungarian-algorithm
from hungarian_algorithm import algorithm
G = {
'John': {'Apple': 20, 'Pear': 10},
'Ethan': {'Apple': 20, 'Orange': 5},
'Michael': {'Pear': 10, 'Limon': 10},
}
print(algori... |
@D.W. what if at each step, there is not a fixed finite number of choices, rather some $k$ choices. In that case, there would be $O(k^t)$ different control-flow paths. By properly tuning, $k$ and $t$ , we can get $t^t \geq n$ or $t \geq W(n)$. Here $k$ is [Lambert's W-function][1]. @D.W. I think a little more explanati... |
|algorithms|optimization|assignment-problem| |
null |
I know that retrieving an item in a collection can be done in $O(1)$ time(on average) using hash tables. I would like to know if there is an algorithm that could be as performance without using arrays.
My main motivation for this question is to know if it is possible to build a retrieve element algorithm in $O(1)$ t... |
null |
**1. Assignment problem.**
**2. Hungarian algorithm.**
Python code:
~~~python
# pip install munkres
from typing import Dict, Union
from munkres import Munkres
G = {
'John': {'Apple': 20, 'Pear': 10},
'Ethan': {'Apple': 20, 'Orange': 5},
'Michael': {'Pear': 10, 'Limon': 10},
}
def... |
null |
null |
First, lets try to understand this scenario
We have three elements $i,j,k$
Their order of arriving at the stack is $j,i,k$ ($p_j<p_k<p_i$)
Their order of getting out of the stack is $i,j,k$ ($i<j<k$)
The answer argues that this scenario is impossible to happen, lets try to see why
---
consider element... |
First, lets try to understand this scenario
We have three elements $i,j,k$
Their order of arriving at the stack is $j,k,i$ ($p_j<p_k<p_i$)
Their order of getting out of the stack is $i,j,k$ ($i<j<k$)
The answer argues that this scenario is impossible to happen, lets try to see why
---
consider element... |
null |
The lower bound can be found as the minimum height of a binary tree holding $n$ leaves. A *complete tree* has this property and has a logarithmic height. |
This answer explains an algorithm that finds the minimum number of edges in $O(n\log n)$ time<!-- assuming $O(c)$ access time for an item in a HashMap(Java)/Dictionary(Python)/Map(C++)-->. With more bookkeeping, the path of weight $k$ with that minimum number of edges can also be found in $O(n\log n)$ time.
#### A B... |
I know that :
$T(n,k)=T(n−1,k−1)+T(n−1,k)$ is the Pascal triangle.
But what is this then:
$T(n,k)=T(n−1,k−1)+T(n,k-1)$
Is there any name for it? I am trying to learn about it's time complexity etc, but I can't find anything online.
|
What does the following recurrence formula represent |
|algorithms| |
null |
Let $G=(V,E)$ be a complete finite graph with the vertices arranged in a circle. Each edge has a nonnegative weight, and we would like to find an efficient algorithm to find a subgraph of maximum total weight, which is a triangulation of the graph. A triangulation of the graph is a subgraph such that no edges cross a... |
Subdivide a graph into non-crossing triangles with maximum edge weight |
|algorithms|weighted-graphs| |
null |
Show a reduction of max flow to min cost (not min cost max flow!!) |
Show a reduction of max flow to min cost |
With memoization, your approach by dynamic programming runs in $O(n^3)$ time, where $n=|V|$. That seems efficient enough considering there are $n(n-1)/2$ edges.
------
Assume $n\ge 3 $; otherwise it is easy to solve the problem.
Label the vertices be $v_0, v_1, \cdots, v_{n-1}$ clockwise. Let $v_n=v_0$.
Fo... |
|algorithms|time-complexity|dynamic-programming|weighted-graphs| |
With proper classification and memoization, an approach by dynamic programming runs in $O(n^3)$ time, where $n=|V|$. That seems efficient enough considering there are $n(n-1)/2$ edges.
------
Assume $n\ge 3 $; otherwise it is easy to solve the problem.
Label the vertices be $v_0, v_1, \cdots, v_{n-1}$ clockwis... |
With proper classification and memoization, an approach by dynamic programming runs in $O(n^3)$ time, where $n=|V|$. That seems efficient enough considering there are $n(n-1)/2$ edges.
------
Assume $n\ge 3 $; otherwise it is easy to solve the problem.
Label the vertices be $v_0, v_1, \cdots, v_{n-1}$ clockwis... |
null |
In an introductory course on Dijkstra's algorithm, I enunciated the following lemma :
> Let x →* z be a shortest path in a weighted graph and let y be any vertex along that path. It follows that x →* y and y →* z are shortest paths too.
To which one of my students pointed out that it does not seem to hold in the ... |
Subpath optimality lemma in weighted undirected graphs |
|shortest-path|weighted-graphs| |
You can reduce from vertex cover in cubic graphs since it is known to be $\textrm{NP}$-hard. Let $G=(V,E)$ be the graph in the instance of vertex cover and, for $v \in V$, call $E_v = \{ (v,u) \mid (v,u) \in E \}$ the set of edges incident to $v$ in $G$.
Fix $1 \le k \le |V|$ and construct an instance of the exact c... |
You can reduce from vertex cover in cubic graphs since it is known to be $\textrm{NP}$-hard. Let $G=(V,E)$ be the graph in the instance of vertex cover and, for $v \in V$, call $E_v = \{ (v,u) \mid (v,u) \in E \}$ the set of edges incident to $v$ in $G$.
Fix $1 \le k \le |V|$ and construct an instance of the exact c... |
In an introductory course on Dijkstra's algorithm, I enunciated the following lemma :
> Let x →* z be a shortest path in a weighted graph and let y be any vertex along that path. It follows that x →* y and y →* z are shortest paths too.
To which one of my students pointed out that it does not seem to hold in the ... |
The second recurrence is ALSO Pascal's Triangle (interchange n and k).
|
It is pretty simple to implement a DFS algorithm for a binary tree but what about BFS for binary trees? I tried to adapt the BFS algorithm for ordered tree, this is the result:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/37xVa.png
It's correct? Are there better solutions? |
Breadth-first search (BFS) for binary tree |
|binary-trees| |
I know that swapping is avoided in mobile systems because of limited memory but I came across this question and couldn't answer if the answer is yes.
Should swapping be done in Mobile systems? If yes, what should be the appropriate swap size in case the secondary storage is 16 times that of RAM. Which swapping locat... |
Swapping in mobile systems |
|operating-systems| |
null |
In an introductory course on Dijkstra's algorithm, I enunciated the following lemma :
> Let x →* z be a shortest path in a weighted graph and let y be any vertex along that path. It follows that x →* y and y →* z are shortest paths too.
To which one of my students pointed out that it does not seem to hold in the ... |
You actually have the idea here:
>... but to create the same contradiction to the lemma in a directed graph, we would need an edge A -> B and an edge B -> A both with weight -7, which would give a cycle of weight -14.
If you apply the implementation of Dijkstra's algorithm using your example, it will treat your g... |
You actually have the idea here:
>... but to create the same contradiction to the lemma in a directed graph, we would need an edge A -> B and an edge B -> A both with weight -7, which would give a cycle of weight -14.
If you apply the implementation of Dijkstra's algorithm using your example, it will treat your g... |
It is pretty simple to implement a DFS algorithm for a binary tree but what about BFS for binary trees? I tried to adapt the BFS algorithm for ordered tree, this is the result:
[![enter image description here][1]][1]
It's correct? Are there better solutions?
[1]: https://i.stack.imgur.com/5dlWE.png |
You actually have the idea here:
>... but to create the same contradiction to the lemma in a directed graph, we would need an edge A -> B and an edge B -> A both with weight -7, which would give a cycle of weight -14.
If you apply the implementation of Dijkstra's algorithm using an undirected graph, it will treat... |
Given three arrays A, B, and C of size n, m, and m respectively (1-based indexed). A function F(i) is defined as -
F(i) = minimum_of(⌈ Ai / B1 ⌉ * C1 , ⌈ Ai / B2 ⌉ * C2 , ⌈ Ai / B3 ⌉ * C3 , .... , ⌈ Ai / Bm ⌉ * Cm)
where ⌈x⌉ is defined as the ceiling function. For example : ⌈2.3⌉ = 3, ⌈3.9⌉ = 4 and ⌈3⌉ = 3.
Fi... |
Finding Sum(F(i)) where F(i) = min(⌈ Ai / B1 ⌉ * C1, ⌈ Ai / B2 ⌉ * C2, ⌈ Ai / B3 ⌉ * C3, .... ,⌈ Ai / Bm ⌉ * Cm) |
|algorithms|data-structures|discrete-mathematics|mathematical-programming| |
{"Voters":[{"Id":755,"DisplayName":"D.W."}],"SiteSpecificCloseReasonIds":[]} |
A simple mental model of a PDA or NPDA is **a finite state machine plus a stack**.
Both parts can be used to remember which kind has been the input taken by the automaton so far. The finite-state-machine part can remember bounded-many information. The stack can remember unbounded-many information (but for any parti... |
It is pretty simple to implement a DFS algorithm for a binary tree but what about BFS for binary trees? I tried to adapt the BFS algorithm for ordered tree, this is the result:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/5dlWE.png
I presume that better solutions are possible. Cou... |
null |
I have to design an NPDA(Non-Deterministic Push Down Automata) for all the strings over
$\{a, b \}^*$, which have equal numbers of $a$'s and $b$'s but do not end up with an $a$.
I know how we should create an NPDA for the strings with an equal number of $a$'s and $b$'s, which its machine would be like this:
[![e... |
NPDA which accepts all the strings of a's and b's that have equal number of a's and b's, but do not end up with an a |
The naive approach of checking every point in the rectangle would take $\Theta(wh)$ time, where $w$ is the width and $h$ is the height of the rectangle.
A moderate improvement on this is to scan every row (or column) of the rectangle and figure out where the circle starts and ends. Then, round up/down the circle end... |
You actually have the idea here:
>... but to create the same contradiction to the lemma in a directed graph, we would need an edge A -> B and an edge B -> A both with weight -7, which would give a cycle of weight -14.
If you apply the implementation of Dijkstra's algorithm to an undirected graph, it will treat th... |
*Max Flow to Min Cost conversion* |
Max Flow - Min Cost |
I am studying Communicating Sequential Processes (CSP), and I understand that an event can be "emmited" ($\overline{e}$) and an event can be "waited on" ($e$), so that an event will sync with another parallel event ($\overline{e} || a \rightarrow e$).
Now how do I represent the fact that an event *must* not occur at... |
How to represent mutually exclusive events in CSP |
|computation-models|parallel-computing| |
Show a reduction of max flow to min cost (not min cost max flow!!) |
Show a reduction of max flow to min cost |
null |
Given an undirected and unweighted graph $G = (V, E)$ and two of its vertices $s$ and $t$. My task is to find an algorithm that checks if there exists an edge belonging to $E$ such that its removal will result in the shortest path from $s$ to $t$ being extended (and if so returns this edge). We may remove only one edge... |
Is there an edge whose removal will extend the shortest path? - graph problem |
|algorithms|graphs|shortest-path| |
Hardware can be directly memory mapped as long as it obeys the logic voltage and current rules of the system and worked on live with an interpreted language such as FORTH. I have had new chips up and running in 15 minutes using a 68HC11 running FORTH and debug problems on wireless systems half a world away on the same ... |
It's been a few years since this question, but even at the time that the question was written, we don't. As several commenters point out, the overwhelming majority of CPUs that you can buy today use a [Harvard architecture][1], with separate instruction and data memory.
This is true from microcontrollers, which typi... |
I am studying B-trees and reading *Introduction to Algorithms* by Cormen et al.
Unfortunately, they have this diagram Figure 18.1 and they do not list the order of the tree.
[![enter image description here][1]][1]
I understand that for a B-tree of order $m$, the tree has 5 properties:
1. Every node has ... |
What order B-tree is this? |
|b-tree| |
I know the term **order** of a B-tree. Recently I heard a new term: **B tree with minimum degree of 2.**
We know that the degree is related to a node but what is the degree of a tree?
Does degree impose any kind of a restriction on the height of a B-tree? |
Are degree and order the same thing when referring to a B-Tree? |
|data-structures|terminology|search-trees|balanced-search-trees|b-tree| |
Good question.
You have given the answer. A B-tree of order $4$ can also be a B-tree of order $5$ or $6$. So, "the order" of a B-tree may not be unique. <!-- This situation is like people with double citizenship, someone who is a Canadian and also an American. -->
Knuth, who gave the definition of B-tree as in th... |
null |
|notation|b-tree| |
null |
### A Configuration just Means "State"
A configuration of a machine $M$ is a snapshot of the machine at a particular moment during a computational process by the machine. It includes all setting/details of the machine. It means, basically, the "state" of a machine, where "state" is in the usual sense of plain Englis... |
If the polygons are overlapping, you can't spare a union algorithm that will "merge" the overlaps. https://en.wikipedia.org/wiki/Boolean_operations_on_polygons. This involves the detection of intersections between the sides and a topological reorganization. Nothing really easy.
It is likely that an simpler technique... |
If the polygons are overlapping, you can't spare a union algorithm that will "merge" the overlaps. https://en.wikipedia.org/wiki/Boolean_operations_on_polygons. This involves the detection of intersections between the sides and a topological reorganization. Nothing really easy.
It is likely that an simpler technique... |
Given an undirected and unweighted graph $G = (V, E)$ and two of its vertices $s$ and $t$. My task is to find an algorithm that checks if there exists an edge belonging to $E$ such that its removal will result in the shortest path from $s$ to $t$ being extended (and if so returns this edge). We may remove only one edge... |
#### the Idea
Find all edges that are on one of the shortest paths from $s$ to $t$. Return the bridges in the graph that consists of those edges.
#### Implementation Algorithm
1. Use breadth-first-search to compute $d_s(u)$, the distance from $s$ to $u$ for each vertex $u$. If $t$ is found not reachable from $s$, ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.