instruction
stringlengths
35
29.1k
I'm looking for an existing algorithm that would ensure that the first k elements after sorting are the top k elements but not necessarily in the right order. To put it differently, I would like an algorithm that acts like C++ std::partial_sort but takes advantage of the fact that I don't need the first elements ordere...
Given sorted array $A[1..n]$, we want to find an element such that, $A[i]=i^2$,Can we use binary search to find such a element? My Attempt: initially, I read this link, but I can't understand the comments for why we can't find that element in $O(\log n)$. Any hint be appreciated.
Show that a language is decidable iff some enumerator enumerates the language in decreasing order. What does it mean by enumerator enumerating in decreasing order? I am so confused about this concept. Can you prove the above theorem? Please help me.
Background The literature on succinct data structures refers often to the “information-theoretic lower bound” of encoding data, i.e., the minimum number of bits needed to store the data – a concept related to information-theory entropy. For instance, the definition of a succinct data structure is one that takes up $Z +...
I have two questions on Kaveh's answer to Definition of uniform boolean circuit : Kaveh mentions that the input is in unary encoding. In the definition it says the input is $1^n$, afaik $1^n$ is a sequence of 1's repeated n times, but unary encoding is a sequence of 1's and ends with 0 there is no power of 1 that gi...
What will be a space complexity of a conversion of a sorted array to a balanced BST in case of a recursive solution? Could you, please, check my reasoning. Is it correct? Here is my algorithm for solving the problem: /** * Definition for a binary tree node. * public class TreeNode { * public int val; * publ...
I have a regular language $L$ from characters of $\Sigma_1$, we define: $\Sigma_2=\Sigma_1\cup \{+,-\}$ and $$L^{+-}=\left\{a_1\cdot p\cdot a_2\cdot q \cdot a_3\cdot\ldots \cdot a_k\mid a_1,a_2\ldots,a_k\in L,p\in\{+,-\},q\in \{+,-\}\setminus\{p\}\right\}$$ I want to show this is still a regular language. To do so with...
Given that cameras, computer vision and AI are constantly evolving with greater zoom, macro, processing power... is it possible that some day cameras would be able to « scan » a room and detect COVID (or any other viruses) somewhere, such as on the door knob? In other words, could evolved cameras and AI be able to see ...
I'm struggling with the median of medians algorithm, and I think it's perhaps more of a semantics thing rather than a technical thing. I've always thought the median of medians algorithm as finding an approximate median $p$ such that $p$ is within $20\%$ of the true median $M$ in the sorted array. However, when I look ...
I'm having trouble approaching this average case analysis in terms of key comparisons. The pseudo-code is as follows: maxSort(Array) { for (int i = Array.length - 1; i > 0; i--) { x = i - 1 max_i = findMaxPos(x) # performs x key comparisons swapValues(max_i, i) } } findMaxPos returns po...
I'm trying to prove a lower bound on some computational problem, but in order to do it, I need an $\Omega(n\log(n))$ lower bound on $\log(T(n))$, where $T(n)$ is a recurrence defined as follows: $T(1) = 1$ $T(n) = \sum_{k=1}^{n-1} T(k)T(n-k)$ Does this recurrence have a known solution? If not, just giving a lower bound...
I am reading Software Engineering 1: Abstraction and Modelling by Dines Bjørner. One of the chapters talks a little bit about call-by-value vs call-by-name. In it, the author states that most programming languages use call-by-value, rather than call-by-name. But from what I have read in the chapter, it seems that call-...
I want to implement Martin Löf's intuitionistic type theory in a functional language such as Haskell, preferably also implementing a lexer/parser for the language. How should I start approaching it? Are there any good papers/blog posts/github repo examples that might be useful? Thanks!
Tabulated hashing uses tables of random numbers to compute hash values. Suppose $|\mathcal{U}| = 2^w \times 2^w$ and $m = 2^l$, so that the items being hashed are pairs $(x,y)$ where $x$ and $y$ are $w$-bit strings (or $2w$-bit strings broken in half), and hash values are $l$-bit strings. Let $A[0 \cdots 2^w-1]$ and $B...
A seven-bit Hamming code is received as 1110101. What is the correct code? Assume the parity to be one. The problem I am facing here is I don't know how to check parity without knowing it is even or odd.
Say I'm given an oracle that tells me whether or not $L(M)$, the set of words accepted by a Turing Machine $M$, is finite. By leveraging this oracle, can I solve the halting problem? That is, on an arbitrary input $<M, x>$, can I tell if M is going to halt on $x$ or will it loop forever? My intuition says no because I ...
I'm trying to find a cover of a surface using disks of variable sizes. In the image, I want to cover the entire blue surface. The disks can go "out" of the blue surface and into the red part, but they cannot go outside the red area. The red area is always an "expansion" of the blue area. I'm trying to find a solution t...
I don't understand two parts in this paper: The min notion on page 4 line 357 (equation 10d): I understand this as to find all the $M_{10}$, $M_{11}$, $M_{01}$ first and then try to minimize the expression in the brackets of equation 10d. Is it correct? Or does it mean to find the min first and then use that to comput...
I'm studying Coq's core language and I found that mutual inductive type definition is in it. https://coq.inria.fr/refman/language/core/inductive.html#theory-of-inductive-definitions Before I read the material, I had supposed that Coq translates mutual definitions in Gallina into nonmutual ones in its core language, sin...
Consider the below function: Considering that print(a) and swap(a, b) are of complexity $\theta(1)$, what is the time complexity of the above code? The answer that comes to my mind is $\theta((n-k)!)$ or $\mathcal{O}(n!)$. However in the book that I'm reading it says it's of order $\theta(n!)$. What am I missing here?...
I'm stuck in trying to compute an overall entropy calculation with an agent. Let me first introduce some background of the problem. Basically, I'm doing some work with the contextual bandit problems. Let's say I have an agent with $m$ actions to select from and in different contexts (I use states in the following), it ...
I was going through paper titled "Algorithms for Inverse Reinforcement Learning" by Andrew Ng and Russell. It states following basics: MDP $M$ is a tuple $(S,A,\{P_{sa}\},\gamma,R)$, where $S$ is a finite seto of $N$ states $A=\{a_1,...,a_k\}$ is a set of $k$ actions $\{P_{sa}(.)\}$ are the transition probabilities ...
Given an array $A[1..n]$. $A$ is mixed of two sorted arrays $B$ and $C$ of equal sizes, such that $B$ is in the ascending order and $C$ is in the descending order. Consider the following example: $B=[2,4,6,8]$ and $C=[9,7,5,1]$. As a result $A=[2,9,7,4,6,5,8,1]$. Interestingly, The instructor said: $A$ can be sorted i...
I wonder if we say L ⊂ {a, b, c}* then is L an infinite language? I think Kleene star makes me think L is an infinite language.
Question: Is the regular expression and regular grammar equivalent? I've look on some examples of regular grammar however I don't think I fully understand how to convert regular expression to its equivalent grammar. So I am also asking for some help or tips to convert regular expression to regular grammar. *Key () -> e...
Find an example of a regular language where the syntactic right congruence and the syntactic congruence are not identical. I have gone through the relevant definitions and understand them, but could not figure out an example for this case.
I was going through the text: Compilers: Principles, Techniques and Tools by Ullman et. al where I came across the concept of viable prefix and I faced some difficultly in grasping the concept. So I present my doubts here in a systematic manner, with a hope for clarification. Viable Prefixes: The set of prefixes of r...
I'll pose the question in the abstract first and then describe concretely what I'm trying to do. Suppose I have a set of 1000 000 multiple-choice questions and 10 oracles that can answer the questions. But the oracles are imperfect and don't always answer correctly. Some oracles answer more accurately than others. We d...
Solving $T(n) = 2T(\frac{n}{2}) + n\log(n)$ without master theorem, given $T(1) = 1$ My approach with recurrence tree: $n \sim n\log(n)$ $\frac{n}{2} \sim 2 \frac{n}{2}\log(\frac{n}{2})$ $\frac{n}{4} \sim 4 \frac{n}{4}\log(\frac{n}{4})$ Hence the summation must follow as: $$T(n) = \sum_{i=0}^{\log(n)} n\log(\frac{n}{2^...
So I'm reading Introduction to computing systems:From bits and gates to C and beyond, and the author states that a CPU is the mechanism that ...directs the processing of information. Which is figuring out what task should get carried out next My question is: what exactly does he mean when he says that a processor "fi...
I am reading Chapter 7 Linear Programming in Algorithms by Dasgupta et al. I don't get how they switch from an equation to an inequality specifically the part highlighted in red/pink regarding the multiplier $y_1 + y_3 ≥ 1$ instead of $y_1 + y_3 = 1$
How does Command Z work through computer commands? What is the step by step computer commands that complete the process?
This is a sample of datetime field: 1615717137369 It means 2 days ago (from 16 march, 13:24) How can I parse the number? P.S: These are some examples: 16 15 89 8678037 16 March 16:15 ( 5 min ago) 16 15 89 8259356 16 March 16:08 (12 min ago) 16 15 89 791 8713 16 March 16:03 (17 min ago) 16 15 89 791 4439 16...
Given $n$ drugs such that each drug $d_i$ should maintain in interval $[c_i,h_i]$.We want to minimize number of containers to maintain medicines in compatible interval. My answer is as follows: I use following greedy algorithm: in each iteration, for remaining drugs, find an interval that have maximum number of compa...
Given I have an initial capital of $10,000 and i want to buy shares in 3 different companies. Cost of a share in company 1 = $55 Cost of a share in company 2 = $68 Cost of a share in company 3 = $79 And, The trading platform charges me $30 collectively for three purchase transactions above. And, I want to invest 70% ...
Given two balanced binary search trees $T_1,T_2$. We want to check, are $T_1\subseteq T_1$ or not. $T_1$ have $n_1$ nodes, and $T_2$ have $n_2$ nodes. Instructor say it can be done in $O(n_1+n_2)$ time complexity with $O(\log n_1+\log n_2)$ space. My idea: I use in order traverse on two trees , and compare first node...
I need to prove that Turing decidable languages are closed under reversal. I have no idea on how I would prove this. Any suggestions or clues?
In my course there are a number of exercises which amount to taking a trained residual network and deleting, swapping or repeating layers (without retraining). Is there any real application for doing this? An exercise might say to swap two specific layers and I will find that the performance will increase (on a very sm...
This is a soft, and probably also an opinion based question. Suppose I am writing a library in C++ for the purposes of working with financial data. My goals are: Since I work with big data, I want to make it as fast as possible by using parallel computing principle inside the functions. I want my colleagues to use thi...
How I understand microcode translate an instruction to microinstructions. And CPU has a unit that stores all possible of microinstructions. These microinstructions can be changed, because it load every time after boot from motherboard. Can instruction set be changed? I am sorry if i ask strange question, if I misunders...
Given a rectangle defined by its corners $(0, 0)$ and $(w,h)$, $n$ circles $\{ (x_1, y_1), (x_2, y_2), \dots, (x_n, y_n)$ with the same radius $r$, I need to determine the smallest possible radius r so that there is no way to get from $(0,0)$ to $(w, h)$ without touching those circles. What I have tried is Use binar...
So, I have been given a TM where the head can access and write both the character that the head is pointing at and the next character to the right. So if we have a TM abbb and the head is pointing at a, it can access and write into the the next character also ie the first b. So it has access to both the first and secon...
Given a graph $G(V, E)$ and two matchings $M \subset E$ and $M' \subseteq E$ with $|M'| > |M|$, how can one prove that $M\oplus M'$ ($\oplus$ denotes the symmetric difference) must contain at least $|M'|-|M|$ augmenting paths of $M$? I know that there have to exist some $M$-augmenting paths since $M$ is not a maximum ...
I am trying to learn FPGA programming, and I would like to analyze an audio input. I would like to know what kind of frequencies are present in the signal but without using Fourier transform - there are two reasons for this. First one is I dont need to know the exact frequency of the incoming signal, and the second rea...
Given an open-address hash table with $\alpha$ < 1, the expected number of probes in a successful search is at most $\frac{1}{\alpha}\ln\frac{1}{1-\alpha}$ I read this in a book and the proof starts by saying Searching for k follows the same probe sequence as inserting it. If $k$ is the $i+1$th key inserted into the...
When I implemented the paper Dynamic Fusion published in 2015 CVPR, I came into the trouble with how to solve the energy function: $$E(W_t, V, D_t, \mathcal{E}) = \text{Data}(W_t, V, D_t) + λ\text{Reg}(W_t, \mathcal{E})$$ Where: Wt is a set of 4x4 transformation matrix at time t; V is a set of 3D vertices from canonic...
Given the following method written in Java: private void collatz(List<Integer> values) { int size = values.size(); if (size == 0 || values.get(size=1) <= 1) { return; } else { int last = values.get(size = 1); if (last%2 == 0) { values.add(last/2); ...
Here is an exercise from an introduction to computation class: Show that the following context-free grammar $G$ generates the language $L$ of words over $\{0,1\}$ with an equal number of $0$s and $1$s: $$ S \to \epsilon \mid SS \mid 0S1 \mid 1S0 $$ How should I prove that $L⊆ L(G)$ and $L(G) ⊆ L$? I think I should st...
I'm trying to solve the following Time complexity recurrence relation: $T(n,k)=T(n-1,k-1)+T(n-1,k)+1$ that come from following code: int C(n, k) { if (k == 0 || k == n) return 1; // stop recursion. return C(n-1, k-1) + C(n-1, k); } Unfortunately, I have no idea to solve $T(n,k)$. Any hint that helpful be apprec...
Two scenarios: Function is called and data is computed and returned. Data is saved in variable, updated when required, data is retrieved from variable. So I was wondering in what kind of scenarios one would be beneficial over the other?
I have thousands of data points associated with users. So a single user can have 2000-10000 data points. These data points are identified by contiguous numbers (e.g. all numbers from 0 to 2000). Each data point can have 3 states: true, false, unknown. What could I do to group these data points so that they don't take t...
In my database I have 1500 food dishes, not all are single words, there are compound words like "cheese with dried fruit and nuts". And I have them in 5 languages (de, en, fr, es, it). My question is how could I do it so that given a text it gives me a prediction of the 5 dishes that are closest to that text. For examp...
Someone there who worked with cardinal contraindications within the framework of propositional logic? I have a problem understanding the pigeon-hole method. It is a method of satisfaction. I have been trying to understand these three patterns for several days now and I am desperate. Can anyone please explain these thre...
I've got a few questions related to the different types of memory that we can find: To my understanding, since there are registers that are close physically to the CPU, these are much faster to access, same goes for the cache that is further to the CPU but still relatively closed, and the RAM which is further than ever...
I understand that PCA takes a data set with input size, with output labels, and reduces the inputs to a set of principal components size r, where r < n. My question is whether or not this can be applied beyond a simple classification problem where the outputs are not simply labels. For instance, in sheet metal forming ...
I have been reading CLRS and came across a few examples of the Master theorem. I could not follow the reason that epsilon was chosen as 0.8 in the example from page 96 . Can I simply use the condition n^log(b) of a to determine the maximum value of epsilon? For example for case 3 where ()=Ω(log+) for some constant >0....
I have only heard of / seen Grobner bases in passing, but my understanding is that they are much like vector bases but for polynomials instead of linear systems. I know polynomials are used in CAD and graphics at the very least. Is there any particular reason why I haven't seen Grobner bases in application? I'm trying ...
Given sorted array $A[1..n]$. We want to find an element such that $A[i]=3i+2$ in $O(\log n)$(binary search). I trying to relate to problem finding element in sorted array $A$ such that $A[i]=i$, but i can't use that technique to solve mentioned problem. Any hint be appreciated.
I'm trying to apply the following algorithm from DPV's textbook to an example to see how it works. First, the algorithm is as following: Algorithm [DPV, p. 60] Input: Coefficients of two polynomials. A(x) and B(x), of degree d. Output: Their product $C = A . B$ Selection: Pick some points $x_0, x_1, x_2, ..., x_{n-1}...
Definition: Distribution $D$ on $\{0,1\}^n$ is called $k$-independent if for every random variable $X$ with distribution $D$ and for all $i_1, \dots, i_k \in \{1,2,\dots,n\}$ random variable $X_{i_1,\dots, i_k}$ has distribution $U_k$ (uniform distribution on $\{0,1\}^k$). Problem: Consider probabilistic algorithm $A$ ...
Suppose given a binary search tree $T$ with $n$ nodes with depth $h$. We did $n$ times search with cost $c_i$ for search $i^{th}$ search on $T$ ,and $\sum_{i=1}^{n}c_i=O(n\log n)$. what we can say about $h$? I think $h=O(\log n)$, but instructor say it's not true.
Given a set of keys $\{i^2|0\leq i\leq 100\}$, and a hash table such that collision resolve by chaining. Our hash function is $ k \mod m$ . What is option is best for $m$ to decrease our search for items in hash table and why? a.7 b.9 c.11 d.12 I think c is the best choice, but i can't prove it.
The code snippet below is the "beginning lines of an assembly language program" used to display a single line string . stack segment para stack 'stack' db 16 dup(0) stack ends my question is : why stack segment is available in assembly program? And how do I define this 'stack'? Any help will be appreciated. My...
Known codition: four pixels shown in the image $(i,j),(i+1,j),(i,j+1)$ and $(i+1,j+1)$ $a=0.9$ and $b=0.4$ I was able to calculate the bilinear interpolation using the algorithm provided by https://en.wikipedia.org/wiki/Bilinear_interpolation. But how should we calculate the Average Interpolation and Nearest Neighbo...
Under Huffman Encoding, what circumstances codeword length of each character be equal?(suppose number of character is power of 2) I think if all frequency of characters is same then codeword length of all characters be the same. Surprisingly, if there are two characters that differences between frequency of two char...
How to efficiently exit from a maze where you know the initial position of the player (1,1), the exit (49,49)? You don't know the maze configuration but you know where your player is, and which direction are opened from his position. Another point, the player can move RIGHT/DOWN/LEFT/UP, and the exit is at the bottom r...
for(int i = 1;i<=n;i++){ for(int j = i+1;j<=n-i;j++){ print("hello"); } } The first loop has time complexity of n and second for loop is dependent on i. That means for every i, the number of time inner for loop gets executed is: $\sum_{k=1}^{n/2}(n-2k)$ After doing some algebra, I get: $\frac{n...
Let $\Sigma=\{0, 1, \#\}$. Is the following language regular; context-free but not regular; or not context-free? Justify your answer $$L=\{x\#y :\ x, y \in\{0, 1\}^∗\text{ and }\operatorname{bin}(x) + 1 = \operatorname{bin}(\operatorname{rev}(y))\}$$
We've definied the splitting lemma for starfree languages as follows: Let $L \in \mathsf{SF}(\Sigma^*)$ and $A, B \subseteq \Sigma$ with $A \cap B = \emptyset$. Then it holds true that for $K_i, L_i \in \mathsf{SF}(B^*)$: $$L \cap B^* A B^*= \bigcup_{\text{finite}} K_iAL_i$$ I can not see why this is useful by any mean...
I'm new to writing languages in context-free or regular grammar, so I'm struggling how to do this one. It is a bit more complicated that simpler ones I've practiced doing. The problem is to construct a grammar for the following language: $$\{a^n (bc)^m \in \{a, b, c\}^* \mid m, n \ge 1 \land m < n/2\}$$ An explanation ...
Let $M$ be a monoid (e.g. $M = \Sigma^*$) and $L \subseteq M$. Then $\mathsf{RAT}(M)$ is the set of rational sets of $M$ and the elements of $\mathsf{RAT}(M)$ are inductively defined as follows: $|L| < \infty \implies L \in \mathsf{RAT}(M)$ $L_1, L_2 \in \mathsf{RAT}(M) \implies L_1 \cup L_2 \in \mathsf{RAT}(M)$ $L_1,...
Stuck on a problem with my roommate and can't seem to find any parallels to this. The problem is simple to understand: you have two possible binary options: T or F. You are given an array which already has some of these options filled out e.g. [T, X, X, F, X, T] - (Here X means unfilled) What we want to do is to fill t...
Intro The job shop problem is a classic scheduling theory problem. Given $N$ jobs and $M$ machines, a typical goal of the JSP is to minimise the makespan (starting time of the last operation + its processing time) over the set of jobs. Jobs must be processed on a sequence of machines in a particular order. An operation...
Algorithm question: Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. Example 1: Input: [0,1] Output: 2 Explanation: [0, 1] is the longest contiguous subarray with equal number of 0 and 1. Example 2: Input: [0,1,0] Output: 2 Explanation: [0, 1] (or [1, 0]) is a longes...
I am using Matlab daily. But I just realized that I even do not know what algorithm Matlab is using for calculating the exponential function $e^x$. The power series expansion is obviously not appropriate for a big $|x|$.
Given an undirected graph and a start and end node, I am trying to find two node-disjoint paths such that the sum of their lengths is minimized. In particular, each path must start at the start node, end at the end node, and no node (other than the start or end node) can be visited by both nodes. Is there an efficien...
I work in 52:17 work:break intervals, as there's some evidence showing it's an effective way to structure the day. However, meetings or planned breaks often require shifting that schedule, moving, shrinking, or expanding certain parts. I'm trying to write a program which will do this for me, given a start time, an end ...
Say we have some function $f(n)=\Theta(\log n)$ and another function $g(n)=\Theta(n+\log n)$. Is it valid to substitute $f(n)$ for $\log n$, giving us $g(n) = \Theta(n + f(n))$? This seems obvious to me but I'm not sure if there is a weird edge case where this isn't true.
Given an undirected graph and a start and end node, I am trying to find two edge-disjoint paths such that the sum of their lengths is minimized. In particular, each path must start at the start node, end at the end node, and no edge can be traversed by both nodes. Is there an efficient algorithm to solve this problem...
Consider a second order equation $F=ma=m\ddot{x}$. In the language of Euler's method $\ddot{x}(t+dt)=F(t,x(t),\dot x(t))$ $\dot{x}(t+dt)=\dot x(t)+\ddot x(t)dt$ $x(t+dt)=x(t)+\dot x(t)dt$ Basically, the entire iteration was the second order force equation $F(t,x(t),\dot x(t))$. However, here one wanted to apply Runge...
I'm a beginner learning about Assembly language and I was doing questions where I have to identify different addressing mode in 8086 processor. One such instruction is: mov ah,09h Here the source operand has immediate address mode and destination operand has Register address mode. In many tutorials online they have jus...
I encountered the following recurrence relation in homework, for which we need to find its asymptotics: $$T\left(n\right)=T\left( \frac{n}{3} \right) + T\left( \frac{n}{6} \right) + 1$$ I observed it is possible to approach this relation with the method of Akra-Bazzi, however this method was not taught in class. Akra-B...
I am implementing a mathematic model for predicting the congestion of 802.15.4 network based on the paper: Performance analysis of IEEE 802.15.4 non-beacon mode with the unslotted CSMA/CA Based on the system of nonlinear equations mentioned in that paper, I converted that formula into python code and solved it with "sc...
We define the vertex cover as the problem of finding for a graph $G$, a cover of size $k$. A cover is a set of vertices such that every vertex has an edge to this set. We define CD (cycles destructor), as the set of vertices with the size $k$, whose removal will lead to a cycle-free graph. Show a reduction from VC to C...
Suppose search $n$ times in a given binary search tree $T$ with $n$ nodes. each searching have cost $C_i$, and $\sum_{i=1}^{n}C_i=O(n\log n)$. Now the problem is to find height of $T$. I think it be $O(\sqrt{n\log n})$, but after reading this post, what is correct proof to get that result?
Given four formulas in first order logic. Which of the following formulas are not valid? (In logic a proposition is valid if it never evaluates to $\bot$.) $(\exists x P(x)\to Q)\to (\forall x (P(x)\to Q))$ $((\neg P\to Q)\wedge(P\to R))\to (\neg P\to R)$ $(\exists x(P(x)\to Q(x)))\leftrightarrow (\forall x P(x)\to\e...
Is there a theory for Operating Systems? That is, subfields of CS have theoretical parts; i.e. PL has type theory, ML has mathematical theorems, security has a lot of provable properties, etc. There are certain "properties" in OS, like the optimality of SJF scheduling algorithm or the dining philosophers, but these see...
Lemma 13.6    $p \in F \Longleftrightarrow [p] \in F'$ Proof. The direction $\Rightarrow$ is immediate from the definition of $F'$. For the direction $\Leftarrow$, we need to show that if $p \approx q$ and $p \in F$, then $q \in F$. In other words, every $\approx$-equivalence class is either a subset of $F$ or disjoin...
Let the alphabet be $Σ = \{0, 1\}$. For any string $w ∈ Σ^*$ of length at least 2, define the operation $C_2(w)$ to be a cyclic shift of size 2 on $w$. That is, if $w = w_1w_2 \cdots w_n$ with $n ≥ 2$ and each $w_i ∈ Σ$, then $C_2(w) = w_3 \cdots w_nw_1w_2$ if n ≥ 3, and $C_2(w) = w$ if $n = 2$. Recall that $w^R$ mean...
Does finding the successor of an element in a heap take $O(\log n)$? An heap is not a binary search tree, so couldn't an element's successor be found in $O(n)$ time?
How does one estimate the access cost for the below query given that the data is sorted according to a non-key attribute, that the data is not uniformly distributed across all possible values of said attribute and that we must use a linear scan? SELECT * FROM EMPLOYEE WHERE DNO = X Context Given the following: Total ...
How to prove In a tree where every node has either $0$ or $2$ children, the number of nodes with $0$ child is $1$ more than the number of nodes with $2$ children.
A sorted array $A[1..n]$ is given. Each element of $A[i]\in \mathbb{N}$, and for each $A[i],A[j]$ we have $A[i]+A[j]\leq n$. Find two elements $A[i], A[j]$ such that $(A[i]-i)+(A[j]-j)=0$. Give a deterministic $O(n)$ time algorithm for this problem. I tackle with this problem as follow : Calculate each $A[i]-i$ , and i...
Is there a well-known or (relatively) easily-implementable streaming algorithm for approximating the median of the last, say, $k$ elements of a stream $c_1,c_2,c_3,\dots$? The scenario is: I have a stream of numbers, and at any point in the streaming process I should be able to query for the (approximate) median in the...
Let H be a class of all functions, mapping M possible keys to N integers. Is it true that H is a 2-universal family? Is it a good idea to use H in applications? I don't even know where and how to start. Can you give me a hint on how to prove this? Is it even possible to prove this?
Suppose there is an n-element stream with elements from $\{0,1\}^\ell$ which means each element is in set $\{0, \dots , 2^\ell-1\}$. Also may assume $2^\ell >n^2$. How can I with $2p$ passes over the data (for $p \in \{1, \dots , 2^\ell\} $) solve the number of distinct elements problem using only $O(\frac{n}{p}\ell)$ ...
Let a non-deterministic machine have at most $2^{t+1}-1$ accepting paths (highest significant bit position is $t$ and lowest significant bit position is $1$). I want to decide if the number of accepting paths $N_{accept}$ is $0$ or $>0$. I can ask a $\oplus P$ oracle to decide if $2^t|N_{accept}$ and $2^{t+1}|N_{accept...
Let a matrix $A=0$. Can I say $A$ is nilpotent? I am asking if the zero matrix is nilpotent or not. Nilpotent means that $A^k = 0$ for some $k$ that is a non-negative integer. When $k = 1$, $A^k = A = 0$. Does this idea support that a zero matrix is nilpotent?
Given that $\mathsf{NP}=\mathsf{PCP}_{[\frac{1}{n},1]}\left(O\left(\log n\right),\left(O(\log n\right)\right)$, show that it is NP-hard to approximate clique up to factor of $n^a$ for some $a \in (0,1)$.
I have six characters: (,),[,],{,}. They are stored lexicographically: '(' < ')' < '[' < ']' < '{' < '}'. So I can store all balanced parenthesis sequences of length $n$ lexicographically and each sequence will have unique number $1 \dots catalan(n)*3^n$. Than I want to get sequence by its number. Problem: If I have an...