Binary Search: Lookup Efficiency With MatchType Set to 1

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,210
Quoted from: http://www.mrexcel.com/board2/viewtopic.php?t=87050

formula 1:

=VLOOKUP(B14,{"Deluxe Tour",128;"Jungle River Safari",88;"My Generation Tour Adult Only",128;"Power Boat Jeep Rental",295},2,0)

formula 2:

=LOOKUP(B14,{"Deluxe Tour","Jungle River Safari","My Generation Tour Adult Only","Power Boat Jeep Rental";128,88,128,295})

i've often wondered how these two would perform next to each other in like conditions, one syntax to another. any idea aladin?
_________________
Regards,
Zack

Both formulas use a sorted built-in table. The LOOKUP formula invokes binary search, the VLOOKUP formula linear search as determined by the match-type = 0. Therefore the LOOKUP formula will be faster.

How do VLOOKUP, LOOKUP, INDEX/MATCH perform when all invoke binary search?

Before proceeding further, one thing must be noted. Using binary search formulas with sortedtextrequires caution. To see this, enter in B14 the following:

Voyage au bout de la nuit

The LOOKUP formula happily returns 295, while the VLOOKUP formula with match-type set to 0 errors out.

=VLOOKUP(B14,{"Deluxe Tour",128;"Jungle River Safari",88;"My Generation Tour Adult Only",128;"Power Boat Jeep Rental",295},2,1)

would behave like the LOOKUP formula.

This cautionary note does not apply to the use of BigNum/BigStr as lookup values in formulas which invoke binary search in order to determine last numeric/text values in ranges of interest.

How about performance differences?

What follows compares the following sets of formulas:

[1]

=VLOOKUP(B7,AccList!$F$2:$H$9978,3,1)

=VLOOKUP(B7,AccList!$F$2:$L$9978,7,1)

[2]

=LOOKUP(B7,AccList!$F$2:$F$9978,AccList!$H$2:$H$9978)

=LOOKUP(B7,AccList!$F$2:$F$9978,AccList!$L$2:$L$9978)

[3]

=INDEX(AccList!$H$2:$H$9978,MATCH(B7,AccList!$F$2:$F$9978,1))

=INDEX(AccList!$L$2:$L$9978,MATCH(B7,AccList!$F$2:$F$9978,1))

[4]

=INDEX(AccList!$H$2:$H$9978,H7)

=INDEX(AccList!$L$2:$L$9978,H7)

=MATCH(B7,AccList!$F$2:$F$9978,1)

which is in H7.

As is clear, the lookup table is in AccListF2:L9978. Column F houses text-formatted account-numbers and the table is sorted in ascending order on F.

Each formula is copied to 6255 cells.

The figures are averages of 5 runs.
All With BS MrExcel.xls
ABCDEFGHI
1FastExcelWorkBookProfileVersion2.0Build434
2WorkBookSummary
3CalcTime(Millisec)%MicroSecsRangeTotal
4ConstFormulaReCalcFullCalcVolatile/FormulaMem(K)Mem(K)
5[1]VLOOKUP94,93512,5220.2115.60.2%9.22,0712,136
6[2]LOOKUP94,93512,5220.2109.70.2%8.82,1192,208
7[3]INDEX/MATCH(a)94,93512,5220.2118.20.2%9.42,1952,260
8[4]INDEX/MATCH(b)94,93518,7830.291.90.3%4.92,3192,406
9
FastXL
 
Aladin Akyurek said:
Yes. It's better performancewise...

let me ask you this:

do you think it would ever be more advantageous to couple the two fore-mentioned functions together to save space memory wise, and sacrafice re-calc time? it would seem to me that it'd have to be a pretty hefty workbook with extremely large areas of data. and if this was the case, you'd already be at a disadvantage in regards to re-calc time.
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
firefytr said:
Aladin Akyurek said:
Yes. It's better performancewise...

let me ask you this:

do you think it would ever be more advantageous to couple the two fore-mentioned functions together to save space memory wise, and sacrafice re-calc time? it would seem to me that it'd have to be a pretty hefty workbook with extremely large areas of data. and if this was the case, you'd already be at a disadvantage in regards to re-calc time.

The MATCH bit in separate cells in the exhibit accounts for ~200K additional memory. That doesn't look like a big issue...
 
Upvote 0
Aladin Akyurek said:
The MATCH bit in separate cells in the exhibit accounts for ~200K additional memory. That doesn't look like a big issue...

i know. i must've come across wrong. i was thinking more along the lines of your exhibit x1,000, even x10,000 in some people's cases. i guess it would be more of a non-issue if they are attempting to steamline efficiency for their workbook/s anyway.
 
Upvote 0
firefytr said:
Aladin Akyurek said:
The MATCH bit in separate cells in the exhibit accounts for ~200K additional memory. That doesn't look like a big issue...

i know. i must've come across wrong. i was thinking more along the lines of your exhibit x1,000, even x10,000 in some people's cases. i guess it would be more of a non-issue if they are attempting to steamline efficiency for their workbook/s anyway.

One issue that never gets rised is whether the lookup formulas should be used as a means of copying large chunks of a large area of data. After that, further processing is applied to the retrieved data. One wonders why such processing is not applied directly to the source area.
 
Upvote 0
Aladin,

Since you're still up and I joined this thread rather late, much like ridding the #N/A in Vlookup, efficiency wise, replace Vlookup with a two step approach using Match then Index?
 
Upvote 0
agreed. i believe that to be, imho, a 'flexibility' issue if you will - for the user. as i've done many times in the past (as in your description) it seems to add a measure of control the user manifests in their worksheets. i could be wrong, like in many cases, but that's how it appears to me at times.

{hiya Brian :-) }
 
Upvote 0
Brian from Maui said:
Aladin,

Since you're still up and I joined this thread rather late, much like ridding the #N/A in Vlookup, efficiency wise, replace Vlookup with a two step approach using Match then Index?

Like...

In C2:

=MATCH(A2,$X$2:$X$100,0)

In B2:

=IF(ISNUMBER(C2),INDEX($Y$2:$Y$100,C2),"")

would be similar to, perhaps lightly faster,...

In C2:

=VLOOKUP(A2,$X$2:$X$100,2,0)

In B2:

=IF(ISNA(C2),"",C2)
 
Upvote 0
GEEZ!,

Just when I changed all my Vlookups to =IF(ISNA(A10)......

At my age, change is difficult!!!! :diablo:

Hey Zack...get some sleep tonight!
 
Upvote 0
and...

In C2:

=MATCH(A2,$X$2:$X$100,0)

In B2:

=IF(ISNUMBER(C2),INDEX($Y$2:$Y$100,C2),"")
compared to this...

=IF(ISNUMBER(MATCH(A2,$X$2:$X$100,0)),INDEX($Y$2:$Y$100,C2),"")

could be more beneficial efficiency wise. if i'm understanding you.
 
Upvote 0

Forum statistics

Threads
1,224,877
Messages
6,181,526
Members
453,053
Latest member
DavidKele

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top