instruction
stringlengths
35
29.1k
The problem is to find the shortest distance in a weighted graph, where the weight of each edge is non-negative and it is given that the weight of each edge is less than a constant C. For example, C = 500. I know that I can solve this problem using Dijkstra, however, the time complexity would be high. The problem shoul...
As the question suggest. I want an algorithm that runs in linear time which finds the longest prefix of a substring that is a sub-prefix of the same string. Formally: Given a string $S$ of length $n$, we define a function $\delta_{S}:$ $[n]\rightarrow[n]$ as follows. For each integer $w$, $1\le w\le n$, $\delta$ is de...
What are some recent breakthroughs in computer science? I am especially interested in research which have received inadequate attention or attains significant improvements over previous approaches.
How do manufacturers lock their devices to run only software by them? And how is it possible at all? For example: upgradeable toothbrush, mobile device, smart watch
I want to know if there exist a algorithm to efficiently compute the number of odd vertex in an undirected graph? A graph vertex in a graph is said to be an odd vertex if its vertex degree is odd, degree of a graph vertex v of a graph G is the number of graph edges which touch vertex v. This post conclusion seems to be...
I am new to reinforcement learning, and recently came across the following issue. When implementing a multi-armed bandit algorithm, we assume we have k machines with reward probabilities [p_1,..., p_k] which we try to approximate. While these probabilities are clearly unknown to the player himself, they must still be e...
if L is CF does that mean L interaction L reverse is also CF? thats the whole question since CF is clsoed for reverse it makes sense but there are alot of refute out there for interactions, so I was wondering how can i prove it ?
We have $c$ arrays of positive integers, named $j[1],j[2],j[3]..,j[c]$. We know that the length of $j[i]$ is $c-i+1$. In addition, the sum of the numbers of $j[i]$ is greater than or equal to the sum of numbers of $j[y]$ if $i \leq y$. Moreover, we have $k$ tuples, each with a length of at most $c$. If we use a tuple $...
Let $\ast$ stand for "type" and $\square$ stand for "kind" so that $\ast:\square$. Suppose I want to find an inhabitant of $\Pi x: A.\Pi y:B(x). \ast$. The derivation rules are given here. Intuitively, as far as I understand, this inhabitant should have the form $\lambda x:A.\lambda y:B(x). P(x,y)$ for some $P: A\to B(...
Some devices (for example Android devices) are "locked", the bootloader checks following bootloader/software sign, right? Chain of trust. Signing technically means that the file must be encrypt with one (private) key and decrypted with another (public) key. The software is compiled to executable binary and if we then s...
Aho-Corasick can result in a quadratic number of matches because it finds all occurrences of each searched-for substring. What is a faster algorithm or modification to this one to simply determine if there is any occurrence for each of the substrings?
To my knowledge a Turing machine is able to compute anything considered computable. I got the definition of Turing completeness from this answer Explain the difference between Turing Complete and Turing Equivalence If so, how can one achieve Turing completeness? Why is the Turing machine (a machine that can compute any...
While I know that every edge is fully saturated in every min-cut of a network flow, I'm trying to get some intuition when the converse is true. I can find an example using edges with infinite capacity, but is there any way to generalize this idea? Are there graphs where every saturated edge is part of some min-cut? EDI...
When adding two 2D matrices of the same size (in row major format), in sequential code with no vector operations, is it faster to add them column by column or row by row? At first I thought it would be faster to add them row by row, but now I'm thinking it would be faster to add them column by column. If you have the f...
My textbook claims the worst-case running time of Shellsort with Shell's increments is $Ω(N^2)$, but this analysis is done when $N = 2^m$ for a positive integer $m$. I see why the proof would work for those cases of $N$. The reasoning for the proof does not appear to, in general, hold for arbitrary $N$. However, the de...
Given the challenge of proving algorithmic bounds on the likes of 3-SAT to resolve P versus NP, I wondered whether it might be possible to use undecidability within an NP problem to ensure that we can never find any algorithm as an alternative to brute force. I couldn't find any references on this type of idea. After p...
There's a question I've long had about reversible computing: do non-trivial algorithms usually end up generating strongly pseudorandom data as an artifact of the computation? The most straightforward example of this would be if you used Fredkin gates or equivalent to wire together a binary multiplier circuit. My unders...
The path-convergence criterion states that there should be a φ-function for variable a at node z of the flow graph exactly when all of the following are true: There is a block x containing a definition of a, There is a block y (y $\neq$ x) containing a definition of a, There is a nonempty path $P_{xz}$ of edges from x...
Recently, I am reading paper An Upper Bound for Resolution Size: Characterization of Tractable SAT Instances, which use tree decomposition to give an upper bound for SAT resolution refutation. For a given nice tree decomposition $T=(V(T),G(T))$. My question: Why $O(3^{treewidth})*V(T)$ is still $O(3^{treewidth})$ my qu...
I'd like to know if there's a reduction $\mathsf{ALL}_{\mathsf{TM}}\leq_{m}\overline{\mathsf{ALL}_{\mathsf{TM}}}$ where of course $\mathsf{ALL}_{\mathsf{TM}}=\left\{ \left\langle M\right\rangle \mid\mathsf{L}\left(M\right)=\Sigma^{*}\right\} $ All attempts I've tried failed - if for example I try to define the reductio...
I have a language $L$ which is NP-hard and I have another language $L_1$, s.t. if I take an instance $q$ of the decision problem corresponding to $L$, and if one of polynomially many instances, $f_1(q),\ldots,f_{p(|q|)}(q)$ is in $L_1$, then $q\in L$. Is this enough to say that $L_1$ is NP-hard?
I hope someone can help me with that: $$T(n)=T(2^{\sqrt{\log n}})+1$$ I will be asked to answer what is the runtime complexity of the algorithm. I tried to set m=2^ and still failed.
for a language $L$ we define $rev\left(L\right)=\left\{ \sigma_{n}\cdot\ldots\cdot\sigma_{1}\mid w=\sigma_{1}\cdot\ldots\cdot\sigma_{n}\in L\right\} $. My question is, are $\mathsf{L,NL}$ closed under this operation? Meaning, for example, that if $L\in\mathsf{L}$ is $rev(L)\in\mathsf{L}$? I think the answer is yes if w...
We know that the K-median problem is proved to be NP-Hard. In fault-tolerant K-median problem on an undirected graph $G=(V, E)$: We are given a set of facilities $F\subseteq V$ and a set of demands (or clients) $D\subset V$ in a metric space. We can open at most $k$ facilities and then assign each client $j$ to the $r...
subject: pairing numbers and intervals Let NUMBERS be a list of n integer numbers. The numbers are listed in no specific order. Duplicates are possible. Let INTERVALS be a list of m intervals. The low and high limits of the intervals are integer numbers. The intervals are listed in no specific order. Duplicates are pos...
Main Problem Given an array $A[1...n]$ ($n \geq 3$) of distinct integers with at least a local minimum, output a local minimum. A local minimum is an integer $1 < i < n$ such that $A[i-1] > A[i] < A[i+1]$. Find an $O(\log n)$ algorithm or prove such an algorithm doesn't exist Notes It could be useful to have an $O(1)$ ...
I'd like to decide whether, given a connected graph $G = (V, E)$ and an integer $k$ as input, $G$ admits two vertex-disjoint subgraphs $T_1 = (V_1, E_1)$ and $T_2 = (V_2, E_2)$ such that $T_1$ and $T_2$ are trees, $V_1 \cup V_2 = V$ (so in some way they are spanning), and $|V_1 - V_2| \leq k$ (they aren't too different...
We are learning of the Ford-Fulkerson Algorithm for max-flow/min-cut, and I have been wondering of the following question: How do we exactly find which nodes are on the "sink" side of the min-cut produced using the algorithm? I have read here https://www.geeksforgeeks.org/minimum-cut-in-a-directed-graph/ that all node...
I was playing around with https://visualgo.net/en/maxflow when I realized a pattern: Take this graph, for example. We notice that the min-cut divides the graph into two sets of nodes: {0, 2, 3, 6} and {1, 4, 5, 7}. I noticed that choosing any node within {0, 2, 3, 6} as a source and {1, 4, 5, 7} as a sink, or vice ver...
What is the definition of the term "small systems" in the context of computer science? My professor didn't really define the term, they just gave examples of some small systems. I'm having a hard time finding a concrete definition of the term online. This is not a homework question. I just want to know the definition s...
Suppose I'm given a set $S$ and antichain $A \subset 2^S$ ($\forall a_1,a_2\in A: a_1\neq a_2 \iff a_1 \nsubseteq a_2$). Let's call subset $b \in 2^S$ covered by $A$ if $\exists a \in A :b \subseteq a $. I'm looking for a way to answer "What part/what percentage of $2^S$ is covered by $A$?" Due to $|S|>100$, it's infea...
Suppose there is an array $A[1..n]$.$A$ contains a permutation of $\{1,2,3,\dots,n\}$. We run the following algorithm $m$ times to sort $A$: for each odd index of $A$ from left to right ,respectively, put $A[i]$ be the minimum of its and right adjacent (if exists). Also we store index of larger number for $A[i]$. fo...
I have been trying to find a a CFG for this language generated. I came to the conclusion that I need three parts When $i \le j$ When $j < 2j < i$ When $j < i < 2j$ I was able to come up the production rules for 1 and 2 but I'm getting stuck at 3. I thought I found a solution in Context Free Grammar for $\{a^ib^j | i,...
Summary Recently I have had a path-finding puzzle that has some complex constraints (currently, I don't have any solution for this one) A 2D matrix represented the graph. The length of a path is the number of traversed cells. One or more number sequences are to be found inside the matrix. Each sequence is scored with ...
I Hope someone Can help me with that: $T(1)=2$ $T(n)=\left(T(\frac{n}{2})\right)^2\cdot2^n $ what is the runtime complexity of the algorithm (base 2) Thanks a Lot!
This is more for my curiosity than anything else as I understand how to find the two's complement of a binary number via the standard approach which is to convert all 0s to 1s and 1s to 0s and then add $1_2$, but this "quick method" truly puzzles me. I see that the author of the book I am going through suggests that th...
I understand the complexity of the issue in the event that P = NP: in this case, we couldn't prove it "by example" - it's simply impossible to sort through all possible tasks. The proof that, for all NP-complete problems, checking a solution is not easier than finding it, apparently, should be very non-trivial. However...
I am reading Michael Sipser's book Introduction to the Theory of Computation and in the section 2.4(chapter 2 and DCFLs section) there is a proof for the lemma that says "Every DPDA has an equivalent DPDA that always reads the entire input string."(lemma 2.41, page 132 in the 3rd edition of the book). I have read this ...
I am trying to prove that the following statements are true: * The average time complexity of the quick sort is O(n log2 n). 
 * The average time complexity of the randomized quick sort is Θ(n log2 n). 
 * The worst case time complexity of the quick sort is Θ(n^2). 
 * The worst case time complexity of the randomized q...
I want to prove that, $$\sum_{i=0}^{h}{2^i\times(h-i)} \sim O(2^h).$$ I did come up with the below proof, $$\sum_{i=0}^{h}{2^i\times(h-i)} \sim O(\sum_{i=0}^{h-1}2^{h-1}) \sim O(h2^h),$$ but as it is clear I did not find the correct path for my proof.
I know that if $P=NP$ then all of the languages in $NP$ are $NP-Complete$, but what about those in $P$? I assume yes, because $P \subseteq NP$, but I just want to check. Thanks!
Consider the following exercise from chapter Dynamic Programming in the book Algorithms by Jeff Erickson. Let $D[1 .. n]$ be an array of digits, each an integer between $0$ and $9$. A digital subsequence of $D$ is a sequence of positive integers composed in the usual way from disjoint substrings of $D$. For example, $...
Let $G$ be an undirected graph with an infinite number of vertices (and edges), and assume it is connected in the sense every $u,v$ have at least one path connecting them. Assume each vertex has a finite degree. My question is: Is it possible for a pair of vertices to exist, such that they will have an infinite number ...
I know that $A_{TM}=\{<M,w>|M~is~a~TM~and~M~accepts~w\}$ is NP-Hard: By showing a polynomial time reduction - $A \le_p A_{TM}$: Let $A \in NP$, then there exists a $NTM$ that decides $A$ in polynomial time, thus there exists a $DTM$ $M_A$ that decides $A$ in exp time. Then $f(w)=<M_A,w>$ is the reduction, so $A_{TM}$ ...
I'm reading this book, and there's something basic that I don't exactly get. The authors say that every common noun is declared to be a type. For example, $Human:Type$. Then, they give an example of semantics of an intransitive verb, which is $talk: Human \to Prop$, where $Prop$ is "the internal totality of all logical...
I was recently playing around in Python, and I wrote a program to check if a given number is prime. It works by checking to see if its divisible by each number other than 1 leading up to itself. It works well for small numbers but for very large numbers it takes a very very long time. I was wondering if there are progr...
I need help in finding a more performant algorithm. I have two timelines in the form of two indexed lists where each element is a floating-point value that represents seconds. The values in each list are only growing with higher indices. Each list has about 2000 elements. From every timeline, I take two indices and thu...
I have thousands of short arrays (length less than 9) holding integers. These numbers can be identical with high probability (in many arrays there are two triples of equal numbers). I need to remove the duplicates in each array, as efficiently as possible. An obvious solution is to sort using a fast sort (such as strai...
I'm trying to find an algorithm to update minimal top-down tree automata/hypergraphs. Regular tree grammars can be seen as definitions for recursive data structures: List -> cons(Bool, List) | nil() Bool -> true() | false() By minimal I mean that distinct nodes should generate distinct term languages. Intuitively thi...
Let $\begin{bmatrix}0\\ 0\end{bmatrix}$ be a two-column vector with $0$ in the first row and $0$ in the second row. Let $\Sigma_2 = \left\{ \begin{bmatrix}0\\ 0\end{bmatrix}, \begin{bmatrix}0\\ 1\end{bmatrix}, \begin{bmatrix}1\\ 0\end{bmatrix}, \begin{bmatrix}1\\ 1\end{bmatrix}\right\}$ be the set of all 2-element colu...
Before an exam in Computability I go through questions from last year's test. So the question is: $$A= \{ \langle M\rangle x | M \text{ is a TM and accepts } x \}$$ $$ L = \{ \langle M \rangle | M \text{ is a TM and halts only on words starting with 101 } \} $$ Prove by reduction that $L$ is undecidable. So this should...
Assuming unbounded memory, it seems many data structures can contain an arbitrary finite number of members. However, how they store data differs. In particular, it seems useful to represent the said "how" by an ordinal. For examples: The list data structure is represented by the fixpoint of $O = 1 + O$, which is $\ome...
I know that if there is a Turing Reduction from $A$ to $B$, say $A \le_T B$, and $B \in R$ then $A \in R$. I also know that Turing Reduction is for Decision, and not Recognition. Is it possible to design a new type of reduction, such that if $B \in RE$ then $A \in RE$ ? Thank you!
Given the following code: int f3(int n) { if(n <= 2) return 1; f3(1 + f3(n-2)); return n - 1; } I was trying to find the time complexity and I got this expression: $T(n)=1+T(T(n-2))$ which I've never seen before. I know the answer is $O(2^{\frac{n}{2}})$ but I have no idea how to get there. Can anyone explain...
I am working on designing a DFA with the language $a^i b^j c^k$ such that $i + j + k$ is odd I thought along the following lines: $i+j+k$ is odd $\Rightarrow$ two of them are even and one is odd or all of them are odd. But designing a DFA like this will lead to a complex and big DFA. I am not sure if there is a simpler...
I am interested in the following problem Input: A boolean function F with n boolean inputs and m boolean outputs. Output: A circuit C implementing F such that C has as few gates as possible. The function F could either be given as a boolean truth table, or more likely, another circuit D. I realize that this is a prot...
I know that a computer can be mechanical, screws/nuts or even water/pipes. Of course, it would be slow and big, but it doesn't have to be electric, transistors, etc. How can a machine like this do all that it does? I can't understand. I would like a thought path for this, analogy. Especially one where I can think it as...
Given an NFA with more than one initial or final state, it is possible to convert it to another NFA with only one initial or final state by using epsilon transitions. To remove the epsilon transitions, we may need to add final or initial states, depending on the method used (backwards removal vs forward removal). Is th...
Suppose we are given an array-based list data structure. Suppose that its initial capacity is $m > 0.$ When appending an element to the end of the list, if the list is full, we extend its capacity by $d > 0$ array components, copy the old content, and finally append the element. Suppose we are to append $n \geq m$ elem...
I am a total noob to programming, and one of the basic ideas in Haskell is how one can define new types using some things called constructors. I haven't quite understood it fully, but why would one want to make any types beyond the basic ones? What practical utility does it hold?
Let A[1 : n] be a vector of n integers such that all elements except O(n^2/3) elements are between 1 and 10n. Design an algorithm with linear complexity that sorts A. Beyond the algorithm, what I can't fully understand is why we are provided with the information "all elements except O(n^2/3)" It is certainly an informa...
Hoare Triple formalizes program correctness, which contains postcondition, program and precondition such as $\vdash P \{Q\} R$ Provided code snippet: i := 0; s := 0; while i < N do s := s + max(arr[i]); i := i + 1; od The program's goal is to compute the sum of the maximum integers obtained from each element $a...
I have two arrays that both contain $n$ elements (positive, non zero, not negative) $\{x_1\dots x_n\}$ $\{y_1\dots y_n\}$ I want to pair them up optimally, one from each array, so that the pairs come out as even as possible, when paired up optimally. I want the difference between the highest sum of pair values and the ...
Assuming $G=(V,E)$ is a 3-colorable graph, then there are 3 disjoint independent subsets of $V$: $S_1,S_2,S_3$ such that $S_1 \cup S_2 \cup S_3=V$, by taking each $S_i$ to include the vertices of color $i$. I wanted to know - if $G$ is not 3-colorable, then can it has 3 disjoint subsets that their union is $V$? I think...
The complementary language of a recognizable undecidable language is not recognizable. If the complementary language of an recognizable language is a non-recognizable language, is the recognizable language a non-decidable language?
This post introduces a new variant of 3-SAT called EQUAL-3-SAT, where the number of 3-Literal clause is equal to the number of variable. Consider the 3-SAT problem where the formula is in conjunctive normal form and we restrict the Boolean formulas such that the number of clauses in the formula is equal to the number ...
I was provided with the solution to the language being represented. An example of accepted input would be [001][101]. The DFA that would recognize this language is below. What do the states represent? What are the meaning of the transitions
What is the optimal time complexity for an algorithm that solves the Longest Increasing Subsequence problem? I am aware of the O(n log n) algorithm mentioned in textbooks (and on the Wikipedia article). Can we do better? Is it possible to solve this problem in O(n) time?
Say they are two tokens, A and B. A has probability weight 0.99 (and B has 0.01). If I want to encode the sequence "AAA", wouldn't the binary encoding just be "0"? And wouldn't that be the same for encoding "AA", or "AAAA", or an number of A's? How is the decoder supposed to know how many A's are sent when all it recei...
A decidable language must be recognizable. Unrecognizable languages must be undecidable? I want to know more about the relation of undecidability and unrecognizability
From my understanding, the general implementation of an adjacency list is using a hashtable with vertices as keys and linked lists to as values in the hashtable to represent the adjacent vertices of the key. It is also said that the time complexity of finding all the neighbours of a given vertex in the graph using the ...
Given what we know, which of the following scenarios are possible: There exist algorithms which are in-fact Ptime algorithms for NP-Complete problems, but which cannot be proved to work. and there are no Ptime algorithms for NP-Complete problems which can be proved to work. and it cannot be proved that P $=$ NP....
The proposirional logic is based on 3 schema of axioms of which (A1) is B ⇒ (C ⇒ B). Then, for any 2 axioms p and q, p ⇒ (q ⇒ p) is an instance axiom of (A1). We can have q ⇒ p by a step of MP as we have already p. We can have p ⇒ q in the same manner. So, we have p ⇔ q, that is, all axioms are equivalent. But can we a...
Reference from here If a Language is Non-Recognizable then what about its complement? There exist complementary languages of unrecognizable languages that are recognizable, and there exist complementary languages of unrecognizable languages that are undecidable. If a language is unrecognizable, then it must be undecida...
I have frequently seen two different definitions of polynomial-time reduction. In the following let $A, B \subseteq \Sigma^*$ be decidable problems. I will try to formulate the definitions in my own words: Definition 1: $A \le_{p_1} B$ iff there exists a polynomial-time computable function $f\colon \Sigma^*\to\Sigma^*$...
Suppose directed graph $G=(V,E)$, let $\delta(u,v)$ as the shortest path between any pair $u,v\in V$. Also there is no negative cycle in $G$. Can we conclude that $$\sum_{u\in V}\sum_{v\in V}\delta(u,v)\geq0\;\;?$$ I try to find a counter example but I guess that it's true because if $\sum_{u\in V}\sum_{v\in V}\delta(u...
I'm studying algorithms on the very famous book "Introduction to Algorithms" by Cormen, Leiserson, Rivest, and Stein. and I'm looking at the algorithms for finding the maximum and minimum elements in a binary search tree . In the book obviously such a tree is described as follows: "We can represent such a tree by a li...
Let's say we are looking at the decimal language $L_6$ where $$\Sigma = \{ 0,1,2,3,4,5,6,7,8,9 \}$$ and $L_6$ accepts an integer w if w is a multiple of 6. I'm trying to find the regular expression for this regular language or prove that it is non-regular. I think that the language is regular since this is an intersec...
Admittedly I haven't fully wrapped my head around the paper yet, but I'm curious if this algorithm can be adapted to say, a one dimensional cellular automata with two states, and an even sized neighborhood, there are references in the paper to "neighbor radius" and neighborhood size of 2r+1. But the reversibility of ne...
Most constructs / schemes in programming serve an essential purpose (sometimes more than one), for instance : Structs in essentially C's solution to the problem of providing user defined data types. Classes in C, Python, generalize the concept and allow for OO programming. Templates or type parameters or generics (C++...
I need to create an implementation of a directed weighted multigraph with dynamic edges: The edges will be changing during the pathfinding, in the following way: Summary of the pathfinding: Pathfinding starts at S. S -> V1 (through edge with weight 3) V1 -> V2 (through edge with weight 7, as edge with weight 3 is not ...
There are n jobs each consisting of two parts: a and b. There are two people: person A is completing part a of each job (one at a time), and person B is completing part b of each job (also one at a time). Constraint: part a of each job must be completed before part b We are given for each i: a[i] : the time that i...
Consider the following optimisation problem that its size is parameterised by $n$ (width) and $m$ (depth): Find $w_1, w_2, \ldots, w_n$ that minmises: $$ \min \Big[w_1x_1^0 + w_2x_2^0 + \ldots + w_nx_n^0 \Big] $$ Subject to: $$ b^1_{\min} \le w_1x_1^1 + w_2x_2^1 + \ldots + w_nx_n^1 \le b^1_{\max} $$ $$ b^2_{\min} \le w...
I have a sampled function sruface $$ z = f(x, y) $$ represented as a grayscale raster image. How to find the upper convex hull of that surface. That is I am looking for the minimal $$ g(x, y) $$ such that $$ g(x, y) \geq f(x, y), \text{Eigenvalues}(\text{Hessian}(g)) < 0 $$ It is possible to convert the image into a 3d...
I am an undergraduate student in mathematics. I have a fair bit of experience with deep learning in computer vision research and am willing to dabble into NLP. I hope that things won't be very disjointed and some of the knowledge can be transferred. I wanted to know if y'all can recommend some YouTube playlists that st...
Let $G=(V,E)$ be a flow network with two vertices $s,t$ also each edge has its capacity equal to $\infty$. Our goal is to transfer a flow of size $C$ from $s$ to $t$ so that minimize an edge that has highest flow value in it. I guess by $O(1) $ times using the Ford-Fulkerson we can minimize such an edge. First let $k$ ...
I was wondering about a solution for the following problem: Given a directed graph $G=(V,E)$ and a subset of vertices $U \subseteq V$ suggest an algorithm that finds if there is a directed path that visits every node in $U$. The path can revisit vertices/edges. The path can visit vertices not in $U$ repeatedly as well...
I'm trying to create an algorithm that finds the minimum number of swaps to convert array A into array B. In this case the arrays can only contain the numbers 0, 1 or 2. So for example: given a = [0, 2, 1, 2] and b = [1, 2, 0, 2]. The minimum number of swaps to convert a into b is 1, namely swap a[0] and a[2]. I've tri...
Suppose I have a rank-$k$ matrix $A \in \mathbf{R}^{m \times n}$. Now suppose this matrix has its elements shuffled by an adversary to maximize the rank. Is there a way to reverse this permutation and recover the low-rank structure? As follow-ups, what about with sparsity assumptions on the matrix or when $k$ is very s...
Let's say if we have an infinite process that never yields such that other process dosent get to run. Since FCFS is a non preemptive scheduler does it leads to starvation
From the NumPy documentation: "NumPy arrays have a fixed size at creation, unlike Python lists (which can grow dynamically). Changing the size of an ndarray will create a new array and delete the original." To my understanding, this would make the numpy array immutable, but from what I've seen, they're actually mutab...
I am using the book Elements of the Theory of Computation (2nd edition), which has been fine until now. However, I am stuck trying to grasp the Machine Turing conveyed in Example 4.1.8 (pages 189-190). I cannot make sense of the copying machine portrayed in Figure 4-8. Can someone help me understand with an input word ...
With the following recursive code to count leaf nodes of a binary tree, is there any way to make it faster or parallel-computing optimized in time? Python code - (mag(P) = number of leaf nodes of tree P depth H, left(P) = produces left subtree and right(P)= produces right subtree, not given here, reduce the tree P to ...
Which algorithm do I use and how much does it cost if I have to: Calculate all distances in an undirected and unweighted graph from two sources to all nodes. I think the most appropriate algorithm is a BFS(G,s) with cost T(n)= O(V+E) where V= (number of nodes) and E=(number of arcs). The algorithm is the one in the fig...
$$(\lambda x. x \text{ } x ) ( \lambda x . x \text{ } x )= (\lambda x. x \text{ } x) ( \lambda x . x \text{ } x)$$ Source I am a bit confused on how this composition was done. When I do it, I get: $$ \lambda x. (\lambda x. x \text{ } x) (\lambda x . x \text{ } x)$$ On what basis do I drop the exterior most $\lambda...
I am trying to understand how operating systems work because I would like to write my own version of Unix. Anyway, I have some doubts about some mechanisms that allow the applications to communicate with the kernel. In particular, according the several sources on the web, when we compile a program, it is OS dependent a...
I am really confused about it. I think 32 bits = 4 bytes but 32 bit address is only 1 bit.
L1 and L2 are two lists which only consist of X's and Y's. L1 and L2 have the same length. How many sublists of L1 contain the same number of X's as the sublist of L2 in the same position? The empty sublist is not counted. For example: L1 = X L2 = Y => return 0 L1 = Y, Y L2 = Y, Y => return 3 L1 = Y, X, Y L2 = X, Y,...
I implemented the $O(n^2)$ convex hull algorithm. That is: Find a triangle known to be in the hull (by finding the lowest point, a point connected to it in the 2D convex hull, and the point that makes the widest angled triangle relative to all other triangles with thsoe 2 points). Add the 3 edges and the triangle nor...
I have to express the solution of the recurrence equation T(n) = T(an) + n where a is a constant, 0 < a < 1, in terms of θ using the iteration method. I am unsure of how I calculate the cost of each level and the number of levels because of the constant a.