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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 1.1 A Philosophy of <strong>D<strong>at</strong>a</strong> <strong>Structures</strong> 7to account balances <strong>and</strong> upd<strong>at</strong>es such as deposits <strong>and</strong> withdrawals. Specialservice represent<strong>at</strong>ives are typically provided (during restricted hours)to h<strong>and</strong>le opening <strong>and</strong> closing accounts. Teller <strong>and</strong> ATM transactions areexpected to take little time. Opening or closing an account can take muchlonger (perhaps up to an hour from the customer’s perspective).From a d<strong>at</strong>abase perspective, we see th<strong>at</strong> ATM transactions do not modifythe d<strong>at</strong>abase significantly. For simplicity, assume th<strong>at</strong> if money is addedor removed, this transaction simply changes the value stored in an accountrecord. Adding a new account to the d<strong>at</strong>abase is allowed to take severalminutes. Deleting an account need have no time constraint, because fromthe customer’s point of view all th<strong>at</strong> m<strong>at</strong>ters is th<strong>at</strong> all the money be returned(equivalent to a withdrawal). From the bank’s point of view, theaccount record might be removed from the d<strong>at</strong>abase system after businesshours, or <strong>at</strong> the end of the monthly account cycle.When considering the choice of d<strong>at</strong>a structure to use in the d<strong>at</strong>abasesystem th<strong>at</strong> manages customer accounts, we see th<strong>at</strong> a d<strong>at</strong>a structure th<strong>at</strong>has little concern for the cost of deletion, but is highly efficient for search<strong>and</strong> moder<strong>at</strong>ely efficient for insertion, should meet the resource constraintsimposed by this problem. Records are accessible by unique account number(sometimes called an exact-m<strong>at</strong>ch query). One d<strong>at</strong>a structure th<strong>at</strong> meetsthese requirements is the hash table described in Chapter 9.4. Hash tablesallow for extremely fast exact-m<strong>at</strong>ch search. A record can be modifiedquickly when the modific<strong>at</strong>ion does not affect its space requirements. Hashtables also support efficient insertion of new records. While deletions canalso be supported efficiently, too many deletions lead to some degrad<strong>at</strong>ionin performance for the remaining oper<strong>at</strong>ions. However, the hash table canbe reorganized periodically to restore the system to peak efficiency. Suchreorganiz<strong>at</strong>ion can occur offline so as not to affect ATM transactions.Example 1.2 A company is developing a d<strong>at</strong>abase system containing inform<strong>at</strong>ionabout cities <strong>and</strong> towns in the United St<strong>at</strong>es. There are manythous<strong>and</strong>s of cities <strong>and</strong> towns, <strong>and</strong> the d<strong>at</strong>abase program should allow usersto find inform<strong>at</strong>ion about a particular place by name (another example ofan exact-m<strong>at</strong>ch query). Users should also be able to find all places th<strong>at</strong>m<strong>at</strong>ch a particular value or range of values for <strong>at</strong>tributes such as loc<strong>at</strong>ion orpopul<strong>at</strong>ion size. This is known as a range query.A reasonable d<strong>at</strong>abase system must answer queries quickly enough tos<strong>at</strong>isfy the p<strong>at</strong>ience of a typical user. For an exact-m<strong>at</strong>ch query, a few secondsis s<strong>at</strong>isfactory. If the d<strong>at</strong>abase is meant to support range queries th<strong>at</strong>can return many cities th<strong>at</strong> m<strong>at</strong>ch the query specific<strong>at</strong>ion, the entire opera-

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

Saved successfully!

Ooh no, something went wrong!