Quiz2SolutionsSu98 - uses to search a list of 10,000 items...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Quiz #2 EEL4851 Summer 1998 solutions On searches. Part 1. Write a function that performs a binary search. int binary_search( int data, int table[ ], int size) { return b_search(data, table, 0, size-1); } int b_search( int data, int table[ ], int F, int L) { int M; if (R - L < 2) if (table[L] == data) return L; else if (table[R] == data) return R; else return -1; else { M = (R - L) / 2; if (data < table[M]) return b_search( data, table, L, M - 1); else return b_search( data, table, M,R); } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Part 2. Fill in the blank and answer the question. The binary search only uses .2658% percent of the number of comparisons that a linear search
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: uses to search a list of 10,000 items. The binary search takes 29 . 13 69315 . 21 . 9 2 ln 000 , 10 ln 000 , 10 log 2 = = = comparisons. The linear search takes 000 , 5 2 000 , 10 = comparisons. So % 2658 . 5000 29 . 13 = What happens to the above percent as the size of the list increases. Why. To be precise: 2 ln 2 Lim 2 1 2 ln 1 Lim 2 log Lim 2 log Lim 2 2 = = = = ∞ → ∞ → ∞ → ∞ → n n n dn d n dn d n n n n n n Also since n grows much faster then n 2 log the ratio goes to 0....
View Full Document

{[ snackBarMessage ]}

Page1 / 2

Quiz2SolutionsSu98 - uses to search a list of 10,000 items...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online