instruction stringlengths 35 29.1k |
|---|
If a problem is NP-complete with respect to randomized (polynomial time) reductions, but not with respect to deterministic reductions, then we have P $\neq$ BPP (See Question 2 here and its answer).
Suppose a decision problem is proved to be NP-complete; and it is also proved to be DP-complete with respect to randomize... |
I know that when we want to find out if Vertex Cover of size $k$ when $k
\leq C$, belongs to P or not (when $C$ is some constant), we actually
can find algorithm with polynomial time complexity (in the algorithm we
iterate over subsets $V'$ such that $|V'|=C$). But what about $k \geq
C$?
I personally think it's not in... |
I have written an assembly program to store digits in a stack. And to print the digits I have used
loop2:
mov ah,2
int 21h
sub cl,1
jnz loop2
But this would only print them in reverse order as the SP is pointing to the last element,
Now, I have a very simple yet very interesting question, I was very curious to know
If... |
I need some help with the following question.
SHIP LOADING: Given items of weights $x_1,\dots,x_n$, ships of weight
capacity $B$, can the items be loaded onto $C$ or fewer ships? (All
numbers are positive integers, given in binary.)
Show that SHIP LOADING is NP-complete. (Hint: reduce from SUBSET SUM,
but go through a... |
Let A be a PTAS algorithm with time complexity $O\left(\frac{1}{\epsilon}\right)$.
Let $n$ be the input of the algorithm A.
From Wikipedia:
The running time of a PTAS is required to be polynomial in $n$ for every fixed $\epsilon$, but can be different for different $\epsilon$.
Can we define $\epsilon$ to be equal to ... |
Let's define a language $$C = \{ \{M_1, M_2\} \mid M_1, M_2 \text{ are TMs s.t. } L(M_1) \cap L(M_2) = \emptyset \}$$
We have to show that $C$ is unrecognizable.
I am having trouble going on about with this proof. I am trying to do this by reduction, showing that this language is unrecognizable, but I am unsure on how ... |
if we define $A_{TM}$ and $\overline{ A_{TM}}$ as follows:
$$
\begin{align}
A_{TM}&= \{ \langle M,w \rangle |M \text{ is a turing machine and $M$ accepts $w$} \}\\
\overline {A_{TM}}&= \{ \langle M,w \rangle |M \text{ is a turing machine and $M$ do not accepts $w$} \}\end{align}
$$
$\overline{A_{TM}}$ and $\Sigma^*\bac... |
I know that $L = \{a^lb^n c^m |l, n, m ∈ \mathcal{N}^+, (l ≥ n) ∨ (l ≥ m)\}$ is a context-free language, because I know the context-free grammar, i.e.
$$
S \rightarrow AbZ \mid XBc \\
A \rightarrow aAb \mid X \\
B \rightarrow aBc \mid Y \\
X \rightarrow aX \mid a \\
Y \rightarrow bY \mid b \\
Z \rightarrow cZ \mid c
$$... |
I am wondering what generic example there is so that an NFA with n states results into a DFA with $2^n$ states after the conversion by the subset construction. I know there is the example by Hopcroft et al. where the resulting DFA has $2^{n-1}$ states but I am looking for a result with exactly 2^n states.
Thanks in adv... |
Consider the the binary erasure channel, with input and output alphabet $\{0,?,1\}$ and channel matrix
\begin{bmatrix}
1-\lambda-\mu & \mu & \lambda\\
0 & 1 & 0\\
\lambda & \mu & 1-\lambda-\mu
\end{bmatrix}
I want to determine its capacity, i.e. maximize $I(X;Y)$ over the probabilities distribution of the input.
I have... |
I’m struggling to understand how $T(N)=C_1 \times N + C_2$ was derived
Assuming $C_1$ refers to l <- 0, and $C_2$ refers to return l
Shouldn’t it total $T(N)= C_1 + (N + 1) + N + C_2$, which simplifies to $T(N)= C_1 + 2N + 1 + C_2$ ?
|
Hey I'm trying to prove that the following Language is regular so far couldn't find a way, hope someone can help me $L^{\prime}=\{x \# y \mid x y \in L, y x \notin L\}$ where $L$ is regular.
|
I don't understand very well section 16.5 of the 3rd edition of the famous Introduction to Algorithms book, known as CLRS. It defines the problem of scheduling unit-time tasks with deadlines and penalties for a single processor with the following inputs:
a set $S = {a_{1}, a_{2}, ..., a_{n}}$ of $n$ unit-time tasks
a ... |
If deterministic context-free languages (DCFLs) are not closed under intersection, does this mean that the intersection of two DCFLs will always be context free but may not be deterministic? Or does it mean their intersection may not be context-free?
|
Say there is a set of m·N named elements. How to produce all the (unordered) combinations of N-sized subsets?
For example, m=2 and N=2, the elements are called A, B, C and D. There will be 3 combinations: AB+CD, AC+BD and AD+BC.
For m=2 and N=3 there will be 10 combinations. In general, it will be:
$$\frac{(mN)!}{(N!)^... |
In my work, I meet a process for DAG, and need to explain it in my report. So, I would like to know the name of the process.
The process is very simple. The vertices of degree two except roots and leaves are replaced to the new edge between the parent and child vertices.
This process is almost the same to what this li... |
In this article about the recent breakthough in Matrix Multiplication, it quotes Chris Umans's words:
Multiplications are everything. The exponent on the eventual running time is fully dependent only on the number of multiplications. The additions sort of disappear.
I was wondering how I should understand this. Why t... |
I am trying to prove the first assertion in the following code, taken from notes of Damon Wischik:
def dijkstra(g, s):
for v in g.vertices:
v.distance = ∞
s.distance = 0
toexplore = PriorityQueue([s], sortkey = lambda v: v.distance)
while not toexplore.isempty():
v = toexplore.popmin(... |
I was watch this lecture https://youtu.be/moPtwq_cVH8?t=2895, and at this point he says a lot about reductions, take a problem and reduce to another problem. From what I could understand this is a symmetric relation, if I can reduce A to B, then I can reduce B to A. This seems pretty intuitive to me but I don't have a ... |
Define the inversion of a binary tree as the tree whose left sub-tree is a mirror reflection of the original tree's right sub-tree around the center and right sub-tree a mirror reflection of the original tree's left sub-tree.
Examples:
Inversion 1 Inversion 2
C | C C | C
/ \ ... |
For two languages over the same alphabet, if neither of them is context-free, can their union still be context-free?
If not, does one of the languages need to be context-free for this to happen? Do both need to be context-free?
|
Please note that this question is different than this question.
The $k$-disjoint triangles problem is as follows:
Input: A graph $G=(V,E)$ and an integer $k\in \mathbb{N}$
Output: Are there $k$ vertex-disjoint triangles in $G$?
An FPT algorithm is presented here (starting from slide 60). The algorithm uses color-codi... |
The problem. Given an undirected, connected, edge-weighted graph $G=(V, E_G; w)$ and a minimum spanning tree (MST) $T=(V, E_T)$ of $G$, the MST sensitivity analysis problem asks to find, for each edge $f \in E_T$, the increase between the total weight $\sum_{e \in E_T} w(e)$ of $T$ and the total weight of a MST of $G-... |
Let's say I have :
a Graph g
v vertices. Each vertex is associated to a cost c.
A special vertex called the starter vertex or vs.
I want to find the path p of length 10 (for example), that start from vs and that maximize the sum of the 10 seens nodes costs. I need to tell you that my graph represent a road network wh... |
what do the tape contents of Turing machine look like after halting? Are there empty symbols after the qaccept or reject?
|
For two languages over the same alphabet that are not context-free, can their intersection be context-free, Or does at least one of them have to be context-free?
|
Wikipedia:
The existence of such one-way functions... would prove that the complexity classes P and NP are not equal.
How is this proved?
|
I'm supposed to write grammar for this language: $$L=\{a^{i+1}b^{i}c^{2j}d^je^{2j}\mid i,j>0\}$$
This is what I have so far:
$$\begin{align}
S &\to aXbY \; \\
X &\to aXb \;|\; a \\
Y &\to ccYdE \;|\; ccdE \\
Ed &\to dE \; \\
dE &\to dee \; \\
eE &\to eee \; \\
\end{align}$$
Edit:
Thank you for answers, I looked at the ... |
I need to prove or disprove the following claim:
Given that the best case complexity of the algorithm A is $O(f(n))$ and the worst case complexity of A is $Ω(g(n))$, it follows that $f(n) ∈ Ω(g(n))$.
I know that obviously $A_b \leq A_w$.
I can also conclude obviously that for constants $c_1 , c_2$ and for all $n_0 \l... |
Let's consider 128-bit LCG with modulus $2^n$ of the form:
$X_{n+1}=a \cdot X_{n} + c \mod 2^{128}$
How fast we can run it in cycles per byte? And how much of RAM it required?
|
I was reviewing for my CS class and came across this question and answer combo that didn't have any explanation why it was correct. I'm confused on how they got the answer:
We have a system to which we can instantaneously add and remove cores
-- adding more cores never leads to slowdown from things like false sharing,... |
I am beginning with my masters degree in mathematics and I will specialize in optimization theory. My minor is computer science and wanted to know which branch of computer science fits my specialization(optimization theory) the best.
I know that machine learning involves some optimization theory (I don't know how much ... |
Consider this algorithm iterating over $2$ arrays $(A$ and $B)$
size of $ A = n$
size of $ B = m$
Please note that $m \leq n$
The algorithm is as follows
for every value in A:
// code
for every value in B:
// code
The time complexity of this algorithm is $O(n+m)$
But given that $m$ is strictly lesser than or ... |
I was just wondering why are are new generation microprocessors faster at the same clock speed as the old ones.
For instance a 2.66Ghz dual core i5 is faster than the a device with clock speed of 2.66Ghz but core 2 dual.
|
Two undirected graphs $G$ and $H$ on the vertices $1,2,\ldots,n$ are disjoint if the intersection of
their edge sets is empty.
Assume both $G$ and $H$ are represented by adjacency matrices.
Describe an efficient
algorithm that decides if $G$ and $H$ are disjoint. What is the complexity of your algorithm?
J... |
This is the pseudocode I used:
Their calculation seems to be different from mine. Can someone explain how they derived it? Here is mine in comparison:
Line 1: $c_1 \cdot (n-1)$
Line 2: $c_2 \cdot (n-1)$
Line 3: $c_3 \cdot n $
Lines 5-6: $c_4 \cdot \frac{n(n-1)}{2}$ (the if statement executes with an arithmetic progre... |
I have a model counting program bob. On some graph coloring formulas, bob got the right answer only after removing clause learning. That is to say, with clause learning, bob sometimes counts duplicate solutions, while satisfiability remains stable. This would be big news if true.
|
In type theory, all computable functions must terminate, however, numbers like Pi are non-terminating real numbers, hence a non-terminating function is required to compute this number, even though one would never compute the full sequence.
How does type theory view/deal with such non-terminating numbers/object?
|
I have an instance linear programming such that the coefficients and the constant terms are 0 or 1.
Formally, the set of variables is denoted as $V$ and $|V| = n$. There are $m$ constraints, formed as
$$ \mathbf{a}_{1}^{\top} \mathbf{v} \leq 1 $$
or
$$ \mathbf{a}_{2}^{\top} \mathbf{v} \geq 1 $$
where $\mathbf{a}_{1}, \... |
Leslie Lamport claims that TLA+ is too complex to be described in BNF.
Does that mean TLA+ is not a context free language?
What is the relationship between the set of context free languages and the set of languages that can be described by BNF grammars?
|
I meet a problem but when I google, there are all Hamiltonian Path Problem: How to find a path to visit every node in directed graph(not necessarily once)?
This problem is different from Hamiltonian Path.
For example:
1 --> 2 --> 3 ↔ 4
↕
5
I have a path $1\rightarrow 2\rightarrow3\rightarr... |
I was going through the text Computer Networking- A Top-Down Approach by Kurose and Ross, there I found subtleties with the TCP congestion control FSM which is shown below:
Mainly I am having difficulty in understanding the action transmit new segment(s), as allowed and transition to the Fast Recovery state.
I have ... |
The Problem:
Say that a language is prefix-closed if all prefixes of every string
in the language are also in the language. Let C be an infinite,
prefix-closed, context-free language. Show that C contains an infinite
regular subset.
Can we show this by using Myhill-Nerode Theorem?
|
Given a regular language $L$ over the alphabet $\Sigma = \{a,b,c,d\}$, is the language $\mathrm{Perm}(L)$ consisting of all permutations of words in $L$ also regular?
My intuition says it is, since each word in $L$ only has finitely many permutations, but I don't know how to prove it.
Any help would be great.
|
I need to construct a TM that converts a number from binary notation to unary and calculate time complexity.
I have done the first part.
The idea is as follows:
binary number is decremented by 1 until it reaches 0. At each
decrement an additional 1 is written on the left side.
e.g.
111 -> 1111111
111x (TM goes to t... |
Remove any 5 elements from a sorted array of n items and replace them with 5 new elements.
Why does running Insertion sort again on this array take linear O(n) time, I tried counting the number of swaps when running Insertion sort again, and noticed every element is shifted by at most 5 places(not sure why), I cannot g... |
I think the empty language is NP but I'm not sure if it is NP-Complete
|
I am studying Crafting Interpreters, and although I understand the responsibility of the Scanner (or Lexer), I still cannot understand if it is a deterministic finite automaton or non-deterministic finite automaton. The code responsible for scanning the input text in the book is:
private void scanToken() {
... |
My question is about the paper Three is Better than One Ensembling Math Information Retrieval Systems (a system used for math information retrieval - both for finding answers and formula search)(code on github).
Before the questions, the following figures illustrates:
CompuBERT (taken from Three is Better than One Ense... |
I am trying to prove the following claim:
Given DAG graph, there is Hamilton path iff the following algorithm
returns true:
Do topologic sorting.
Move on the graph's vertices one by one (from low to high). In case there is no edge connecting 2 vertices with adjacent values from the topologic sorting then return fals... |
Working with a question that states:
Consider a hypothetical machine in which physical address space is
of 512 words and virtual address space is of 2048 words. The page
size is 8 words. What is number of bits used for: Page offset,
Physical Page Number, Virtual Page Number
Since my course uses MIPS, I'm assuming the... |
I'm a bit confused by Wikipedia's tables of algorithms for the shortest path problem.
For an unweighted graph with $E$ edges and $V$ vertices, it gives the best algorithm as breadth-first search, with a time complexity of $O(V+E)$. But above that, for an undirected graph with natural-number weights, it gives the best a... |
I'm working on Algorithm Design (Kleinberg-Tardos) Chapter 1 exercise 7:
Some of your friends are working for CluNet, a builder of large
communication networks, and they are looking at algorithms for
switching in a particular type of input/output crossbar. Here is the
setup. There are n input wires and n output wires,... |
I'm trying to understand how the construction of simple grammars works.
In my textbook, there's the following example I am supposed to find a grammar for:
Let $L_1= \{a^n b^n c^m d^m \mid n \geq 1, m \geq 0\}$ be a language over the alphabet $\Sigma = \{a,b,c,d\}$. Find a grammar $G = (\Sigma, N, S, P)$ - where $N$ de... |
I've got a question about how best to classify the performance of an approximate algorithm. I'm trying to find the 'correct' value of a graph problem instance whose cost function has an objective function and a penalty function. I've configured my method such that the optimum solution of the problem has the highest val... |
Condidering the proof, NLOGSPACE$\subset$PSPACE
I wrote following proof:
NLOGSPACE = NSPACE$(\log n)$ $\hspace{15pt} \because$ Definition of NLOGSPACE
NSPACE$(\log n)$ $\subseteq$ DSPACE$(\log^2 n)$ $\hspace{15pt} \because$ Theorem(1)
We let $m = \log n$, then,
DSPACE$(m^2)$ $\subset$PSPACE $\hspace{15pt} \because$ Def... |
Consider the language
$$L = \{w \mid w \text{ has an unequal number of a’s and b’s}\}$$
where Σ = {a, b}.
Prove that L is not regular.
Hint: Try proof by contradiction.
Would this be the right Answer:
L = {a^m b^n | m < n} U {a^m b^n | m > n}
Looking at this we can tell that a is more than b or a is less than b. They d... |
I am thinking about how to break an array into k parts using DP with the following requirement.
Array A of size n divided into k parts
All elements are positive integers and order is fixed.
The maximum difference between the sum of elements in 2 groups is minimized.
You may think of a scenario: there is a book with... |
This question is distilled from an interview question.
Given two arrays $a$ and $b$ containing $n$ integers each, change each integer in array $a$ into the corresponding integer in array $b$ by increasing or decreasing a single digit by $1$. What is the optimum algorithm?
The number of digits in $a[i]$ are the same as ... |
Given an array $arr$, element $arr[i]$ indicates its parent. If the element has no parent then $arr[i]=-1$. What is the optimal algorithm for finding the minimum number of groups such that no element in each group is a child node (whether directly or indirectly) of any other node in the same group.
|
While reading graph theory, I came across different definitions where they use partitions and divisions, I was wondering, are these terms same or different?
Can anyone explain me their difference in Set Theory?
I know this is a simple question but anyone hardly talk about it but they always make here a mistake.
|
I have two sets, let's call them C and T, of unpaired points, which could for example represent two types of cells. Hence, both points are drawn from the same underlying distribution, but the points in T underwent an additional process/function.
Although biologically debatable, I want to find the most similar points in... |
This problem is from Sipser's Theory of Computation 3rd Edition.
1.35 Prove that $A/B = \{\omega \ | \ \omega x \in A \ \mathrm{for\ some \ } x\in B\}$ is regular where $A$ is regular and $B$ is any language.
I want to verify that my proof is correct. It is as follows:
Let $A$ be a regular language. Then it has a DF... |
Given admissible heuristics f(s), g(s), h(s).
It is true that max(f(s), g(s), h(s)) is still admissible.. but is it still admissible if its max(f(s), g(s) + h(s)). I believe it is not admissible but I just want to make sure.
|
If $K$ is a context-free language, then $K$ is a decidable language.
$\text{Acc}_{\text{CFL}} = \{〈G, w〉: G \text{ is a context-free grammar and G can generate } w\}$ is decidable.
I am a bit confused. For me, showing that $K$ is dedicable is equivalent show that $Acc_{GNC}$ is decidable. Where am I wrong?
|
I'm trying to solve this the recurrence :
$$
T(n)=\begin{cases}
1, & \text{ if } n = 1 \\
T(n-1) +n(n-1), & \text{ if } n \geq 2
\end{cases}
$$
|
Is it true that $ 2^{O(3k)} = 2^{O(k)} $?
But It should be different from $ O(2^{k}) = 2^{O(k)} $ ?
I will be happy for simple explanation.
Thanks.
|
It seems that $ \text{NV}_{\text{TM}} = \{〈N〉: N \text{ a Turing-Machine and } L(N) ≠ ∅\}$ is not decidable.
Here is a proof:
Suppose that $\text{NV}_{\text{TM}}$ is decidable with the
Turing-Machine $R$.
We can define for each Turing-Machine $M$ and each entry $w$ a
Turing-Machine $S_{M,w}$ as follow:
$S_{M,w} :=$
I... |
Problem:
Let $X=\{x_1, ..., x_N \}$ be a set of binary variables. Each variable can be assigned to either $0$ or $1$ so there are $2^N$ possible assignments.
Input: We are given a positive integer $C$ and a set of binary functions $F=\{f_1,...,f_M\}$ where each function is defined as a simple conjunction of some subset... |
Here’s the decision problem:
Suppose I have N positive integers encoded in base-2 (as oppose to unary)
Are these integers precisely the integers 1-N in some order?
This is related to the Hamiltonian path problem which is NP-complete
Given a graph with N vertices you can nondeterministically walk a path of length N
If y... |
When it times to decide the decidability or undecidability, sometimes I see that we can simulate a Turing-Machine on another Turing-Machine. I heard it is related to Universal Turing-Machine. Can you explain what it means that we can simulates a TM on another Turing-Machine? For me, if I have a deterministic automata $... |
I found a task where you need to transform context free grammar to normal form.
I'm a High Shcool student at this moment. But my Brother learning this at the university. He don't have much time to explan this, this is why I'm writting this question.
This is the task description: A chainless G grammar equivalent to G' g... |
So I have been going over Turing machines for my revision and came across an old worksheet with the question:
Derive a Turing Machine using high level description with stages to decide on the following language {<,>| }.
I thought I understood Turing machines and CNF until I came across this but I can't figu... |
I can't understand this theorem:
If both L and L complement are turing-recognized, both are turing-decidable
Proof:
w is M input
if w ∈ L then M1 accepts w and M accepts w
if w ∉ L then M2 accepts w and M rejects w
M is a TM containing M1 and M2.
|
How can we show that the language $K = \{<M>: M \text{ is a finite automata and L(M) contains a word of form } a^ib^j\}$ is decidable?
|
I'm working on a proof for following question
$L=\{(R,S)\mid \text{R,S are regular expressions and } L(R)\subset L(S)\}$. Show that this language is/isn't decidable.
A language is decidable iff we have a Turing machine that halts for all input strings. If $L$ is regular, we can construct a DFA and therefore a Turing ... |
I am confused. I know that compilers translate your code one time as a whole into intermediary code, but how come when I type in something improper, the IDE shoots out a compilation error immediately? What am I not understanding? I thought the whole difference between an interpreter and a compiler is that the former tr... |
I just thought this up while walking after typing up a knapsack with repetition implementation in Python.
I want to teach computer science so I talk to myself a lot pretending to talk to students.
So in my imaginary lecture for merge sort, I used the example of an unshuffled deck of cards.
But then it hit me that, "Wit... |
I want to construct a PDA for $Σ^* -\{(a^nb) ^n, n>0\}$ where $Σ=\{a, b\}$. Here is my try:
I know that context-free languages are closed under union operation. Also I know how to make a PDA for union. So I tried to decompose the given language to some parts. For example, the language of the strings starting by $b$, th... |
I need to find a sorting algorithm to sort an array where the the $k$-th element appears $2^{k-1}$ times in $O(2^k)$.
It also given there are $k$ distinct elements in the array, hence there are $1 + 2 + 2^2 + \dots + 2^{k-1}=2^k-1$ elements in the array. So I actually need to sort the array in $O(n)$ where $n$ is the a... |
I will set this question in a very practical way. Let's say we have a web-form data received as JSON at the backend together with the schema (for instance, some version of JSON schema), something like: {"data": {...}, "schema": {...}}. An important thing is, that backend can validate the data according to the type defi... |
Consider the following language:
$$L=\{a^nb^n | n \ge 1\}$$
I constructed the following Turing Machine:
\begin{eqnarray}
T &=& (Q, \Sigma, \Gamma, \delta, q_0, B, F) \nonumber \\
Q &=& \{q_0, q_1, q_2, q_3, q_4\} \nonumber \\
\Sigma &=& \{a, b\} \nonumber \\
\Gamma &=& \{a, b, X, Y, B\} \nonumber \\
F &=& \{q_4\} \nonu... |
This question states that the problem of Hyper-graph Isomorphism is equivalent to Graph isomorphism. I have not been able to find a description of the reduction so I am wondering how that might work and what is its complexity. If I understand the post in the link correctly, the reduction has to be polynomial in order f... |
I have just proved that for every $\alpha, \beta>0 : (\log n)^\alpha=O(n^\beta)$.
Now, given an array of $n$ elements, I want to find an efficient comparison based algorithm for finding the $\log n$ largest elements in the array, and returning them in sorted order.
I will appreciate your help on what is the best way to... |
In Formal Grammars course we have a task to implement an extended NPDA (a pushdown automata where taking any amount of symbols from the stack is allowed (including ε) and it can be in several configurations at the same time) in any programming language. It can be one that accepts with a state or an empty stack.
I have ... |
I would like to understand what role does Transactional memory plays in memory organization, I know that To allow for more efficient parallel programming with higher performance, processor implements a hardware transactional memory facility.
But I would like to know what the processor do for memory management when ther... |
Many problems that take a boolean circuit as input are NP hard to compute. Do we have examples of such problems that become polynomial time computable when only boolean formulas are allowed as input?
In boolean circuit complexity, a circuit is just defined by a Directed Acyclic Graphs with designated input and output ... |
I am having difficulty understanding the difference between PAC and Oracle Machines. I cannot compare these two in terms of uncertainty and physical effort.
The degree of uncertainty we can tolerate in a system has been discussed ever since Turing. His oracle machines
answer questions with maximal uncertainty, and zer... |
Let $\Sigma_1 , \Sigma_2$ be alphabets. Let $L\subseteq \Sigma_1^*$ be a regular language, and let $ h:\Sigma_1^* \rightarrow \Sigma_2^* $ be a homomorphism.
Proof $h(L)$ is regular.
I have written a proof using induction over the number of operands in the regular expression $r$ such that $L = L(r)$, that there exists ... |
Prove or disprove or this statement:
The union of an infinite number of regular languages is regular.
Can someone help?
|
On one of my previous courseworks, I was faced with the following problem, which I think is unrealistic when using a direct / straightforward approach that usually algorithms have by leveraging certain data structures like dictionaries, etc.
Design an O(log n) algorithm whose input is a sorted list A. The algorithm
sh... |
What is the time complexity and space complexity of working out, in suitably generalised versions of the battle systems of both Paper Mario 64 and Paper Mario: The Thousand Year Door:
The minimum number of turns that Mario can win in
The minimum number of turns that Mario can guarantee a win in
Of course, we could al... |
How can we prove that in binary search
$$\mathit{low} - \mathit{high} ≤ 1$$
Below is a sample algorithm for Binary Search.
while (low<=high) {
int mid = low + (high-low)/2;
if (data[mid]<value) low = mid+1;
else if (data[mid]>value) high = mid-1;
else return &data[mid];
}
return nullptr;
A good stranger... |
I'm a bit confused about the scale of heuristics for implementing A* search. $f(n)$ is the total cost of travelling to a node $n$. It is calculated by $f(n) = g(n) + h(n)$. $g(n)$ is the cost of the path to node $n$ from the source node. $h(n)$ is a heuristic function that estimates the cost of the cheapest path from n... |
Prove that the following language is not a regular language:
$L = \{ 0^x1^y | x, y \geq 1\text{ and } x \geq y\vee (x < y \wedge y \mod x = 0)\}$
Is there anyone to prove this ?
|
Let $a,b>0$. Prove
$\left(\log\left(n\right)\right)^{a}=O\left(n^{b}\right)$.
I'm supposed to find an algorithm to find the log(n) largest elements in an array and return them sorted and explain why it's bounded by $O(n^{b})$, but the thing is I'm having trouble proving the above and I'm kind of stuck.. Any tips?
|
Given a directed graph $G = (V, E)$ and a vertex $v \in V$, how to find all vertices $v'$ such that exists a simple cycle $v \to ... \to v' \to ... \to v$? That is, to find the set of vertices $$V' = \{v' : \exists c, \text{c is a simple cycle in G}, v \in c, v' \in c \}$$
I found this question related: Find all cycles... |
I am studying Kruskal's algorithm. Is the only acceptable sorting criteria to sort edges from lowest weighted edge to greatest weighted edge? I ask this because I assume that if the algorithm used an alternative sorting criteria say, greatest to lowest, then it would not produce a MST. My reasoning is that edges with l... |
For any computable-function, there may be multiple different algorithms (possibly countably infinite). For example, sort has many different implementations/algorithms, that we know of or that we have found so far. They all produce the same output for the same input.
Given any specific computable-function or even a spec... |
I was asked to find write a pseudocode of an algorithm that extracts the Log(N) largest elements in an array and return them in a sorted list, my attempt is
largestLogn(Arr)
n = Arr.length
j = 0
ans = new array of size Log(n)
Arr = Quicksort(Arr,1,a)
for i=(a-log(n)) ➜ a
ans[j] = Arr[i]
j++
return ans
From my limi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.