theory

Help with the theory behind a pixelate algorithm?

假如想象 提交于 2019-12-09 13:15:51
问题 So say I have an image that I want to "pixelate". I want this sharp image represented by a grid of, say, 100 x 100 squares. So if the original photo is 500 px X 500 px, each square is 5 px X 5 px. So each square would have a color corresponding to the 5 px X 5 px group of pixels it swaps in for... How do I figure out what this one color, which is best representative of the stuff it covers, is? Do I just take the R G and B numbers for each of the 25 pixels and average them? Or is there some

Visitor pattern. Is void* an acceptable return type for a completely abstract interface?

放肆的年华 提交于 2019-12-09 12:16:19
问题 I have an AST, represented in the usual way (a tree of nodes of an abstract type). I have several uses cases for traversing this tree (an optimizer, which returns another AST; IR code generation, which returns a llvm::Value* ; and a debug analyzer, which simply outputs to stdout and returns nothing). A visitor feels like the right way to go here, but the differing return types through each use case of the visitor make it hard to see how to implement an interface for this. I considered this:

Basic programming/algorithmic concepts [closed]

寵の児 提交于 2019-12-09 08:04:02
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm about to start (with fellow programmers) a programming & algorithms club in my high school. The language of choice is C++ - sorry about that, I can't change this. We can assume students have little to no

What are the consequences of saying a non-deterministic Turing Machine can solve NP in polynomial time?

余生颓废 提交于 2019-12-09 04:44:40
问题 these days I have been studying about NP problems, computational complexity and theory. I believe I have finally grasped the concepts of Turing Machine, but I have a couple of doubts. I can accept that a non-deterministic turing machine has several options of what to do for a given state and symbol being read and that it will always pick the best option, as stated by wikipedia How does the NTM "know" which of these actions it should take? There are two ways of looking at it. One is to say

Algorithm: for G = (V,E), how to determine if the set of edges(e belong to E) is a valid cut set of a graph

廉价感情. 提交于 2019-12-09 01:44:08
问题 Given a subset of edges of a graph G = (V,E), how can we check whether it is a valid cut-set of the graph or not? Note: A cut is a partition of the vertices of a graph into two disjoint subsets. So, cut-set of the cut is the set of edges whose end points are in different subsets of the partition. I am interested to find an algorithm for this problem 回答1: A simple algorithm would be to remove the suspected cut-edges from the graph, and see if you can still get from a node of a removed edge to

Why don't we have a // comment in CSS? [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-08 14:34:14
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why do /**/ comments work in stylesheets but // comments don't? In CSS there is only one way to create comments: /* I'm a comment */ The problem is that it isn't nestable. Does anyone know why we don't have an alternative comment syntax like // ? 回答1: I think the real answer is that CSS treats newlines like any other whitespace, so it wouldn't make sense to have comments that are terminated by a newline. This is

Finding “strongly connected” subgraphs in a Graph

半城伤御伤魂 提交于 2019-12-08 09:47:45
问题 I am trying to find an algorithm to find the sub graphs in a undirected connected graph, where each vertex in the subgraph has an edge to every other vertex in the subgraph. My real problem is that I am having trouble classifying this problem, so that I can research possible algorithms or solutions. Would anyone know what this problem is called or is there any existing algorithms that achieve this? 回答1: I believe that you are referring to the Clique problem. 回答2: Hmm, I believe I encountered

grundy's game dividing a pile into two unequal piles

◇◆丶佛笑我妖孽 提交于 2019-12-08 03:24:28
问题 I have come across a problem. There are N piles of stones where the ith pile has xi stones in it. Alice and Bob play the following game: a. Alice starts, and they alternate turns. b. In a turn, a player can choose any one of the piles of stones and divide the stones in it into any number of unequal piles such that no two of the piles you create should have the same number of stones. For example, if there 8 stones in a pile, it can be divided into one of these set of piles: (1,2,5), (1,3,4),

Color Remapping - Matching target palette using a 3D grid?

孤街浪徒 提交于 2019-12-08 02:39:33
问题 Let's say I have color 'FOO', and it is stored in RGB format. I need to recolor 'FOO' so it matches the closest color in a list of colors. Doing this on the fly, couldn't I view the RGB values from each color as points on a 3D grid (r=x, g=y, b=z) and compute the distance between point 'FOO' vs the points from each color in the list? The closest point to 'FOO' would be the replacement color? 回答1: In theory, yes. In reality, computing the closest color is non-trivial if you want to do it well.

how to prove 2 sql statements are equivalent

只愿长相守 提交于 2019-12-08 00:11:32
问题 I set out to rewrite a complex SQL statement with joins and sub-statements and obtained a more simple looking statement. I tested it by running both on the same data set and getting the same result set. In general, how can I (conceptually) prove that the 2 statements are the same in any given data set? 回答1: I would suggest studying relational algebra (as pointed out by Mchl). It is the most essential concept you need if you want to get serious about optimizing queries and designing databases