Cody

Problem 934. Find: Faster Alternatives for Large Sorted/Unique Vectors

Solution 1259527

Submitted on 30 Aug 2017
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
feval(@assignin,'caller','score',0);

2   Fail
L=1000; a=randi(2^32-1,L*1.2,1,'uint32'); a=unique(a,'R2012a'); a=a(1:L); % Warm-Up Test cases for i=1:5:1000 assert(isequal(find_fast(a,a(i)),i)) end

Error using find Second argument must be a positive scalar integer. Error in find_fast (line 10) ixs = find(v(ii)<=Nsteps,'last',1); Error in Test2 (line 8) assert(isequal(find_fast(a,a(i)),i))

3   Fail
% Timing Performance Case L=12000000; a=randi(2^32-1,L*1.2,1,'uint32'); a=unique(a,'R2012a'); a=a(1:L); q=200; val=zeros(q,1); for i=1:q val(i)=a(randi(L)); end t0=clock; for i=1:q ptr=find_fast(a,val(i)); end dt=etime(clock,t0)*1000; assert(isequal(find_fast(a,val(1)),find(a==val(1),1,'first'))) fprintf('Your Time = %i msec\n',floor(dt)) feval(@assignin,'caller','score',min(200,floor(dt))); % Performance Score

Error using find Second argument must be a positive scalar integer. Error in find_fast (line 10) ixs = find(v(ii)<=Nsteps,'last',1); Error in Test3 (line 16) ptr=find_fast(a,val(i));