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. 1.6 Exercises 21than 10,000 of the array values are non-zero. Describe two different implement<strong>at</strong>ionsfor such arrays th<strong>at</strong> would be more space efficient than a st<strong>and</strong>ardtwo-dimensional array implement<strong>at</strong>ion requiring one million positions.1.7 Imagine th<strong>at</strong> you have been assigned to implement a sorting program. Thegoal is to make this program general purpose, in th<strong>at</strong> you don’t want to definein advance wh<strong>at</strong> record or key types are used. Describe ways to generalizea simple sorting algorithm (such as insertion sort, or any other sort you arefamiliar with) to support this generaliz<strong>at</strong>ion.1.8 Imagine th<strong>at</strong> you have been assigned to implement a simple sequential searchon an array. The problem is th<strong>at</strong> you want the search to be as general as possible.This means th<strong>at</strong> you need to support arbitrary record <strong>and</strong> key types.Describe ways to generalize the search function to support this goal. Considerthe possibility th<strong>at</strong> the function will be used multiple times in the sameprogram, on differing record types. Consider the possibility th<strong>at</strong> the functionwill need to be used on different keys (possibly with the same or differenttypes) of the same record. For example, a student d<strong>at</strong>a record might besearched by zip code, by name, by salary, or by GPA.1.9 Does every problem have an algorithm?1.10 Does every algorithm have a Java program?1.11 Consider the design for a spelling checker program meant to run on a homecomputer. The spelling checker should be able to h<strong>and</strong>le quickly a documentof less than twenty pages. Assume th<strong>at</strong> the spelling checker comes with adictionary of about 20,000 words. Wh<strong>at</strong> primitive oper<strong>at</strong>ions must be implementedon the dictionary, <strong>and</strong> wh<strong>at</strong> is a reasonable time constraint for eachoper<strong>at</strong>ion?1.12 Imagine th<strong>at</strong> you have been hired to design a d<strong>at</strong>abase service containinginform<strong>at</strong>ion about cities <strong>and</strong> towns in the United St<strong>at</strong>es, as described in Example1.2. Suggest two possible implement<strong>at</strong>ions for the d<strong>at</strong>abase.1.13 Imagine th<strong>at</strong> you are given an array of records th<strong>at</strong> is sorted with respect tosome key field contained in each record. Give two different algorithms forsearching the array to find the record with a specified key value. Which onedo you consider “better” <strong>and</strong> why?1.14 How would you go about comparing two proposed algorithms for sorting anarray of integers? In particular,(a) Wh<strong>at</strong> would be appropri<strong>at</strong>e measures of cost to use as a basis for comparingthe two sorting algorithms?(b) Wh<strong>at</strong> tests or analysis would you conduct to determine how the twoalgorithms perform under these cost measures?1.15 A common problem for compilers <strong>and</strong> text editors is to determine if theparentheses (or other brackets) in a string are balanced <strong>and</strong> properly nested.

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

Saved successfully!

Ooh no, something went wrong!