instruction
stringlengths
35
29.1k
I have a very simple question about the best possible big-O bounds for the following data structure: It starts out empty When you add an element, it is inserted, and the index it was at is associated with it. So if it was the first item inserted, it's index would be zero: 14 12 19 <- items 0 1 2 <- associated indice...
Let's say I have a Binary search tree with $n$ nodes and know its shape. I also knows each node has a unique key that is an integer between $1$ and $n$ (inclusive). This would make the assignment of the keys to the nodes unique, given its shape. What is a good $O(n)$ algorithm for assigning each node its correct key? F...
Given a DRAM-based memory system with a total capacity of $x$ bytes, $y$ DRAM rows and a refresh time of $t$ milliseconds, how do I compute the power consumption for one DRAM refresh? I couldn't find something concerning this question so far.
Im trying to figure out if there's an assembler instructions or a bios intruction to get multi-threading in a kernel. In the case that doesn't exist that, how could i set muti-threading in a kernel?
I calculate similarity percent between two images. Another image is the same with changed brightness. I've already tried comparing by pixel (euclidean distance for grayscale and 0/1 values), comparing by HSV. I've tried also normalisation (pixel brightness-mean brightness). The results were quite good (80-90%), but the...
Suppose a language $L$ has a non-adaptive PCP verifier which uses at most $r(n)$ random coins, and queries at most $q(n)$ locations of the proof, on inputs of length $n$. How can we show that there is a PCP verifier $V'$ for $L$ that uses proofs of length at most $2^{r(n)}q(n)$? I understand that the verifier can query...
The single sell profit problem is: Given a list of prices on each day, find the maximum profit that could have been made by buying on one of the days and selling on a later day. There is a solution with a single scan that is easy to implement and runs in $O(n)$. This question is not about that. It's about the divide-...
Suppose there are two strings, $S$ and $T$, and we want to find the length $l$ of the shortest substring of $S$ which contains all the characters in $T$, in order. (Assume the length of $T$ is bounded, so it doesn't need to be considered for determining time complexity.) Here are some examples: $S$ = "abcabc", $T$ = "...
Using guess and check method, for two given graphs with the same number of nodes, a NTM selects a permutation of the node set and then checks if the edges are preserved. The nondeterministic selection of a permutation of the nodes is done in polynomial time. How is the choice of a function done in polynomial time? This...
I need to prove or disprove that $L^* = L^*L^*$. Intuitively, I know this is true, and I know I need to prove that $L^*$ is subset of $L^*L^*$ and that $L^*L^*$ is a subset of $L^*$. But I am really struggling to prove that.
A unit disk graph is defined by a collection of $n$ vertices corresponding to $n$ points on the plane, with an edge between any two vertices whose distance is at most $r$. Some $NP$-hard problems become solvable in polynomial time for unit disk graphs. I am interested in designing approximation algorithms by adapting s...
The use of the phrase "worst-case running time" is really confusing to me. Isn't plainly stating that the time complexity of an algorithm is $O(n^2)$ supposed to mean that the growth rate of the algorithm is sub-quadratic? If it is then why do we say that $O(n^2)$ is the worst case time? Or do they have different meani...
I've been doing review problems for a midterm and I came across this one problem that I haven't been able to solve. The problem essentially says that given a complete graph $G=(V,E)$ partition the vertices into two subsets $A$ and $B$ such that weight of the smallest intra edge (i.e. an edge $e=(u,v)$ such that $u$ and...
in John Backus' 1978 FP paper "Can Programming Be Liberated from the von Neumann Style" he says To help assemble the overall result from single words [von Neumann ie. conventional mutation-based] languages provide some primitive combining forms in the statement world--the for, while,and if-then-else statements--but th...
Define a sequence $c_1,c_2,\dots$ by the equations $$ c_1=0, \quad c_n = 4c_{\lfloor n/2 \rfloor} + n \text{ for all } n > 1. $$ Prove that $\frac{(n+1)^2}{8} < c_n$ for all $n \geq 2$. Hint: $\lfloor \frac{n}{2} \rfloor \geq \frac{n-1}{2}$ for all $n$. How do I solve this question? I have no idea how to start.
I need to prove the following languages are not regular and I'm having a tough time identifying the equivalence class that can have an infinite index. How would I go about doing these? I know how to prove it after finding the equivalence class but any tips on how to identify the one that has the infinite index? I know ...
From this talk and these lecture notes here and here I learned that sequential consistency does not actually model what really happens in practice. However, it is also pointed out that most of the work in formal methods assumes the sequential consistency model even though there exists other models which correctly chara...
Could you please help me understand the following Language $L = \{ a | a ∈ \{0, 1\}^∗, |a| = k ≥ 4, a = a_1a_2...a_{k−1}a_k, ∃i ∈ N, 1 ≤ i < k : a_i = a_{i+1} \}$ what does $a_i = a_{i+1}$ mean? Could you please give me an example of word in $L$?
I am designing a simple compiler for my university project. In my programming language, the break keyword is allowed. I want to know whether break keyword occurs outside a loop should be a syntax error or semantic error. I want to know what is the best approach. If it is a syntax error I can do it in the grammar file. ...
I was solving some problem from past test, there was this question: Use the closure property of regular language to show the language $L$ is not regular $$L =\{ a^3 b^n c^{n-3} \mid n>3\} $$ I know how to solve it using Pumping Lemma, but how to solve it with closure property? Also, I know that to prove that a langua...
I'm trying to understand how you set about writing an OS in something like C. I've always used C to write applications - using commands like malloc and fork and so on to request things from the OS. If these methods don't exist when you're programming the OS itself (or perhaps the Kernel in particular), how do you write...
Question: Assume there are $n$ distinct gifts on the real line. Their positions are $\{x_1, ..., x_n\}$ and each of them has an individual value $p_i$. Now you can choose a subset of them such that any two gifts in your choice are at a distance more than 5. What’s the maximum total value you can get? Design an algorith...
I'm trying to show that for the following Towers of Hanoi general algorithm that $T_k(n)=\Theta(n)$ for all $k\geq 2 + \frac{n-1}{2}$, I'm not sure how to incorporate the restriction on $k$ into my proof. generalTH(n_disks,k_stacks) if n<k: ### in 2n-1 moves reassemble ### return m = n-2 generalTH(n-m,...
Let $G=(V,E),n=|V|,m=|E|$ be a graph. There exists an algorithm with time complexity $O(n+m)$ to test if given graph $G$ is chordal. If I know the graph is NOT chordal, is there a algorithm to find any of the cycles without a chord of length $k\geq 4$ (running in polynomial time of course)?
This question concerns a variant of the 'experts' problem and the randomized weighted majority algorithm that can be used to solve it. This is the description of the problem from Wikipedia: Imagine that every morning before the stock market opens, we get a prediction from each of our "experts" about whether the stock ...
Given recurrence relation $T(n)=8T(n/6)+n \log n$, I get that the running time of the leaves should be $n^{\log_6 8}$ and $f(n)$ should be $n \log n$, but how can I know which one is bigger ?
I'm still quite new to regex, and I've seen topics online of people talking about removing lambda productions, but that has yet to be discussed in the class and the only formal definition of the rules in a grammar that I was given by my teacher: $rule ∈ V$ $\times$ $(V ∪ Σ)^*$ where V is the set of variables and Σ is t...
Lately, I have been in touch with some C++ snippets, and I have a very strange observation on the tiny detail: Most of the times, I see, that people declare iteration variables outside of the for/while definitions, and then initialise them inside for/while definitions, like: int i, j, k; for(i = 0; ..; ..) { } //note,...
I am stumped on the following question: For any depth first search of a directed graph, is it true that the strongly connected component containing the vertex with the lowest post order number also contains a sink? I know that the sink has the highest post-order number, so I am inclined to say False, but I do not know ...
There is a question in the second chapter of the book that I'm unable to solve, and unfortunately algorist.com does not provide a rigorous enough solution, or maybe I can't quite understand it. Here is the question: I've noticed the sums of rows are the powers of 3, and it's intuitively obvious that the sums of rows a...
Consider a transition system defined by $\langle S,T \rangle$, where $S$ is a set of states and $T \subseteq S \times S$ is a set of transitions, where $T$ is total, i.e. for every state $s$ there is at least one outgoing transitions $(s,s') \in T$. Each path corresponds to a set of states, namely, the states visited a...
The original grammar is $$ S \to SaS \mid SbS \mid ScS \mid d $$ My answer is $$ S \to daS \mid dbS \mid dcS \mid d $$ Is that correct?
I came across the following two regular expressions $r_1 = 0^+(10^+0)^∗0^*$ and $r_2 = 0^+(10^+0)^∗$. I know, in general, proving if two regular expressions are equivalent is hard in terms of time complexity, and that there are several algorithms to determine this. (e.g, convert regex to DFAs.) However, I wanted to kno...
Given a list of non-overlapping ranges and values, i.e. [(0, 5, 0.5), (10, 15, 1.1), ...], and a list of potentially overlapping ranges (bins), i.e. [(0, 10), (5, 15), (0, 5), ...], find the average, min, max, standard deviation of the bins. For example, the answer for averages would be [0.25, 0.55, 0.5, ...]. Assume t...
I have a control flow of function F, I want to know all control flows of this functions. I.e., function F { A; if B { B; } C; } would have the control flows {[ABC],[AC]}. My intuition tells me that the complexity/amount of different control flows is $O(2^m)$ with $m$ being the amount of branches. How...
As far as I can tell, we have invented tools and algorithm to: Detect a wider range of colors at a larger range than humans or any other animals on the planet Detect sound with wavelengths inaccessible to humans or most animals on the planet But why is it that dogs can smell COVID or Cancer and we can't produce a sim...
This is my first time posting here, so I hope I'm on topic. I have a table of natural-language data of the form [Underlying] -> [Observed] ABC -> abcd EFGH -> eghf IJK -> ik LMNOP -> lnop LNOP -> lnop and so on. There are around 5000 more of these, but this is a sort of representative sample of things that go on. For ...
Are there two function $f:N\rightarrow N$, and $g:N\rightarrow N$ such that $f(n)+g(n)\ne O(f(n))$ $\wedge$ $f(n)+g(n)\ne O(g(n))$? My idea: i think because of for any $f:N\rightarrow N$, and $g:N\rightarrow N$ then $f(n)+g(n)= O(\max \{f(n),g(n)\})$ then there are no two such functions. is my argument is valid?
Please help me understand the following $L = \{ a | a ∈ \{0, 1\}^∗, |a| = k ≥ 4, a = a_1a_2...a_{k−1}a_k, ∃i ∈ N, 1 ≤ i < k : a_i = a_{i+1} \}$ To prove: The language $L$ has regular pumping property My argumentation: Let $p = 4 $. Let $z$ in $L$, with $z$ $\geq $ $p$. Set $u$ to $\epsilon$. Than $x$ is the first lette...
Can anyone help me understand the time and space complexity here? I know zip() is O(1) and sorted() is O(n). The loop has the operation min() inside but is operating on just 2 values so is that also O(1)? If so then every operation in the loop is O(1) so the overall time complexity is O(n) correct? For space, z could g...
Input : $x \in \mathbb Z$ and $a_1,a_2,\dots,a_n \in \mathbb N$. Output : $b_1,b_2,\dots,b_n \in \mathbb Z$ such that $\sum_{i} a_i b_i=x$ and $\sum_{i}|b_i|$ is minimized. Main question is, can we solve this problem with greedy or parallel algorithms?
I am trying to model a problem to enable me to use Dijkstra's Shortest Path algorithm. Given are a set of vertices V, and a set of vertices X ⊂ V. Between these vertices are given a set of edges where: edge(u,v) with u ∈ V \ X being weighted > 0 edge (u,v) where u ∈ X being weighted = 0 other edge combinations (i.e. u...
I'm starting to dig into the RAFT consensus algorithm and I wanted to clarify something pretty basic: it seems like RAFT operates on the assumptions that 1) each node trusts all the other nodes and that 2) nodes would not have a failure mode where they would incorrectly identify themselves as a leader from a higher ter...
I don't mean compiler flags for pipelining. I would like to program in a way that helps the compiler do optimizations using pipelining. I mean I want to order instructions in C in such a way that GCC (or other compiler) can easily pipeline my instructions. For example, if I have: a+=b c=a/b d+=b f+=b Here, the last tw...
This question asks for an informal explanation of why all polymorphic functions between functors are natural transformations (This is a claim made by Bartosz Milewski). One answer to that question refers to the Theorems for free! paper. However, after reading it I'm not seeing how it implies the result. The parametrici...
I have read this paper https://arxiv.org/pdf/1803.03674v1.pdf for outlier detection problem with real data (online training) In this paper, the authors used Incremental Decision Tree to build subspaces (nodes in tree) by 2-mean method. The problem is in the algorithm 2 (build tree in paper), the condition (line 22): if...
Let's suppose there are two banks, Bank A and Bank B. A transaction needs to happen that transfers money from an account in Bank A to an account in Bank B. Bank A and Bank B have separate banking systems which makes this transaction a distributed one. From what I understand following is what happens, I refer the system...
I have a scheduling problem with the following specifications: A single machine is used. $n$ jobs $\mathbb{J} = \{J_1,...,J_n\}$ are available from the start $t = 0$. Each job can be executed several times. There is a cycle length $t = T_{max}$ and the scheduled jobs have to fit in $[0,T_{max}[$. There are two types ...
Let $X$ a maximal prefix code on an alphabet $A$, $m(X)$ its maximal length, $F = X \cap A^{m(X)}$ and $F’ \subseteq A^{m(X)}$. Let $X’ = X \setminus F \cup F’$ a maximal prefix code. Why is it true that $X’ = X$? In other words, why is it true that one cannot obtain a maximal prefix code from another maximal prefix co...
I'm looking for a resource (online or printed) that explains in a self-contained way the classic tableau for first-order logic with equality. All I can find are expositions of tableaux for first-order logic without equality, or resources which explains the tableau without equality and then treat equality with the same ...
How to prove this language is context-free but not regular? I can't figure out it. A string is contractible if there is a sequence of contractions which result in the empty string, where a contraction is the removal of a sequence of length 2 or more consecutive identical symbols. When a contraction is applied it must ...
IF SAT(satisfiability problem) belongs to P, then is it possible for a certificate of an arbitrary instance of SAT to be found efficiently?
I had this question on a problem set recently, but I wasn't sure how to solve it. Given a complete weighted undirected graph $G$, here are two "algorithms" to find a Hamiltonian path: greedy: start at one vertex at random, and greedily choose the edge that leads to an unvisited vertex with smallest weight anti-greedy:...
Problem: Describe (English is enough) a linear algorithm that, given a set $S$ of $n$ distinct numbers and a positive integer $k \leq n$, returns the $k$ numbers in $S$ that are closest to the median of $S$. Answer: I interpret the term linear algorithm to mean one that runs in $O(n)$ time. It is not clear to me if tha...
Given two statement: A:if inputs of a problem is online, then there is faster or equal algorithm in view of time complexity for that problem when input is offline. B:if inputs of a problem is offline, then there is faster or equal algorithm in view of time complexity for that problem when input is online. Which of the...
I know that the 3-cycle cover decision problem for directed graphs (3-DCC), defined as finding whether a directed graph has a disjoint vertex cycle cover in which every cycle has at least 3 edges, is NP-complete. Does anyone know what is the actual scaling of the best known algorithm to solve that problem? And, most im...
I have a requirement where I need to group similar elements together within an original list. For example: I/P array: [1, 2, 3, A1, B1, 4, B2, 5, 6, C1, B3, B4, 7, 8, 9, 10, A2, A3, 11, 12, A4, C2, D1] Now I would like to group the elements starting with an alphabet such that all the elements belonging to a specific al...
I am a CS major trying to decipher quantum computing. I have done some elementary study on qubits and I always seem to get lost at the "infinitely many" states that the qubit can have. And I really want to understand what it actually means. My understanding is as follows and please correct me if I am wrong, A classical...
This is a problem that I have been struggling to understand in a theoretical computer science book I've been reading: We call a sequence of $n$ integers $x_1, \dots, x_n$ valid if each $x_i$ is in $\{1, \dots, m\}$. How would you design a dynamic programming-based algorithm that takes in $n$, $m$ and “target” $T$ as i...
In the definition of in-place algorithm, from Wiki, " However, this form is very limited as simply having an index to a length n array requires O(log n) bits." How does an array index requires log n bits? For example, A[0], 0 here just take O(1) bits, right? It is just 1 number. I guess my question is about how an arra...
Given a language $L$ and a set of strings $\Sigma^* = \{0, 1\}^*$, how can I find a regular set that expresses $L = \{ w \in \Sigma^* \mid w$ ends with $00$ and does not contain $11\}$? Well, the part that states that w must end with 00 is easy and I (think I) managed to find the regular set for it. But I can't modify ...
I am in an intro to OS class and we are learning about mutual exclusion and semaphores. One classical problem we learned about was the dining philosophers problem. My professor touched on the different cases using simple semaphores (i.e asking the last philosopher to grab the right fork before the left while the others...
At least intuitively, I understand the following terms to be rigorously associated: Field Separator (FS) as a delimiter which delimits text segments such as words, sentences or lines/fields and an example would be an Input Field Separator / Internal Field Separator (IFS) Indentation character: Whitespace character Ta...
I'm stuck on how to progress with this proof, despite I have tried, I cannot see the next move. Given this proof without predicate: So far what I've accomplished: My idea is, as I can't see any other option using (-(Sv(P->Q)) as the first assumption in order to introduce a conditional, so the assumption must end in P...
Re-usability of code is one of the main benefits of the bottom-up approach (Wikipedia) I can't quite figure out how bottom-up approach enables code re-usability. I am aware that Object Oriented Programming is bottom-up approach and it has features such as inheritance that enable code re-usability. But I cannot connec...
I am given a connected graph $G$ with some embedding. I want to find a non-deterministic algorithm running in $O(n)$ time to decide whether $G$ with that embedding is a plane graph (i.e, can be drawn without intersecting edges). I know there exist algorithms that decide whether a graph is planar or not in time $O(n)$, ...
Not sure which OS is best to invest in for my computer science degree. Have had varying opinions - from your experience in education or working in the sector, what is the operating system that will treat me the best for the next three years of my degree?
How does LZW decompress data with dictionary clearing/flushing? I understand that a space is reserved in the dictionary that represents a clear code (usually 256), but how is this code actually used when compressing and decompressing data? My thoughts for compression are that it checks the table size, and if the table ...
There are 10 teams, Team A through Team J, playing in a triple round robin pool (each team plays thrice against each other team, for a total of a 27 games per team). After the round robin pool, the top 4 teams (with the highest number of wins) make playoffs (with some tie-breaking procedure that can be done in polynomi...
How to prove that $L$, where $$L = \{\langle M\rangle: L(M)\text{ is recognizable}\}$$ is decidable? What about $\bar{L}$?
I need to use it to prove $L^*=L^*L^*$. So I know that $L^*=L^1 \cup L^2 \cup L^3\cup\ldots$ But how do you describe $L^* L^*$?
Define Σ = {a, b, c, . . . , z} be the set of letters in the English alphabet. Prove that the following language is undecidable: Cats-VS-Dogs = {(M) | Either “cats” ∈ L(M) or “dogs” ∈ L(M), but not both.}.
Given a circle with $n$ equal segments. On each segment there is an integer. We want select segments at equal distance, maximizing the sum of integers on selected segments. I have an algorithm with runtime $O(n^2)$ as follows: First calculate maximum sum of segments at distance one. Second calculate maximum sum of se...
Given a regular language $L$ and a string $x$ give an efficient algorithm to count the occurrences of substrings $x[i,j] \in L$. More in particular, I am looking for a linear time algorithm in the length of the string $|x|$, for a given deterministic automaton $M$ accepting the language $L$. This question is meant to g...
I was going through the text : Compilers: Principles, Techniques and Tools by Ullman et. al where I came across the following algorithm to convert an $\epsilon\text{-NFA}$ to $\text{DFA}$ 1. initially, ϵ-closure(s0) is the only state in Dstates and it is unmarked; 2. while there is an unmarked state T in Dstates do b...
How practical are logic engines for proof paths combined with knowledge graphs in Providing reasonable explainability for ML models trained using GNNs? Adding more context. there is a history of logical reasoning (found in academic articles and in filed/granted patents) as a partial mechanism to building solutions to p...
I am not able to solve the following recurrence relation: $$ T(n) = \begin{cases} T(n-1) + n^2 & \text{if } n \ge 2, \\ 1 & \text{otherwise.}\\ \end{cases} $$ How do I start?
This is a question from a practice quiz at my university. Is the question asking for the cardinality of Σ1 = {a,b} to the power of four? if that's the case, then the set would still have a cardinality of 2 since elements in a set are unique. It wouldn't be {a,b,a,b,a,b,a,b} right?
I've been working on undecidability proofs and I found this question in the practice problems for the textbook "An Introduction to Automata Theory." I know that we start by contradicting the statement, and assuming that Language1 is decidable, so that there is a decider D which decides Language1. Then we construct a Tu...
I've been working on decidability practice problems and I came across this one in a practice problem set from the textbook An Introduction to Computational Techniques. I know the steps for how to prove a language is undecidable by constructing a Turing Machine which shows that the language is not recursive. However, I'...
A Burrows-Wheeler Transform (BWT) can be used to find the suffix array intervals for a pattern $P$ by issuing $p=|P|$ paired $rank$ queries \begin{align} s^\prime &= C[P[i]] + rank(s-1, P[i]) + 1 \\ e^\prime &= C[P[i]] + rank(e, P[i]) \end{align} where $s$ denotes the start of the search range and $e$ is the end of th...
In this question, I asked about how to prove naturality from parametric polymorphism, using parametricity. The current answer to that question simply assumes that the functors in question satisfy the functoriality conditions. Is there a "free theorem" result for functoriality? i.e. is it sometimes possible to see from ...
I am trying to teach myself Automata theory. I have hard time with the Pumping Lemma, so I am trying to work through examples. I stumbled upon this example, but it doesn't have steps how to solve it. I would appreciate a clear explanation of how I would use the Pumping Lemma to prove that this language S is not regular...
What is the complexity of the BFS algorithm for the shortest path on the unweighted grid? The grid is a classical maze with a starting point and exit, need to find an exit. Can move only vertically and horizontally. Found the answer here: https://stackoverflow.com/questions/50901203/dfs-and-bfs-time-and-space-complexi...
My understanding is the following: Time = With the initial not state is just to check if there are no elements in the list a. This is done in O(1) time. The first loop enumerates the second list b with the operation append() which is done in O(1) time therefore the first loop is O(n). The second loop I am confused if t...
Whenever there is a back edge, a cycle is detected. Then, do a pair of parallel edges form a cycle in a graph? If no, why it is not a back edge?
Let $X = X_1 \cup X_2$ a code on an alphabet $A$, with $X_1$ a biprefix code and $X_2$ a uniform code, with $m(X_1) < m(X_2)$, i.e. the maximal length of the first is strictly lower than the second. Now, if $v \in X_2$ we define a sequence such that $v_0 = v$ and $v_{i+1} = 1$ if $v_i \notin X_1A^*$ and $v_{i+1} = y_ix...
consider we have n bags of random amounts of coins. given k extra coins, the question is to find the largest gcd that can be obtained by adding these coins to any bag( all the k coins may not go in one bag and not all the coins are necessarily added) input consists of the number of bags followed by k( number of extra c...
For example, assuming I am using the set of natural numbers $\mathbb{N}^* = \mathbb{N} \cup 0$ as my domain. I want to create an algorithm such that at each index value $i$, I output a set. For example, $0$ maps to $\{1,2,3,4\}$ $1$ maps to $\{5,6,7,8\}$ $2$ maps to $\{9,10,11,12\}$ How might I go about deriving the ...
$T(n) = T(n/3) + T(2n/3) + n$ How can I solve this recurrence formula?
As the title said, prove $T(n) = T(\left\lceil{\frac{n}{2}}\right\rceil) + 1 = O(\log(n))$ My approach is to find $c, n_0 \in \mathbb{R}_+$ such that: $$\forall n \geq n_0, T(n) \leq c\log(n) -d \text{, where d is a constant}$$ Assume the statement is true for every $m < n$, especially $m = \left\lceil{\frac{n}{2}}\rig...
I was going through the text Compilers: Principles, Techniques and Tools by Ullman et. al first edition where I came across the following table. The authors justify the table as follows: Given a regular expression $r$ and an input string $x$, we now have two methods for determining whether $x$ is in $L(r)$. One appr...
I want to prove that $T(n) \neq O(n)$ for the Karatsuba algorithm, which has the following recurrence: $$ T(n) = \begin{cases} k_1, & \text{if $n$ = 1} \\ 3T(n/2) + k_2n, & \text{if $n \gt$ 1} \end{cases} $$ where, $k_1$ and $k_2$ are constants, such that $k_1 \gt 0$ and $k_2 \in \mathbb R$. So, to prove that $T(n) \ne...
If you use min() or max() on a constant sized list, even in a loop, is the time complexity O(1)?
I'm reading the Digital Design and Computer Architecture by David Harris, Sarah Harris. The authors give the following definition of combinational logic: A combinational circuit’s outputs depend only on the current values of the inputs; in other words, it combines the current input values to compute the output... A co...
I got stumped by this question during a coding challenge and I haven't come up with promising ideas for how to solve it. I am looking for hints or approaches to solve the problem, not necessarily the code. Given a string s find the lexicographically smallest palindrome of the same length that is lexicographically grea...
Consider $n\times n$ matrix $T$ which represents transitive closure of a directed graph. That means $T_{uv}=1$ if and only if there exist a directed path between vertices $u$ and $v$. Initially, $T$ is a identity matrix (every vertex has a self-loop). Now consider following function: function insertEdge(u, v): for x ...
I don't even know if this is the right place to ask this this...but how will Big O be with quantum computers? More specifically, will the worst case always be constant? If yes, how will this change our understanding of current algorithms? For example, will this mean that the difference between an algorithm running at B...
Recall floating-point representation: Suppose $f$ is a floating-point number then we can express f as, If $f$ is normal: $$(-1)^{s}\cdot2^{e-127}(1 + \sum\limits_{k=1}^{23} b_{23-k}\cdot 2^{-k})$$ If $f$ is denormal/subnormal: $(e = 0)$ $$(-1)^{s}\cdot2^{-126}(0 + \sum\limits_{k=1}^{23} b_{23-k}\cdot 2^{-k})$$ where $...
Given a set of points $x_1, \dots, x_n \in \mathbb{R}^2$, suppose one wants to find: $\text{argmin}_i \sum\limits_{j=1}^{n} \lVert x_i - x_j\rVert_\infty$ i.e. the point which minimizes the sum of the $L_\infty$ distances to the other points. One can apply the matrix $R =\left(\begin{smallmatrix}\frac{1}{2} & \frac{1}{...