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

Solution 210660

Submitted on 28 Feb 2013 by bartekltg
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

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 = 65 msec

Suggested Problems

More from this Author246

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!