Java Reference
In-Depth Information
}
for
(i=0;i
<
m; i ++)
System . out . println (
"Position "
+i+
"\t"
+HashTable [ i ]) ;
}
Running this code, we get the following output:
Position 0
--> whale
Position 1
--> snake
Position 2
-->
Position 3
-->
Position 4
-->
Position 5
-->
Position 6
-->
Position 7
--> cow
Position 8
--> shark
Position 9
-->
Position 10
-->
Position 11
-->
Position 12
--> fish
Position 13
--> cat
Position 14
-->
Position 15
--> dog tortoise
Position 16
--> horse
Position 17
--> flamingo
Position 18
-->
Position 19
--> pelican
Position 20
--> parrot lion
Position 21
-->
Position 22
-->
We will further describe hashing techniques once the linked lists are introduced
in the next chapter.
6.7 Exercises
Exercise 6.1 (Sequential search)
Consider a collection of topics in a library with each book modeled by its
(1) title, (2) author(s) and (3) ISBN unique number. Provide a class
Book
with an appropriate constructor. Further equip this class with another
constructor that takes as its argument a
Book
object. Consider an array
of topics
Book [] array
. Give a search function
SequentialSearch
that given a query book element searches inside the array whether
the topic is present or not by checking ISBN numbers. What is the
time complexity of this method? Design a function
static Book []
Search WWH ::
Custom Search