Alex L
BAN USERWell obvious reason is less moving in/out processes from RAM to disk/disk to RAM since disk I/O is extremely slow comparing to CPU speed or even RAM speed. I don't know what other clarification you have got but I will assume single process takes at most 2GB and you are running multiple processes simultaneously.
- Alex L February 19, 2014My idea to solve this:
1. either use a array of integer count[] to record the number of each character appears in string 1, or use a hashtable, character as key and count as value.
2. go through string2 from head to tail and lookup the current character in ur array or hashtable. each lookup takes O(1) in either case.
3. once you found a matching character, use it as starting point and check the characters following by.
4. if step 3 fail in middle, reset and start over the search from the next character in string2.
This algorithm should take only O(n) time and O(n) space.
I will try come up with code later
1. initialize idxA = 0, representing index in a[]
- Alex L February 19, 20142. Do binary search for possible pair in b[0]. have a idxB record the resulting position
3. At this point idxB points to closest possible value (or equal) to the desired sum.
4. do linear search through a[] & b[], follow the rule:
if (a[idxA] + b[idxB] > x) idxB--
else if (a[idxA] + b[idxb] < x) idxA++
else found.
This should have worst case O(a.len+b.len) but slightly better in average case.