theory

What use cases are there for defining a new root class?

两盒软妹~` 提交于 2019-11-27 03:22:38
问题 We know that in Objective-C there are two main root classes: NSObject and NSProxy . There are other roots (mainly for private and legacy purposes) like Object , and NSLeafProxy . Defining a new root is fairly trivial: @interface DDRoot <NSObject> @end @implementation DDRoot //implement the methods required by <NSObject> @end My question is: why would you ever want to define a new root class? Is there some use-case where it's necessary? 回答1: As far as I can tell, there should be no reason for

Why is cloning (in .NET) so difficult?

不羁岁月 提交于 2019-11-27 03:09:14
问题 In the past I had the need to clone objects, only to find that they don't implement a Clone() method, forcing me to do it by hand (create a new instance and copy all properties from the original to the new one) Why isn't cloning as easy as duplicating the memory block the object is allocated in, and thus have the Clone method in the object class, having all classes in .NET inherit it? 回答1: Because that wouldn't perform a deep clone, which is usually what clones really need to be. Imagine you

Algorithm to print out a shuffled list, in-place and with O(1) memory

寵の児 提交于 2019-11-27 02:16:59
问题 After reading this question I started to wonder: is it possible to have a shuffling algorithm which does not modify or copy the original list? To make it clear: Imagine you are given a list of objects. The list size can be arbitrary, but assume it's pretty large (say, 10,000,000 items). You need to print out the items of the list in random order, and you need to do it as fast as possible. However, you should not: Copy the original list, because it's very large and copying would waste a LOT of

Calling base class overridden function from base class method

浪子不回头ぞ 提交于 2019-11-27 01:17:19
public class A { public void f1(String str) { System.out.println("A.f1(String)"); this.f1(1, str); } public void f1(int i, String str) { System.out.println("A.f1(int, String)"); } } public class B extends A { @Override public void f1(String str) { System.out.println("B.f1(String)"); super.f1(str); } @Override public void f1(int i, String str) { System.out.println("B.f1(int, String)"); super.f1(i, str); } } public class Main { public static void main(String[] args) { B b = new B(); b.f1("Hello"); } } I'm seeking that this code would output: B.f1(String) A.f1(String) A.f1(int, String) Yet I'm

Does an algorithm exist which can determine whether one regular language matches any input another regular language matches?

醉酒当歌 提交于 2019-11-27 01:07:49
问题 Let's say we have regular expressions: Hello W.*rld Hello World .* World .* W.* I would like to minimize the number of regexes required to match arbitrary input. To do that, I need to find if one regular expression matches any input matched by another expression. Is that possible? Billy3 回答1: Any regular expression can be linked to a DFA - you can minimize the DFA and since the minimal form is unique, you can decide whether two expressions are equivalent. Dani Cricco pointed out the Hopcroft

Is finding the equivalence of two functions undecidable?

一个人想着一个人 提交于 2019-11-27 01:02:17
Is it impossible to know if two functions are equivalent? For example, a compiler writer wants to determine if two functions that the developer has written perform the same operation, what methods can he use to figure that one out? Or can what can we do to find out that two TMs are identical? Is there a way to normalize the machines? Edit: If the general case is undecidable, how much information do you need to have before you can correctly say that two functions are equivalent? Given an arbitrary function, f , we define a function f' which returns 1 on input n if f halts on input n . Now, for

Difference between convergence and idempotence in Chef

梦想的初衷 提交于 2019-11-27 00:57:46
问题 What is the basic difference between convergence and idempotence in Chef? 回答1: Convergence and idempotence are not Chef-specific. They're generally attributed to configuration management theory, though have use in other fields, notably mathematics. Let's start with the more basic, idempotent. We're going to ignore the mathematic use of idempotent, and focus instead on what configuration management people mean when they talk about it. That is: "multiple applications of the same action do not

How to determine whether a language is LL(1) LR(0) SLR(1)

半世苍凉 提交于 2019-11-27 00:55:34
问题 Is there a simple way to determine whether a grammar is LL(1), LR(0), SLR(1)... just from looking on the grammar without doing any complex analysis? For instance: To decide whether a BNF Grammar is LL(1) you have to calculate First and Follow sets - which can be time consuming in some cases. Has anybody got an idea how to do this faster? Any help would really be appreciated! 回答1: First off, a bit of pedantry. You cannot determine whether a language is LL(1) from inspecting a grammar for it,

Graph Theory: Representation and Algorithms

假如想象 提交于 2019-11-27 00:15:11
Summer Project - 2019 Graph Theory: Representation and Algorithms 1 Introduction In order to complete this project successfully, the student should be familiar with many basic notions of graph theory. The questions below whose answers should be included in the project report will force the student to go over these necessary background notions about graphs. Most of the background can be studied in the following references, specially Cormen textbook where graph definitions can be found in Appendix B.4 and the Graph Algorithms can be read in chapters 22 to 26. 1. Introduction to Algorithms, T.H.

What is the Zipper data structure and should I be using it?

耗尽温柔 提交于 2019-11-27 00:13:39
问题 The question is simple: I cannot understand the Zipper data structure. My question is related to its uses with a Tree. I want to understand how can I change the tree node using zipper. And how not to copy the whole tree (or the most part of it). Please, clarify if I'm wrong with zipper. Maybe it cannot help with the tree update? Or, maybe, it is possible to update the tree and I just cannot see the way? 回答1: Let's start with the Zipper-analog for lists. If you'd like to modify the nth element