computer-science

Generic and practical sorting algorithm faster than O(n log n)?

北城余情 提交于 2020-08-22 04:27:05
问题 Is there any practical algorithm for generic elements (unlike counting sort or bucket sort) that runs faster than O(n log n)? 回答1: Many people have mentioned the information-theoretic Ω(n lg n) bound on comparison sorting algorithms, which can't be broken in comparison sorts. (This earlier question explores why that's the case.) However, there are some types of comparison sorts that, while not breaking O(n lg n) in the average case, can be shown to run faster on inputs that are already

Difference between JUMP and CALL

。_饼干妹妹 提交于 2020-08-20 18:36:31
问题 How is a JUMP and CALL instruction different? How does it relate to the higher level concepts such as a GOTO or a procedure call? (Am I correct in the comparison?) This is what I think: JUMP or GOTO is a transfer of the control to another location and the control does not automatically return to the point from where it is called. On the other hand, a CALL or procedure/function call returns to the point from where it is called. Due to this difference in their nature, languages typically make

Big O Notation - Correct definition for a loop with HashSet lookup

二次信任 提交于 2020-08-05 06:12:22
问题 From my understanding, a simple for loop will have a complexity of O(n). foreach(var record in records) { // ... } If I introduce a Hash lookup within the foreach, will that keep the complexity to O(n)? var ids = new HashSet<int>(); foreach(var record in records) { bool isRecordInIdSet = ids.Contains(record.id); } Likewise, if the HashSet was instead a list, would that make the complexity to O(n^2)? var ids = new List<int>(); foreach(var record in records) { bool isRecordInIdSet = ids

Parsing dice expressions (e.g. 3d6+5) in C#: where to start?

醉酒当歌 提交于 2020-07-31 08:30:10
问题 So I want to be able to parse, and evaluate, "dice expressions" in C#. A dice expression is defined like so: <expr> := <expr> + <expr> | <expr> - <expr> | [<number>]d(<number>|%) | <number> <number> := positive integer So e.g. d6+20-2d3 would be allowed, and should evaluate as rand.Next(1, 7) + 20 - (rand.Next(1, 4) + rand.Next(1, 4)) Also d% should be equivalent to d100 . I know I could hack together some solution, but I also know that this seems like a very typical computer-science type

How to set contents of a file that don't start with “\t” as keys, and those who start with “\t” and end with “\n” as values to the key before them?

旧街凉风 提交于 2020-07-08 00:49:09
问题 I want make a dictionary that looks like this: { 'The Dorms': {'Public Policy' : 50, 'Physics Building' : 100, 'The Commons' : 120}, ...} This is the list : ['The Dorms\n', '\tPublic Policy, 50\n', '\tPhysics Building, 100\n', '\tThe Commons, 120\n', 'Public Policy\n', '\tPhysics Building, 50\n', '\tThe Commons, 60\n', 'Physics Building\n', '\tThe Commons, 30\n', '\tThe Quad, 70\n', 'The Commons\n', '\tThe Quad, 15\n', '\tBiology Building, 20\n', 'The Quad\n', '\tBiology Building, 35\n', '

Are all NP problems also NP-complete?

别等时光非礼了梦想. 提交于 2020-07-04 09:51:47
问题 The definition of NP-complete is A problem is NP-complete if it belongs to class NP all the other problems in NP polynomially transform to it So, if all other problems in NP transform to an NP-complete problem, then does that not also mean that all NP problems are also NP-complete? What is the point of classifying the two if they are the same? In other words, if we have an NP problem then through (2) this problem can transform into an NP-complete problem. Therefore, the NP problem is now NP

What cache coherence solution do modern x86 CPUs use?

主宰稳场 提交于 2020-06-27 16:01:05
问题 I am somewhat confused with what how cache coherence systems function in modern multi core CPU. I have seen that snooping based protocols like MESIF/MOESI snooping based protocols have been used in Intel and AMD processors, on the other hand directory based protocols seem to be a lot more efficient with multiple core as they don't broadcast but send messages to specific nodes. What is the modern cache coherence solution in AMD or Intel processors, is it snooping based protocols like MOESI and