theory

Did you apply computational complexity theory in real life?

╄→гoц情女王★ 提交于 2019-11-28 18:59:12
问题 I'm taking a course in computational complexity and have so far had an impression that it won't be of much help to a developer. I might be wrong but if you have gone down this path before, could you please provide an example of how the complexity theory helped you in your work? Tons of thanks. 回答1: O(1): Plain code without loops. Just flows through. Lookups in a lookup table are O(1), too. O(log(n)): efficiently optimized algorithms. Example: binary tree algorithms and binary search. Usually

Recursive set union: how does it work really?

余生颓废 提交于 2019-11-28 18:40:56
I am currently taking the Scala course on Coursera on my free time after work, in an attempt to finally give a try to functional programming. I am currently working on an assignment where we are supposed to "calculate" the union of two sets that contain some object. I am intentionally omitting details as it's not really important to what I am trying to ask here. What is relevant, however, is that the sets are defined as binary trees, with each node containing an element, and two subtrees. That being the case; the example union in the lecture is as follows: def union(other:BTSet) :BTSet = (

Is the time complexity of the empty algorithm O(0)?

只谈情不闲聊 提交于 2019-11-28 16:38:20
So given the following program: Is the time complexity of this program O(0)? In other words, is 0 O(0)? I thought answering this in a separate question would shed some light on this question . EDIT: Lots of good answers here! We all agree that 0 is O(1). The question is, is 0 O(0) as well? andand From Wikipedia : A description of a function in terms of big O notation usually only provides an upper bound on the growth rate of the function. From this description, since the empty algorithm requires 0 time to execute, it has an upper bound performance of O(0). This means, it's also O(1), which

What is fuzzy logic?

五迷三道 提交于 2019-11-28 16:12:09
I'm working with a couple of AI algorithms at school and I find people use the words Fuzzy Logic to explain any situation that they can solve with a couple of cases. When I go back to the books I just read about how instead of a state going from On to Off it's a diagonal line and something can be in both states but in different "levels". I've read the wikipedia entry and a couple of tutorials and even programmed stuff that "uses fuzzy logic" (an edge detector and a 1-wheel self-controlled robot) and still I find it very confusing going from Theory to Code... for you, in the less complicated

How to write a simple database engine [closed]

删除回忆录丶 提交于 2019-11-28 14:55:41
I am interested in learning how a database engine works (i.e. the internals of it). I know most of the basic data structures taught in CS (trees, hash tables, lists, etc.) as well as a pretty good understanding of compiler theory (and have implemented a very simple interpreter) but I don't understand how to go about writing a database engine. I have searched for tutorials on the subject and I couldn't find any, so I am hoping someone else can point me in the right direction. Basically, I would like information on the following: How the data is stored internally (i.e. how tables are represented

Steps to creating an NFA from a regular expression

人盡茶涼 提交于 2019-11-28 14:54:26
问题 I'm having issues 'describing each step' when creating an NFA from a regular expression. The question is as follows: Convert the following regular expression to a non-deterministic finite-state automaton (NFA), clearly describing the steps of the algorithm that you use: (b|a)*b(a|b) I've made a simple 3-state machine but it's very much from intuition. This is a question from a past exam written by my lecturer, who also wrote the following explanation of Thompson's algorithm: http://www.cs.may

Make java methods visible to only specific classes

无人久伴 提交于 2019-11-28 12:40:30
I have a manager class that is responsible for managing Objects of a certain kind. To do so it needs to manipulate these Objects, but these Objects have no relation to the manager whatsoever, so design technically, they are in separate packages "project.managers" and "project.objects" . The important thing is that the Objects in question should only be manipulated by the managers and nowhere else, but need to be accessible by every other class in the project. As such I'd like to have the managers have access to manipulating methods, but restrict access to every other class. The most obvious

Number theory

自古美人都是妖i 提交于 2019-11-28 12:18:54
题目链接 神奇题目,卡scanf的答案错误和ios::sync_with_stdio(false);的时间超限。 思路:针对一个数组的操作,即对一个区间。可以用线段树去进行维护。初始化建树,叶子节点的值为1,维护每段区间上各个元素的乘积sum。M yi,将第i个元素的值改为yi。N di,将第di个元素的值改为1。输出即查询区间[1,Q]的sum值。也就是变成了单点更新、区间查询问题。 #include<cstdio> #include<cstring> #include<queue> #include<cmath> #include<algorithm> #include<map> #include<vector> #include<string> #include<set> #include<iostream> #define ll long long #define lson p<<1 #define rson p<<1|1 using namespace std; const int maxn=1e5+100; ll mod; struct node { int l,r; ll sum; }t[maxn<<2]; void pushup(int p) { t[p].sum=(t[lson].sum*t[rson].sum)%mod; } void build(int p

Alternative Entropy Sources

荒凉一梦 提交于 2019-11-28 12:00:21
Okay, I guess this is entirely subjective and whatnot, but I was thinking about entropy sources for random number generators. It goes that most generators are seeded with the current time, correct? Well, I was curious as to what other sources could be used to generate perfectly valid, random (The loose definition) numbers. Would using multiple sources (Such as time + current HDD seek time [We're being fantastical here]) together create a "more random" number than a single source? What are the logical limits of the amount of sources? How much is really enough? Is the time chosen simply because

Are the grammars of modern programming languages context-free or context-sensitive?

假装没事ソ 提交于 2019-11-28 11:11:52
Are the C++, C# or Java languages context-free or context-sensitive? C++ is neither context-free nor context-sensitive, since the template system is Turing-complete and determining whether a piece of C++ code is legal C++ is undecidably hard. For example, I could define a template class that simulates a TM on a string and then creates a constant with value 1 if the machine accepts and 0 if it does not. If I did that, then the following code would be legal iff the TM halted on the given input: int myArray[TMTemplate</* ... args ... */>::value]; Since if the TM rejects, this creates an array of