Cody

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

Solution 176885

Submitted on 13 Dec 2012 by Aurelien Queffurust
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   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

Elapsed time is 0.000010 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000001 seconds. Elapsed time is 0.000002 seconds. Elapsed time is 0.000002 seconds.

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

Elapsed time is 0.000006 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000008 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000006 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000007 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000009 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000010 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000009 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000010 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000006 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000009 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000006 seconds. Elapsed time is 0.000006 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000006 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000006 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000009 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000006 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000007 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000005 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000006 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000006 seconds. Elapsed time is 0.000004 seconds. Elapsed time is 0.000003 seconds. Elapsed time is 0.000003 seconds. Your Time = 15627 msec