instruction
stringlengths
35
29.1k
I know that 3SAT is npc but i wonder why my little algorithm won't solve this problem: given positive 3SAT - meaning: each of the m clauses is a disjunction of 3 literals over the variables x1,…,xnx1,…,xn (nn variables) and each literal is a positive appearance of a variable (no xi xi). for example: (x1∨x3∨x7)∧(x5∨x4∨...
I recently started learning stuff with bits and now while I was solving one problem, I started thinking what is the most efficient way to calculate $$\lfloor \log_{2}K\rfloor$$ What I started thinking It is clear that we can calculate log in $O(\log K)$. Here is my code for example long long a; long long result = 0; fo...
I am not very familiar with "heuristic", so please correct me if anything said by me is wrong. Per my understanding, Algorithm is an automatic steps which guarantee to give a correct solution corresponding to a specific problem (and its input domain) Heuristic is somehow a rule to guess the next step, hoping when repea...
I recently tried coming up with an algorithm that uses dynamic programming for the counting variant of the change problem. Given a set of target and a set of denominations, print the number of possible combinations that add up to the target. So if my target is 5 and my set is { 1, 2, 5, 10 } then the solution is 4. Mor...
https://en.wikipedia.org/wiki/B-tree#Initial_construction Currently I know of 2 ways for building a B-Tree : bulkloading and just inserting key after key. In the wiki example the keys are sorted, which I guess is a condition for this bulkloading concept. What is the advantage of bulkloading if the keys are unsorted ? ...
The normal tsp seems way harder than the euclidean one, is the euclidean tsp np complete? If so is there a simple reduction that gives an answer to the tsp if you have the euclidean tsp algorithm?
Suppose I'm looking for a some unknown number $x$ in the interval $[a,b]$ under the following assumptions: $x$ is unique. Given any $t \in [a,b]$ I can check, at some fixed computational cost, whether $t>x$. Let's call this operation $C(t)$. Let $\epsilon>0$ be some small number. I'm interested in efficient algorithm...
First of all, I introduce (2,3)-satisfability: Formulas are in CNF form, the special property is that each clause has $2$ or $3$ literals. Formula is satisfied iff only and only if there exists valuation such that: clauses with two literals are treated normally - it sufficient to satisfy one literal (also $2$ litera...
Let $L=\{a^nb^n | n \ge 1\}$, then $L^\star=L^0 \cup L^1 \cup L^2 \cup L^3 \cup \dots = \{\epsilon\} \cup \{a^nb^n\} \cup L^2 \cup L^3 \cup \cdots$ . How to find $L^2$ and $L^3$, and is $L^2=\{a^nb^na^nb^n\}$? In this video https://youtu.be/rnGpW6RRAcw at 31:51, the professor said that $L^2 = \{a^{n_1}b^{n_1}a^{n_2}b^...
Does exist an algorithm to find all equivalence classes of given regular expression without kleene star? If yes then what is it? Note that alphabet of the given regular expression is binary, i.e. it contains only 2 symbols exactly. This is important, because I can easily construct NFA from the given regular expression ...
While there are many types of probing in hash tables, such as linear probing, quadratic probing, and more, I haven't encountered a so-called "hash-probing" (maybe this method which I describe below exits and I just don't know its name, and if that is the case I would love some references). This is the concept: When ...
I have gone through many algorithms including streaming k-means, CluStream etc and they all have their pros and cons. What is the best performing algorithm in terms of Computational Complexity Memory Requirement Quality of Clusters can handle non-static, uncertain data stream Algorithms needs to be online i.e worki...
Lets say we have two wooden planks each 1m long. And we want to have 4 pieces, 60cm 30cm 50cm and 20cm. Is there an algorithm for calculating the least waste? When using brute force it quickly escalates in time :( Formally we have $N$ wooden planks each $L_1, \dots, L_N$ cm long. And we want to have $M$ pieces, $l_1, l...
I am currently working on a computer vision problem that involve 8 convergent cameras. I am trying to recreate a 2D image (I actually don't care of the shape of the image) that is the representation of my scene seen from the 8 convergent cameras (like an above view ?). I am currently working with Real-time Stereo-Image...
I have a directed acyclic graph where the nodes are tasks and the edges are dependency relations between tasks - the edges go from the dependency to the task that depends on it. It is possible that multiple tasks depend on the same parent task and that a task depends on multiple other tasks, so it can be any DAG. I nee...
Given: G(V,E) DAG, vertex s, and function w: V -> R. (the weight on the vertices) Define: We define a weighted path in G as sum of all the vertices weight. Question: Find the heaviest path in G that starts from s. in linear time. Well, first of all we notice it's DAG, so we can use topological sort here. and also. My t...
I know that in order to build i's failure link, I compare i's and j's success links: If they are the same (if a = b), then i's failure link should point to state j + 1. If they aren't the same, we go to the state pointed by j's failure link and do the same. (we stop when we fail at the initial state) How do you comp...
Specifically, we need a Turing machine that on input $1^n$ outputs binary representation of $n$ on output tape in $O(n)$ time. I am not able to get any thing better than trivial $O(n \log n)$ time. Any hints or solution?
Suppose we have a game where there is no good measure of how "far" the target is (that we could use to nudge the agent towards the goal via the immediate returns). If the agent gets only -1 reward per time step and experiencing a full episode where it reaches the goal is extremely improbable (it's equivalent to just bl...
I have a particular problem I need to solve, but I'm not sure how to classify the problem or pick the right algorithm to solve it. I'm hoping someone here can lead me in the right direction. I've generalized and reduced the problem to this: Given an $M \times N$ matrix with elements in $\{0, 1\}$, cover all the $1$ ele...
What is the motivation to pick "value restriction" over other candidates? Examples of alternatives: Enclosing pureness into the function type, for example: pure_function : x -> x impure_function : x => x Polymorphism by name (call by name) as in Xavier Leroy, 1993 Xavier Leroy, 1993. Polymorphism by name for referen...
What is the big-O of the function $2\log(\log(n)) + 3n\log(n) + 5\log(n)$? Is it just $O(n\log(n))$ for the whole function? I'm not sure how to represent $2\log(\log(n))$.
I know this question is trivial. But I am looking for a concise formal definition of $\alpha$-approximation. Is it correct to say that "An algorithm is an $\alpha$-approximation to problem $X$, if for any instance of problem $X$ the solution returned by this algorithm is within a factor $\alpha$ of the optimal solutio...
Assume a binary tree of height N. All nodes have exactly 2 children and all leaves have height N. For example, the following tree has N=3: 3 / \ / \ / \ 2 2 / \ / \ / \ / \ 1 1 1 1 / \ / \ ...
i have a problem solving the recursion $T(n) = T(n-20)+log(n)$, because the Master Theorem is not applicable in this case. This is my attempt: $T(1) = 1$(given) $T(n) = T(n-20)+log(n)$ $T(n) = T(n-20-20)+log(n-20)+log(n) $ ... ... $T(n) = T(n-k)+log(n-(k-20))+....+log(n)$ Let be $ k = n-1$ $T(n) = T(n-(n-1)) +log(n-(n-...
We use a simple uniform hash function to insert 300 keys into two tables of size 1000, we use chaining at one table and linear probing at the other. We are given that the keys were mapped into 290 different cells. What is the expected time of unsuccessful search in each case? I think that the expected time will be 30...
Let's say we have a binary min-heap of size $n$, and we want to get an array of the smallest $\log n$ values in the heap, sorted. What is the best complexity that we can get and how do we implement it? The simplest solution would be using $\text{Get-Min, Delete-Min}$, $\log n$ times, and that would be of time complexit...
I come across the following claim: For all positive, increasing function $f$, $g$, and $h$, if we have $f(n) \in O(g(n) + h(n))$, then we can conclude that either $g(n)\in \Omega(f(n))$ or $h(n) \in \Omega(f(n))$, or both of them are correct. (We say that a function $f$ is positive and increasing, if we can get that $f...
x = n; y = 0 while x >= b: x = x DIV b y = y + 1 return y This function takes in $n,b\in\mathbb{N}, n > 0, b > 1$, and returns $k\in\mathbb{N}$ such that $b^k\leq n \lt b^{k+1}$ So far I think it is: $b^y \leq n$ $x \leq n$ but now I'm stuck
I'm going through a hackerrank challenge on recursion https://www.hackerrank.com/challenges/ctci-recursive-staircase and I'm having difficulty understanding how the solution below solves the problem. Here's the tree (the recursion calls) like you would with the fibonacci problem but I don't see the insight With N = 3 ...
What does connected components mean in the context of non-graphs? Graphs have vertices and the vertices are connected by edges. Hence, you can build a spanning tree (for example) by systematically joining connected components (where connected components refer to connected subgraphs). Previous discussion on this topic ...
I have an array of words with their coordinates in the document, I want to turn them into sentences. For example this: [ { "bounds": [ { "x": 10, "y": 10 }, { "x": 15, "y": 10 }, { "x": 15, ...
Problem statement: You are in an infinite 2D grid where you can move in any of the 8 directions : (x, y) to (x+1, y), (x-1, y), (x, y+1), (x, y-1), (x-1, y-1), (x+1, y+1), (x-1, y+1), (x+1, y-1) You are given a sequence of points. Give the minimum number of steps in which you can cover all of them. You st...
Let's consider the language over $\{0,1\}$ containing such words $w$ that: $$w = m_1m_2..m_n $$ where $m_i$ has length $n$. (so $|w|=n^2$) and $$m_1 + m_2 + .. + m_n \mod 3 = 0$$ ($m_i$ we interpret as binary encoded number). Prove, that the language is $NC^1$ class. The first problem is: How to decide whether $m_...
i have to calculate the asymptotic runtime of a nested sum: Sum $\sum_{n=1}^{log_{4}(n)} \sum_{n=1}^{\sqrt{n}}1$ My solution is $\Theta(log(n) \cdot \sqrt{n})$, which is wrong, because the solution says $\Theta(\sqrt{n})$. I dont understand where my mistake is: Sum $\sum_{i=1}^{log_{4}(n)} \sum_{j=1}^{\sqrt{n}}1 = \su...
I believe that in the general case stable matching for 3 members rather than 2 is NP-Complete, but I wonder if in my case there's something that I am missing that could have reasonable time complexity. The specific purpose of the program I am trying to write is to take an arbitrary number of objects and split them int...
I read that system being in safe state doesn't guarantee that deadlock is not possible. Can someone give me an example where system is in safe state and deadlock is possible?
I'm looking for a small function from integers to integers - in a language that only has floats - that can act as a visual RNG. Normally I would use a function such as the one described here: int cash(int x, int y){ int h = seed + x*374761393 + y*668265263; //all constants are prime h = (h^(h >> 13))*1274126...
Given a hash function $H:\{0,1\}^*\rightarrow\{0,1\}^n$, a difficulty $d\in\mathbb{N}$, and data $D\in\{0,1\}^*$, the framework of the Hashcash/Bitcoin Proof-of-Work entails finding a nonce $c$ such that $H(c\Vert D)$ starts with $d$ zero’s. That is to say, Hashcash/Bitcoin Proofs-of-Work appear to find a preimage $c\...
Suppose I want to find the numbers that appear in at least 3 of the 10 sorted lists, is there an efficient way to do it apart from iterating over all 10 of them in parallel?
I am contemplating the project of writing a compiler. I am wondering if, aside from the availability of easy google results, it is easier to write a compiler for a more explicit/verbose language such as ada, compared to a very compact language such as APL, for example. I should add that i am especially interested in wh...
Can the HTML5 parsing algorithm (https://html.spec.whatwg.org/multipage/parsing.html#parsing) be implemented in $O(n)$, or at worst $O(n\mathop{log}n)$, time, even for malicious input? It seems difficult; there appear to be places where a malicious document could force the user agent to perform $O(n)$ traversals $O(n)...
I am wondering if a pair prefix/AS may change often ? I mean let's say we have a list with many given prefixes (e.g. 4.6.20.0/24) that are mapped to ASN (e.g. 10753), this list is built on a given date. The question is, should we expect that several prefixes are mapped to other ASN in a list built few days later ? I ...
The class DP is defined as the set of all languages $L$ such that $L = L_1 \cap L_2$ where $L_1 \in NP$ and $L_2 \in coNP$. For example, the language SAT-UNSAT is defined in the following manner ($\varphi$ is a $3-CNF$ formula): $\{( \varphi, \varphi'): \varphi \in SAT \wedge \varphi ' \in UNSAT \}$. This language is t...
Actually I found that the set of context-sensitive Languages, $\mathbf{CSL}$ ($\mathbf{=NSPACE(O(n)) = LBA}$ accepted languages) are not so widely discussed as $\mathbf{REG}$ (regular languages) or $\mathbf{CFL}$ (context-free languages). And also the open problem $\mathbf{DSPACE(O(n))} =^{?} \mathbf{NSPACE(O(n))}$ is...
I have been working in the Welder theorem prover for some time now. But I'm confused in the way they handle data-types. I'm not familiar with the terminology of sorts and constructors. Here is how one defines a list data-type in the system: val list = mkSort("A")(Seq(cons, nil)) val nil = mkConstructor("A")(Some(list))...
I am reading Turing's "Computing machinery and intelligence" paper (https://www.csee.umbc.edu/courses/471/papers/turing.pdf) and found a fragment in which he says: I have set up on the Manchester computer a small programme using only 1,000 units of storage, whereby the machine supplied with one sixteen-figure number r...
I've struggling with this problem for a while. Given text $T=t_1t_2\ldots t_n$ and pattern $P=p_1p_2\ldots p_m$ over alphabet $\Sigma=\mathbb{N}$, we say there's a block matching of $P$ in index $i$ if there exist $m$ successive blocks $S_1,\ldots,S_m$ such that $$p_1=\sum_{s_1 \in S_1}s_1 \land p_2=\sum_{s_2 \in S_2}s...
Given Directed Graph G(V,E) with red/black vertices, v is "good" if there's a path from v to a black vertex. in linear time. Question: Find all the good vertices in the graph I've come up with an algorithm which almost works. Run SCC on G. Sort topologically. Run from the last SCC till the first SCC. If we find a blac...
I know that if a language class is closed under operation X then the problem is decidable. for eg: "Intersection of two CSL is CSL"? this problem is decidable because it is already proved that CSL follow intersection closure property. But what if language is not closed under the operation. for eg: problem: Is intersec...
There is given input - words is sequence of numbers: $w_i$ is number in sequence, $i$ is position. All of them are in written in binary system. $$w_1\#,...\#w_k\#i$$ Prove that there exists deterministic Turing machine which find $i$-th number in sorted sequence $w$ in logspace. I am not sure if I cor...
I am looking for an answer regarding the CPU read and write. We know there are two clocks that are working in the computer system, one is the peripheral clock and the other is the CPU own clock on which its control systems are working. I am familiar with the clock domain crossing but I dont understand how the CPU read ...
How BDI (Beliefs-Desires-Intentions) agent models is connected with PSI agent model http://cognitive-ai.com/ (and https://en.wikipedia.org/wiki/Psi-theory)? Is one of the models the generalization of the other? PSI model seems to be more sophisticated but it may lack (at present) all the logical foundations and reasoni...
I have a programming problem, instead of describing the whole domain it's easier for me to create an analogy. The numbers I use in this example are completely arbitrary. Your cousin is coming over later and you must feed him dinner. He will only eat what he randomly decides he wants when he gets to your house and will ...
This question: Chernoff bound when we only have upper bound of expectation is similar, but for an upper bound of expectation. The standard Chernoff bound says that is $X$ is a sum of 0/1 random variables, then, for any $\delta \in (0,1)$, $P(X \leq (1-\delta) E(X)) \leq e^{-\frac{\delta^2 E(X)}{2}}$. Suppose we only h...
I have some sets (A, B, ...) each containing some vectors (e.g. [1, 0, -1]). How can I pick exactly one vector per set such that they sum to a specified target vector? For example: A: { [1, 0, -1], [3, 0, 0], ... } B: { [0, -1, -1], [2, -1, 0], ... } Target: [3, -1, -1] Solutions: 1) A=[1, 0, -1], B=[2, -1, 0] 2) A=...
I am looking for the canonical implementation of the "k-combinations with repetition" algorithm. Simple Example: Input: "ABC" (choose 2) ['AA', 'AB', 'AC', 'BB', 'BC', 'CC'] I have a recursive implementation, I'm looking for the performance optimized state of the art version. Usually people mention Knuth for this...
Algorithm to distribute elements evenly among a population In the software I am doing I have three different categories: Maize: 1- Variety A 2- Variety B 3- Variety C 4- Variety D 5- Variety E 6- Variety F 7- Variety G Fertilizer: 1- Type A 2- Type B 3- Type C 4- Type D Manag...
I have logs of activities without labels, which describe whether an activity is normal or not. Assuming that normal behaviors will follow a Gaussian distribution, I fit Gaussian distributions on dataset. I utilized this to generate a synthetic dataset with abnormal patterns. Then, according to the literature review, I ...
I am trying to implement an algorithm called the 'rapidly exploring random belief tree'. The aim of this algorithm is to come up with a path for a robot, which, instead of connecting start and goal with a least distance metric or something similar, drives the robot into areas where it can get high accuracy measurements...
Given a set $\{1,\ldots,ck\}$, is there a known algorithm to efficiently list all partitions in with $c$ blocks of cardinality $k$? In The art of computer programming (Fascicle 3B) by Knuth, there's a mention of an algorithm by Ruskey that can list all partitions with $c$ blocks. I could just use this algorithm and dis...
I'm pretty new to CFG, and I've tried out some samples as well. As of now I'm trying this for-loop to write it in CFG using BNF: Start{ int z = 20; for(int b = 0; b < 5; b++) { //some statement } } Attempted BNF: <program> ::= Start <blockstatements> <blockstatements> ::= <statement> | <state...
I'm trying to practice some combinatorics and I faced this problem, let's say we have given graph with N nodes and M edges. $$N\leq500, M \leq N\cdot(N - 1)/2$$ In this graph I want to count the sub-sets of edges such that each subset will have exactly $N-1$ edges and the edges forming the subset will form connected gr...
Given is a set of points $P_{1},....,P_{n}$ with $P_{i} = (x_{i},y_{i})$. No two points have the same x and y coordinates. Given is also a set of m axis-parallel rechtangles $R_{1},...,R_{m}$ in a plane, described by their bottom left corner $(l_{j},b_{j})$ and upper right corner $(r_{j},u_{j})$. No two rechtangles int...
I am trying to implement a trigram HMM tagger for a language that has over 1000 tags. In my training data I have 459 tags. Now if we consider that states of the HMM are all possible bigrams of tags, that would leave us with $459^2$ states and $(459^2)^2$ transitions between them, which would require a massive amount of...
I am sorry if I sound repetitive(I've asked a similar sounding question earlier - Relevance of memory reads while calculating the time complexity of an algorithm). Actually, it didn't answered my intended query. May be I framed the question inappropriately, and in an unnecessarily complex and indirect way. In the curre...
I have an exercise where one is supposed to give a function that will enumerate the following language: $L_1 = \{ a^pb^p \hspace{1mm} |\hspace{1mm} p \in \mathbb{N} \hspace{1mm} \wedge \text{ (P is a prime number )} \}$. The solution is the following function: $f: \mathbb{N} \rightarrow \Sigma^*$ with $f(i) = a^{p_{...
A single-tape Turing machine $M$ has the property that, for every input $w$, during the first $2 |w|$ steps, the head of $M$ moves only right (it does not move left nor stays in place); the machine is also allowed to halt at any moment during these first $2|w|$ steps. Prove that the language of $M$ is in $DTIME(n)$. Pe...
My question is as follow. Imagine a random shape cluster of high dimension in an euclidian space, how can i get points which are at the edge of the cluster where edge are defined as segments connecting outermost points. I can imagine to compute the similarity matrix and get points which are the most distant from others...
Let's suppose there are N processes and we have the following code: atomic <int> c = 0; semaphore b = 0; proc P(i){ ... if(c.getAndInc() < N - 1){ b.wait(); } else{ b.signal(); } ... } A deadlock will occur as N - 2 processes will be blocked by $ b.wait() $. I'm trying to identify how th...
I have a directed, weighted graph with no double edges. Each node represents a person, and each edge represents a debt. I want to reduce the total number of transactions required to settle all debt, i.e. have the smallest number of edges while maintaining fairness. I've noticed that you can eliminate edges when you owe...
Suppose I have two processes of 50 bytes and have only one partition (hole) of 100 bytes. Suppose the first process takes up the partition and 50 bytes is remaining . Can the second process reside in the same partition even if free space is available or will internal fragmentation occur in case of first fit? Also is it...
i know that resources duplicate is solution to Structure Hazard but what about code scheduling .... Can code scheduling considered as a solution to Structure Hazard ? with Example please .
Let's say we have number 4920 and we want to find the closest $n^x$ to 4920 2 ^ 12 = 4096 but it's not the closest possible $n^x$, for example 17 ^ 3 = 4913 is closer to 4920 The question is, how do we find the closest $n^x$, where $n$ and $x$ are less than 2 digits long? (because $4913^1$ is not what I want)
Everyone keeps claiming that integer factoring is in $NP$ but I just don't get it... Even with the simplest algorithm (division with all integers up to $\sqrt{n}$) the complexity should be $\sqrt{n}\log(n)$... How is that not in $P$? Is there something I'm missing?
Can someone help with this $L= \{a^ib^j | 2i \leq 2j \leq 3i, i>0\}$
(weak) Church-Turing thesis states every physically realizable computation device can be simulated by a Turing machine (not necessarily efficiently). (1) Then Does any model that is not physically realizable and cannot be simulated by Turing machine? (2) Is there any evidence for this thesis?
I was reading about Amdahl's law and it state that value of Amdahl's law always lies between 0 and 1. My question is, is it still true in today's case/scenario? When we have system like core i7?
Context I'm working on load-balancing traffic between client and server nodes. Assumptions: every server has a static weight that represents its computational power: $W^0_i$ we are able to measure with reliability the latency between a client and a server ($rtt_i(j)$ is the latency to reach server $j$ from client $i$)...
Assume my language is $$ L= ww^{r}\ $$ Now when we use NPDA for this,we will guess middle every time. It may be actual middle or it may not, so a new branch is created every time as I have a choice here. Now each branch will get the current stack contents and start its operation. So my question is, do these branches ...
I have a few math courses to pick from in my studies, and I would love some insights on which math courses from the following list are the most relevant for machine learning. I will note - to avoid this question being closed on "opinion based" cause, that my question does not involve which math courses I like or intere...
I was looking at this picture: https://upload.wikimedia.org/wikipedia/commons/thumb/a/a2/Automata_theory.svg/640px-Automata_theory.svg.png Which made me think, that if all Turing Machines PDA's and FSA's recognize certain sets of languages, there has to be a set of languages which is recognized by Combinational Logic c...
When I send a message from one device to another, during the process during which the other device is receiving the data, is that data stored temporarily on some place on the device or is it immediately stored on the hard-drive of the device. and while using TCP when you receive an ACK does this mean that that data has...
Assume language $L$ as follow:- $$ L = \{ a^n b^x c^m d^y | (n=m) \lor (x=y)\} $$ Is it possible to design DPDA/NPDA for this? I know if the condition would have been "and" then it is not possible. But is it possible with "or"? My approach:- 1. Push all $a$'s to the stack. At $b$ define non deterministic behavior as f...
I have already defined here what is minimal 3CNF formula. In the answer to the question, D.W. answered: What you are thinking is wrong. A minimal, unsatisfiable formula can have more than 8 clauses. In response to: In a minimal k-cnf formula, there should be 2k different k literals clauses exactly, so in a minimal 3CNF...
I've recently been thinking about this problem. Given an array $A$ containing $n$ integers and an index $i$, find the number of subgements of $A$ containing $A[i]$ as their minimum. To better illustrate the problem, consider the array $A = [5, 1, 7]$ and we want to find the number of subsegments containing $A[1] = 1$ a...
Is there any literature / research on the average size efficiency of stacks vs queues? I asked because I was recently working on a problem where, if using a queue, the size quickly blew up and the computer ran out of memory. If I used a stack the size stayed very small. I think the reason in this case was that the se...
I need to figure out the complexity of the following loop in theta notation but I can't figure it out. Some help would be much appreciated. from j := 1 until j > n loop from k := 1 until k > n*n*n loop k := k + j end j := j + 2 end some help with an explanation would be much appreciated. The solutions state ...
This question is referring to the Pumping Lemma for CFLs, namely: If $L$ is a CFL, there is a pumping length $p$ such that any string $z \in L$ of length $\geq p$ can be written as $z = uxwyz$, where $|xy| \geq 1$, $|vxy| \leq p$, and $\forall i ≥ 0, ux^iwy^iz \in L$. Let's say we have a language consisting of $0$s ...
I have an Approximation Algorithm problem and its answer but I am having a hard time to clearly understand. The problem is as follows: Consider the following closest-point heuristic for building an approximate traveling-salesman tour whose cost function satisfies the triangle inequality. Begin with a trivial cycle co...
It's fair to summarize classes in OOP as "product types with functions." However, couldn't there be something like "sum types with functions"? How would inheritance work with them? I'm trying to scout if anybody has considered this question before in language design.
using luhns credit card check algorithm why is digits with 7 length allowed ? for example 1111111 is a verfied credit card number meaningly if it has only six digits its not. this does not look like a credit card number to me, am i missing something ? go to any online credit card validation site and try 1111111 and se...
I asked this in stackoverflow, but the question probably fits here better. This question arose from the objection that LISP is regarded as a functional language with some simple principles, namely functions, variables, and operators that roughly correspond to predicates, propositional variables, and connectives in logi...
I thought this problem had a trivial solution, couple of for loops and some fancy counters, but apparently it is rather more complicated. So my question is, how would you write (in C) a function traversal of a square matrix in diagonal strips. Example: 1 2 3 4 5 6 7 8 9 Would have to be traversed in the following orde...
I have this problem to resolve in dynamic programming: An ice cream shop owner has 4 stores. To meet the demand in the summer he purchased 7 refrigerators for the ice cream. Because the stores are in different places, there are different points for selling the ice cream. It was estimated the profit (in monetary unit) ...
Hi I would like to create a self-affine fractal on L-Systems. The axiom I have created is FF-GGG-GG-GGG++GGG+GG-GGG+GG+GGG+FF++ffGG+GGG+FF+GGG which creates the image below At each stage I would like to replace each rectangle with the initial pattern. I am not sure how to do this.
Prove that for every two positive functions $f(n),g(n)$: $$ \max(f(n),g(n)) = \Theta(f(n)+g(n)). $$ I've just started data structures and I barely understand it, so please be gentle with me.
I've read about basic planar-graph embedding and about embedding a planar graph onto a set of fixed points, but I was wondering how one might constrain the locations of some nodes—perhaps to a set of points—while allowing others complete freedom. Is this achievable with a current popular algorithm, or with minor modifi...
I understand that for a problem to be solvable using dynamic programming, it needs to have the following properties: optimal substructure overlapping subproblems I stumbled upon an article which states that: Counting problems cannot exhibit optimal substructure, because they are not optimization problems. Instead, t...
The modern definition of computable functions $f\colon \mathbb N \to \mathbb N$ as given on Wikipedia quite naturally describes partial functions, and not just total functions. Now I am reading some historical references, and before and around the 1930's people just seemed to be concerned with total computable function...