computer-science

Find row of pyramid based on index?

跟風遠走 提交于 2019-12-05 16:27:25
Given a pyramid like: 0 1 2 3 4 5 6 7 8 9 ... and given the index of the pyramid i where i represents the i th number of the pyramid, is there a way to find the index of the row to which the i th element belongs? (e.g. if i = 6,7,8,9 , it is in the 3rd row, starting from row 0) There's a connection between the row numbers and the triangular numbers. The nth triangular number , denoted T n , is given by T n = n(n-1)/2. The first couple triangular numbers are 0, 1, 3, 6, 10, 15, etc., and if you'll notice, the starts of each row are given by the nth triangular number (the fact that they come

Dependencies Tree Implementation

左心房为你撑大大i 提交于 2019-12-05 15:46:25
For those who used apt-get, you know that everytime you install / uninstall something, you get the notificatons saying you need / no longer need certain dependencies. I'm trying to understand the theory behinds this and potentially implement my own version of this. I've done some googling, came up with mostly coupling stuff. From what I understand, coupling is 2 classes/modules that depends on each other. This is not exactly what I'm looking for. What I'm looking for is more like a dependencies tree generation, where I can find the least dependent module (I've already made a recursive way of

What's the fastest heuristic algorithm to split students into groups?

a 夏天 提交于 2019-12-05 13:47:16
I have X number of students, where X is a multiple of 6. I now want to split up the students into groups of 6. I have a function that measures how "good" a group of 6 is (lets say it's a black box that runs in constant time for now). By splitting up the students, and then calling my function on each group to measure it's goodness, and then summing up the goodness of each group, I'm able to measure how "good" a certain set of groups is. I'm trying to create an algorithm that will group the students in a way so that the total goodness of all the groups is maximized, and no group has an

GCC couldn't vectorize 64-bit multiplication. Can 64-bit x 64-bit -> 128-bit widening multiplication be vectorized on AVX2?

孤人 提交于 2019-12-05 11:57:54
I try to vectorize a CBRNG which uses 64bit widening multiplication. static __inline__ uint64_t mulhilo64(uint64_t a, uint64_t b, uint64_t* hip) { __uint128_t product = ((__uint128_t)a)*((__uint128_t)b); *hip = product>>64; return (uint64_t)product; } Is such a multiplication exists in a vectorized form in AVX2? No. There's no 64 x 64 -> 128 bit arithmetic as a vector instruction. Nor is there a vector mulhi type instruction (high word result of multiply). [V]PMULUDQ can do 32 x 32 -> 64 bit by only considering every second 32 bit unsigned element, or unsigned doubleword, as a source, and

Representing identifiers using Regular Expression

只谈情不闲聊 提交于 2019-12-05 10:19:51
问题 The regular definition for recognizing identifiers in C programming language is given by letter -> a|b|...z|A|B|...|Z|_ digit -> 0|1|...|9 identifier -> letter(letter|digit)* This definition will generate identifiers of the form identifier: [_a-zA-Z][_a-zA-Z0-9]* My question now is how do you limit the length of the identifier that can be generated to not more than 31 characters. What changes need to be made in the regular definition or how to write a regular expression to limit it to not

Difference between Memory Mapped I/O and Programmed I/O

橙三吉。 提交于 2019-12-05 10:02:35
While going through computer Architecture, I learnt different method of controlling I/O device which are, Programmed I/O Interrupt I/O DMA I learnt all three methods. But I come across another term Memory Mapped I/O . Is there any relation between Programmed I/O and Memory Mapped I/O ? I am confused with these two. Are they similar? Those terms are mostly independent and not mutually exclusive. Below I'll use a pseudo-assembly code to make the examples clearer, it is a demonstrative code, not real code. How do I access a device? If the device is accessible in a dedicated address space,

Bin-packing (or knapsack?) problem

风流意气都作罢 提交于 2019-12-05 10:00:37
I have a collection of 43 to 50 numbers ranging from 0.133 to 0.005 (but mostly on the small side). I would like to find, if possible, all combinations that have a sum between L and R, which are very close together.* The brute-force method takes 2 43 to 2 50 steps, which isn't feasible. What's a good method to use here? Edit: The combinations will be used in a calculation and discarded. (If you're writing code, you can assume they're simply output; I'll modify as needed.) The number of combinations will presumably be far too large to hold in memory. * L = 0.5877866649021190081897311406, R = 0

Multithreading in MySQL?

狂风中的少年 提交于 2019-12-05 09:35:27
Are MySQL operations multithreaded? Specifically, on running a select, does the select (or join) algorithm spawn multiple threads to run together? Would being multi-threaded prevent being able to support a lot of concurrent users? Several background threads run in a MySQL server. Also, each database connection is served by a single thread. Parallel queries (selects using multiple threads) are not implemented in MySQL. MySQL as is can support "a lot of concurrent useres". For example Facebook started successfully with MySQL. Besides each connection has a thread, there are several management

Print a tree in sorted order using heap properties (Cormen)

烂漫一生 提交于 2019-12-05 05:13:47
I am refreshing on algorithm theory (from Cormen). There is an exercise in the chapter for binary tries that asks: Can the min-heap property be used to print out the keys of an n-node tree in sorted order in O(n) time? Show how, or explain why not. I thought yes it is possible. In the min heap the element in a node is smaller than both its children. So the root of the heap is always the smaller element of all the n elements and the left child of the root is the smaller than all the elements in the left subtree and the right child of the root is the smaller than all the elements in the right

What does qualify mean?

ぐ巨炮叔叔 提交于 2019-12-05 05:00:44
When reading articles, manuals, etc... about programming, i always come across the word qualified . like in java the fully qualified class name would be com.example.Class. Reading this article, defines the scope resolution operator :: in C++ as being used to Qualify hidden names so you can still use them. Is there a definition for this ? Beccause it seems to be used in a different context each time. In computer programming, a fully qualified name is an unambiguous name that specifies which object, function, or variable a call refers to without regard to the context of the call. In a