KHO THƯ VIỆN 🔎

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

➤  Gửi thông báo lỗi    ⚠️ Báo cáo tài liệu vi phạm

Loại tài liệu:     PDF
Số trang:         400 Trang
Tài liệu:           ✅  ĐÃ ĐƯỢC PHÊ DUYỆT
 













Nội dung chi tiết: The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 Information”; on the other hand, it might simply have been called “Table Look-Up.” We are concerned with the process of collecting information in a c

omputer’s memory, in such a way that the information can subsequently be recovered as quickly as possible. Sometimes we are confronted with more data The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

than we can really use, and it may be wisest to forget and to destroy most of if, but at other times it is important to retain and organize the given

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

facts in such a way that fast retrieval is possible.Most of this chapter is devoted to the study of a very simple search problem: how to find the data

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 es of f; in a noimumerical application, we might want to find the English translation of a given Russian word.In general, we shall suppose that a set

of N records has been stored, and the problem is to locate the appropriate one. As in the case of sorting, we assume that each record includes a speci The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

al field called its key, this terminology is especially appropriate, because many people spend a great deal of time every day searching for their keys

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

. We generally require the N keys to be distinct, so that each key uniquely identifies its record. The collection of all records is called a table or

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 f files is frequently called a database.Algorithms for searching are presented with a so-called argument, K, and the problem is to find which record h

as K as its key. After the search is complete, two possibilities can arise: Either the search was successful, having located the unique record contain The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

ing K\ or it was unsuccessful, having determined that K is nowhere to be found. After an unsuccessful search it is sometime desirable to enter a new r

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

ecord, containing K, into the table; a method that does this is called a search-and- insert ion algorithm. Some hardware devices known as associative

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 ching on a conventional general-purpose digital computer.Although the goal of searching is to find the information stored in the record associated wit

h K, the algorithms in this chapter generally ignore everything but3926SEARCHING 393the keys themselves. In practice we can find the associated data o The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

nce we have located K‘, for example, if K appears in location TABLE + :, the associated data (or a pointer to it) might be in location TABLE + i 4-1,

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

or in DATA 4-«, etc. It is therefore convenient to gloss over the details of what should be done after K has been successfully found.Searching is the

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 In fact we can often arrange the data or the data structure so that searching is eliminated entirely, by ensuring that we always know' just where to f

ind the information W'C need. Linked memory is a common way to achieve this; for example, a doubly linked list makes it unnecessary to search for the The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

predecessor or successor of a given item. Another way to avoid searching occurs if we are allow’ed to choose the keys freely, since W'e might as well

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

let them be the numbers {1,2,..., jV}; then the record containing K can simply be placed in location TABLE 4- K. Both of these techniques W’ere used t

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 n the topological sorting algorithm had been given symbolic names instead of numbers. Efficient algorithms for searching turn out to be quite importan

t in practice.Search methods can be classified in several ways. We might divide them into internal versus external searching, just as we divided the s The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

orting algorithms of Chapter 5 into internal versus external sorting. Or we might divide search methods into static versus dynamic searching, W'here “

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

static” means that the contents of the table are essentially unchanging (so that it is important to minimize the search time without regard for the ti

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 heme is to classify search methods according to whether they are based on comparisons between keys or on digital properties of the keys, analogous to

the distinction between sorting by comparison and sorting by distribution. Finally we might divide searching into those methods that use the actual ke The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

ys and those that work with transformed keys.The organization of this chapter is essentially a combination of the latter two modes of classification.

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

Section 6.1 considers “brute force” sequential methods of search, then Section 6.2 discusses the improvements that can be made based on comparisons be

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 ass of methods called hashing techniques, based on arithmetic transformations of the actual keys. Each of these sections treats both internal and exte

rnal searching, in both the static and the dynamic case; and each section points out the relative advantages and disadvantages of the various algorith The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

ms.Searching and sorting are often closely related to each other. For example, consider the following problem: Given two sets of numbers, A = {ííi, (1

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

2,..., dm } and B = {6i,Ò2,...,òn}, determine whether or not A c B. Three solutions suggest themselves:394 SEARCHING61.Compare each at sequentially wi

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 the bjS in a table, then search for each of the dị.Each of these solutions is attractive for a different range of values of m and n. Solution 1 will t

ake roughly Clmn units of time, for some constant Cl, and solution 2 will take about C2(mlgm + nlgn) units, for some (larger) constant C2-With a suita The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

ble hashing method, solution 3 will take roughly C37H 4- c«n units of time, for some (still larger) constants C3 and C4. It follows that solution 1 is

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

good for very small m and n, but solution 2 soon becomes better as m and n grow larger. Eventually solution 3 becomes preferable, until n exceeds the

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 good substitute for searching, and searching is sometimes a good substitute for sorting.More complicated search problems can often be reduced to the

simpler case considered here. For example, suppose that the keys are words that might be slightly misspelled; we might want to find the correct record The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

in spite of this error. If we make two copies of the file, one in which the keys are in normal lexicographic order and another in which they are orde

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

red from right to left (as if the W’ords were spelled backwards), a misspelled search argument will probably agree up to half or more of its length wi

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 A related problem has received considerable attention in connection with airline reservation systems, and in other applications involving people’s nam

es when there is a good chance that the name will be misspelled due to poor handwriting or voice transmission. The goal is to transform the argument i The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

nto some code that tends to bring together all variants of the same name. The following contemporary form of the “Soundex” method, a technique that wa

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

s originally developed by Margaret K. Odell and Robert c. Russell [see U.S. Patents 1261167 (1918), 1435663 (1922)], has often been used for encoding

CHAPTER SIXSEARCHINGLet's look at the record.— AL SMITH (1928)This chapter might have been given the more pretentious title “Storage and Retrieval of

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2 o the remaining letters after the first:b,f, p, V -> 11 —> 4c,g, j, k, q, s, X, z -> 2m, n -4 5d,t —> 3r —> 63.If two or more letters with the same co

de were adjacent in the original name (before step 1), or adjacent except for intervening h’s and w’s, omit all but the first.4.Convert, to the form “ The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

letter, digit, digit, digit” by adding trailing zeros (if there are less than three digits), or by dropping rightmost digits (if there are more than t

The art of computer programming volume 3 sorting and searching (second edition 2011) part 2

hree).6SEARCHING 395For example, the names Euler, Gauss, Hilbert, Knuth, Lloyd, Lukasiewicz, and Wachs have the respective codes E460, G200, H416, K53

Gọi ngay
Chat zalo
Facebook