Академический Документы
Профессиональный Документы
Культура Документы
Lecture No. 38
___________________________________________________________________
Data Structures
Lecture No. 38
Summary
We will discuss the concepts of Tables and Dictionaries in this lecture with special
reference to the operations on Table ADT and the implementation.
Address
50 Zahoor Elahi Rd, Gulberg-4, Lahore
30-T Phase-IV, LCCHS, Lahore
131-D Model Town, Lahore
Phone
567-4567
517-2349
756-5678
Address
50 Zahoor Elahi Rd, Gulberg-4, Lahore
30-T Phase-IV, LCCHS, Lahore
131-D Model Town, Lahore
Figure 38.2: A table having three fields.
Phone
567-4567
517-2349
756-5678
Implementation of Table
Lets talk about why and how we should implement a table. Our choice for
implementation of the Table ADT depends on the answers to the following.
In a table for searching purposes, it is best to store the key and the entry separately
(even though the keys value may be inside the entry). Now, suppose we have a record
of a person Saleem whose address is 124 Hawkers Lane while the phone number is
9675846. Similarly we have another record of a person Yunus. The address and
phone fields of this person are 1 Apple crescent and 622455 respectively. For these
records in the table, we will have two parts. One part is the complete entry while the
other is the key in which we keep the unique item of the entry. This unique item is
key
entry
Binary Search
The binary search is an algorithm of searching, used with the sorted data. As we have
sorted elements in the array, binary search method can be employed to find data in the
array. The binary search finds an element in the sorted array in log n time. If we have
100000 elements in the array, the log 1000000 will be 20 i.e. very small as compared
to 100000. Thus binary search is very fast.
The binary search is like looking up a phone number in the directory or looking up a
word in the dictionary. For looking a word in the dictionary, we start from the middle
in the dictionary. If the word that we are looking for comes before words on the page,
it shows that the word should be before this page. So we look in the first half.
Otherwise, we search for the word in the second half of the dictionary. Suppose the
word is in the first half of the dictionary, we consider first half for looking the word.