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

Solution 897471

Submitted on 27 May 2016 by Tom Purcell
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

2   Pass
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

3   Pass
% 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

Your Time = 10 msec