efficiency

Has this algorithm been implemented properly?

I am currently implementing a BK-Tree to make a spell checker. The dictionary I am working with is very large (millions of words), which is why I cannot afford any inefficiencies at all. However, I know that the lookup function that I wrote (arguably the most important part of the entire program) can be made better. I was hoping to find ...

Why is my program slow ? How can I improve its efficiency ?

I've a program that does Block Nested loop join (link text). Basically what it does is, it reads contents from a file (say 10GB file) into buffer1 (say 400MB), puts it into a hash table. Now read contents of the second file (say 10GB file) into buffer 2 (say 100MB) and see if the elements in buffer2 are present in the hash. Outputting th...

How long will a query with two "contains" tests take to execute on the appengine datastore?

I have two sets of thirty or forty IDs, set A and set B. I have a kind of entity that has a field idA (an id that might be in set A) and a field idB (an id that might be in set B). I want to find all of the entities with idA in set A and idB in set B. I could perform a query with filters like "A.contains(idA) && B.contains(idB)," but ...

Tricky MS Access SQL query to remove surplus duplicate records

I have an Access table of the form (I'm simplifying it a bit) ID AutoNumber Primary Key SchemeName Text (50) SchemeNumber Text (15) This contains some data eg... ID SchemeName SchemeNumber -------------------------------------------------------------------- 714 Malcolm ...

What options do I have for creating customized keyboard shortcuts?

As I am getting more heavily into programming as a job and no longer as a hobby, I am definitely in need of some ways to improve my productivity. One thing that would definitely help in that respect is being able to create customized keyboard shortcuts for text/code snippets. For instance, holding down CMD+L+O+R+E+M will output a paragra...

Efficient computation of "variable (number of points included)" moving average in R

Hi everybody, I'm trying to implement a variable exponential moving average on a time series of intraday data (i.e 10 seconds). By variable, I mean that the size of the window included in the moving average depends on another factor (i.e. volatility). I was thinking of the following: MA(t)=alpha(t)*price(t) + (1-alpha(t))MA(t-1), whe...

Which of the following would be more efficient?

In C: Lets say function "Myfuny()" has 50 line of codes in which other smaller functions also get called. Which one of the following code would be more efficient? void myfunction(long *a, long *b); int i; for(i=0;i<8;i++) myfunction(&a, &b); or myfunction(&a, &b); myfunction(&a, &b); myfunction(&a, &b); myfunction(&a, &b); myfunc...

Java Loop Efficiency. if-continue OR if

Hi. The question being thought today while completing my task is about the loop efficiency.. Lets say. I have an array {'a','x','a','a'} And a loop that should avoid 'x' element Now i wonder how these two approach differ in term of efficiency - not taking the while or do-while or for loops differentiation char[] arrExample = {'a','x'...

Given a String and an array of Strings, how do I efficiently calculate the occurrences of the array in String?

Let's assume text is a String and contains a text. tags is an Array of Strings. text = <<-EOS Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis au...

efficient way to bind a drag event

i have read a program that have a drag functionality in a table but i really think it is not efficient , here is the code var downState = false; $('#element').delegate('td','mousedown',function() { downState = true; //do stuff }).delegate('td','mouseenter',function() { if (downState) //do stuff }); what i don't like is ...

Rails: An efficient method to match subdomains in the database?

We allow users to add domains to an active record model such as User.domain and find the users by domain using User.find_by_domain. In the future we want to allow users to enter *.example.com as their domain and allow User.find_by_subdomain('sub1.example.com') and User.find_by_subdomain('sub2.example.com') to work. However we also want ...

CakePHP, wrting a better query string.

In Cakephp is there a better way to write this: $unread_orders = $this->Order->find('all', array('conditions' => array('Order.status' => 'unread') )); $read_orders = $this->Order->find('all', array('conditions' => array('Order.status' => 'read') )); $dispatched = $this->Order->find('all', array('conditions' => array('Order.status' => 'd...

Merge two Hash Maps Android

Hi guys, I want to merge Two HashMaps. I could use map1.putAll(map2); but I don't want to overwrite the key's as yes they will have conflicting keys. So the keys in each map will be like this word1 word1 word2 word2 word3 word3 and when I merge them I would like: word1 word2 word3 word4 word5 word6 It c...

Efficiently determining the relationship between rows in a spreadsheet

This is a problem I've just run into, or rather its a simplification that captures the core problem. Imagine I have a spreadsheet containing a number of columns, each of them labeled, and a number of rows. I want to determine when the value in one column can be inferred from the value in another. For example, we might find that every ...

Efficiency of boolean comparisons? In C.

I'm writing a loop in C, and I am just wondering on how to optimize it a bit. It's not crucial here as I'm just practicing, but for further knowledge, I'd like to know: In a loop, for example the following snippet: int i = 0; while (i < 10) { printf("%d\n", i); i++; } Does the processor check both (i < 10) and (i == 10) for e...

Why does InnoDB do a full scan for COUNT(*)?

In a table with 5 millions rows, a SELECT count(*) FROM table would be instant in MyISAM but would take several seconds in InnoDB. Why is this that way? Why haven't they optimise count in InnoDB like MyISAM? Thanks. ...

Improving loop efficiency/extensibility

I have an array of pixels which make up a 2D grid and I want to move these pixels right and left over time... constantly however the loop I came up with is fairly inefficient and does not allow for much expansion in terms of changing the motion. Any ideas on how to improve what I already have would be much appreciated. while (true) { ...

Where to find typing efficiency tips?

E.G. I was reading some source code recently. and someone had the code. array = "name1 name2 name3 name4 name5".split() Which is really fast/easy to write. While if I had written the code I would've went. array[0] = name1 array[1] = name2 etc... Which takes way longer! So I was wondering where I could find some writing ef...

Timer Efficiency

I am planning to develop a system with tens of thousands of objects in it, which will each have up to 42(but more likely down around 4 or 5) separate actions they will potentially be performing at regular intervals. I also plan to write code that will deactivate the timers until the object comes into use. When idle, the objects will on...

Find the least number of coins required that can make any change from 1 to 99 cents

Recently I challenged my co-worker to write an algorithm to solve this problem: Find the least number of coins required that can make any change from 1 to 99 cents. The coins can only be pennies (1), nickels (5), dimes (10), and quarters (25), and you must be able to make every value from 1 to 99 (in 1-cent increments) using those co...