11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 3.14 Projects 893.24 Prove th<strong>at</strong> if an algorithm is Θ(f(n)) in the average case, then it is O(f(n))in the best case.3.14 Projects3.1 Imagine th<strong>at</strong> you are trying to store 32 Boolean values, <strong>and</strong> must accessthem frequently. Compare the time required to access Boolean values storedaltern<strong>at</strong>ively as a single bit field, a character, a short integer, or a long integer.There are two things to be careful of when writing your program. First, besure th<strong>at</strong> your program does enough variable accesses to make meaningfulmeasurements. A single access takes much less time than a single unit ofmeasurement (typically milliseconds) for all four methods. Second, be sureth<strong>at</strong> your program spends as much time as possible doing variable accessesr<strong>at</strong>her than other things such as calling timing functions or incrementing forloop counters.3.2 Implement sequential search <strong>and</strong> binary search algorithms on your computer.Run timings for each algorithm on arrays of size n = 10 i for i ranging from1 to as large a value as your computer’s memory <strong>and</strong> compiler will allow. Forboth algorithms, store the values 0 through n − 1 in order in the array, <strong>and</strong>use a variety of r<strong>and</strong>om search values in the range 0 to n − 1 on each sizen. Graph the resulting times. When is sequential search faster than binarysearch for a sorted array?3.3 Implement a program th<strong>at</strong> runs <strong>and</strong> gives timings for the two Fibonacci sequencefunctions provided in Exercise 2.11. Graph the resulting runningtimes for as many values of n as your computer can h<strong>and</strong>le.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!