Purchase Solution

Detailed comparision of linear and binary searches on a list

Not what you're looking for?

Ask Custom Question

Suppose that you have a dictionary whose words are not sorted in alphabetical order. As a function of the number, n of words, what is the efficiency of searching for a particular word in this dictionary ?

Do the same for dictionary whose words are sorted alphabetically. Compare results.

Purchase this Solution

Solution Summary

This solution provides a detailed comparison of searching a list of words using a linear search vs. using a binary search. The discussions explains the expected performance in O() notation and shows how the O() value is calculated.

Solution Preview

The only way to search a list of unsorted elements is to use a loop to look at each element in the list. For example:

foreach (e in list) {
if (e == targetValue) {
found = true;
}
}

Assuming random data, approximately half of the time the sought after element will be in the first half of the list while half of the time it will be in the second half of the list. This means that the average number of elements that have to be inspected is n/2 (for a list of n elements). In O() notation this is O(n).

A dictionary whose words are not sorted is simply a list ...

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Javscript Basics

Quiz on basics of javascript programming language.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.