CS301-Lec43 handout - CS301 Data Structures Lecture No. 43...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS301 – Data Structures Lecture No. 43 ___________________________________________________________________ Data Structures Lecture No. 43 Reading Material Data Structures and Algorithm Analysis in C++ Chapter. 5, 7 5.4, 5.5, 5.6, 7.1 Summary Hashing Animation Applications of Hashing When Hashing is Suitable? Sorting Elementary Selection Algorithms Selection Sort Hashing Animation In the previous lecture, we discussed about collision strategies in hashing. We studied three solutions, Linear Probing, Quadratic Probing and Linked List chaining. Hashing is vast research field, which covers hash functions, storage and collision issues etc. At the moment, we will see hashing in implementation of table ADT. Operations of insert , delete and find are performed in constant time using this hashing strategy. Constant time means the time does not increase with the increase in data volume. However, if collisions start happening then the time does not remain constant. Especially if we see linear probing , we had to insert the data by sorting the array sequentially. Similar was the case with quadratic . In case of linked list , we start constructing linked list that takes time and memory. But later we will see some situations where hashing is very useful. Today, we will study these three strategies of hash implementation using animations. These animations will be provided to you in a Java program. It is important to mention here that all the data structures and algorithms we have studied already can be implemented using any of the languages of C/C++ or Java . However, it is an important decision to choose the programming language because every language has its strong area, where it has better application. Java has become very popular because of its facilities for Internet . As you already know C++ , therefore, Java is easy to learn for you. The syntax is quite similar. If we show you the java code you will say it is C++. Let’s see the hashing animation. This animation will be shown in the browser. This is an applet written in java language. We will see linear probing, quadratic probing and link list chaining in it. This is an example of how do we solve collision. Page 1 of 7
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS301 – Data Structures Lecture No. 43 ___________________________________________________________________ We have an array shown in four different columns. The size of the array is 100 and the index is from 0 to 99. Each element of the array has two locations so we can store 200 elements in it. When we have first collision the program will use the 2 nd part of the array location. When there is a 2 nd collision the data is stored using the linear probing. At the top right corner we have hash function x and its definition is “mod 100”. That is when a number is passed to it, it will take mod with 100 and return the result which is used as index of the array. In this example we are using numbers only and not dealing with the characters. We also
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/21/2010 for the course CS CS301 taught by Professor Dr.naveed malik during the Spring '10 term at Virtual University of Pakistan.

Page1 / 7

CS301-Lec43 handout - CS301 Data Structures Lecture No. 43...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online