CS301-lec42.ppt
Verified academic study resource for CS301 (Data Structures) under the Computer Science at Virtual University of Pakistan. This PPT document (Official Lecture Handouts & Highlighted Notes) covers Complete Course Handouts (Lectures 1 to 45) spanning approximately 450 pages across 8 curriculum modules, and is indexed for student examination review with instant in-browser preview and 100% free direct download.
- Course
- CS301 – Data Structures
- Faculty
- Computer Science
- Format
- PPT
- Type
- Handout
- Coverage
- Complete Course Handouts (Lectures 1 to 45)
- Tags
- SLIDES
Virtual University examiners construct 100% of objective MCQs and subjective marking schemes directly from the official CS301 handouts.
What this file covers — CS301 syllabus roadmap
- Core Architecture, Syntax & Primitive Data Structures — Lectures 1 to 6 (Pages 1 to 65). 15% Objective Marks (8–10 MCQs)
- Conditional Branching, Loops & Logical Control Flow — Lectures 7 to 12 (Pages 66 to 140). 18% Exam Marks (MCQs + 2-Mark Short Questions)
- Memory Management, Pointers, Arrays & Functions — Lectures 13 to 18 (Pages 141 to 215). 22% Exam Marks (High Yield for Midterms)
- Midterm Consolidation, Strings & Algorithm Synthesis — Lectures 19 to 22 (Pages 216 to 280). Midterm Exam Culmination (Lectures 1–22 Scope)
- Object-Oriented Paradigms: Classes & Data Abstraction — Lectures 23 to 29 (Pages 281 to 360). 16% Final-Term Marks (Core OO Concepts)
- Inheritance Hierarchies & Dynamic Polymorphism — Lectures 30 to 36 (Pages 361 to 435). 20% Final-Term Marks (Virtual Functions & V-Tables)
- Templates, Standard Library & Persistent File I/O — Lectures 37 to 41 (Pages 436 to 510). 14% Final-Term Marks (Generic Code & Streams)
- Final-Term Examination Dossier & Capstone Synthesis — Lectures 42 to 45 (Pages 511 to 585). Final-Term Exam Synthesis (Lectures 23–45 Scope)
Frequently asked questions
Where can I download CS301-lec42.ppt for free?
You can preview and download "CS301-lec42.ppt" (CS301 PPT, ~450 pages) directly from the MIHORA VU Study Library (https://study.mihora.tech/doc/cs301-lec42-ppt) with 100% free high-speed downloads and zero registration requirements.
What syllabus chapters and lectures are covered in this CS301 file?
This document covers Complete Course Handouts (Lectures 1 to 45) across 8 distinct lecture units (Lectures 1 to 6, Lectures 7 to 12, Lectures 13 to 18, Lectures 19 to 22, Lectures 23 to 29, Lectures 30 to 36, Lectures 37 to 41, Lectures 42 to 45), featuring comprehensive definitions, solved objective questions, and examiner marking rubrics.
What is the passing criteria for CS301 under the VU 20% Two-Half Rule?
Under official Virtual University regulations, students must score at least 20% in the First Half (Quizzes, Assignments, GDBs, and Midterm combined) AND independently at least 20% in the Final-Term examination paper. Scoring under 20% in the final exam results in an automatic F grade regardless of earlier marks.
Are CS301 solved past papers and handouts verified for 2026 exams?
Yes. All CS301 materials on MIHORA VU—including Moaaz, Waqar Siddhu, and team archives—are reviewed against the current VU syllabus to help students prepare for 2026 Midterm, Final-Term, and online quiz examinations.
Inside this file
Lecture No.42
Data Structures
Dr. Sohail Aslam
Example Hash Functions
If the keys are integers then key%T is
generally a good hash function, unless the
data has some undesirable features.
For example, if T = 10 and all keys end in
zeros, then key%T = 0 for all keys.
In general, to avoid situations like this, T
should be a prime number.
Collision
Suppose our hash function gave us 0 kiwi
the following values:
1
• hash("apple") = 5
hash("watermelon") = 3 2 banana
hash("grapes") = 8 3 watermelon
hash("cantaloupe") = 7
4
hash("kiwi") = 0
hash("strawberry") = 9 5 apple
hash("mango") = 6
hash("banana") = 2
6 mango
7 cantaloupe
hash("honeydew") = 6
8 grapes
9 strawberry
• Now what?
Collision
When two values hash to the same array
location, this is called a collision
Collisions are normally treated as “first
come, first served”—the first value that
hashes to the location gets it
We have to find something to do with the
second and subsequent values that hash to
this same location.
Solution for Handling collisions
Solution #1: Search from there for an empty
location
• Can stop searching when we find the
value or an empty location.
• Search must be wrap-around at the end.
Solution for Handling collisions
Solution #2: Use a second hash function
• ...and a third, and a fourth, and a fifth, ...
Solution for Handling collisions
Solution #3: Use the array location as the
header of a linked list of values that hash to
this location
Solution 1: Open Addressing
This approach of handling collisions is
called open addressing; it is also known as
closed hashing.
More formally, cells at h0(x), h1(x), h2(x),
… are tried in succession where
hi(x) = (hash(x) + f(i)) mod
TableSize,
with f(0) = 0.
The function, f, is the collision resolution
strategy.
Linear Probing
We use f(i) = i, i.e., f is a linear function
of i. Thus
location(x) = (hash(x) + i) mod
TableSize
The collision resolution strategy is called
linear probing because it scans the array
sequentially (with wrap around) in search
of an empty cell.
Linear Probing: insert
Suppose we want to add ...
seagull to this hash table 141
Also suppose: 142 robin
• hashCode(“seagull”) = 143 143 sparrow
• table[143] is not empty 144 hawk
• table[143] != seagull
145 seagull
• table[144] is not empty
146
• table[144] != seagull
• table[145] is empty
147 bluejay
Therefore, put seagull at 148 owl
...
location 145
Linear Probing: insert
Suppose you want to add ...
hawk to this hash table 141
Also suppose 142 robin
• hashCode(“hawk”) = 143 143 sparrow
• table[143] is not empty 144 hawk
• table[143] != hawk
145 seagull
• table[144] is not empty
146
• table[144] == hawk
hawk is already in the
147 bluejay
148 owl
table, so do nothing.
...
Linear Probing: insert
Suppose: ...
• You want to add cardinal to 141
this hash table 142 robin
• hashCode(“cardinal”) = 147
143 sparrow
• The last location is 148
144 hawk
• 147 and 148 are occupied
145 seagull
Solution:
146
• Treat the table as circular;
147 bluejay
after 148 comes 0
• Hence, cardinal goes in 148 owl
location 0 (or 1, or 2, or ...)
Linear Probing: find
Suppose we want to find ...
hawk in this hash table 141
We proceed as follows: 142 robin
• hashCode(“hawk”) = 143
•
143 sparrow
table[143] is not empty
• table[143] != hawk 144 hawk
• table[144] is not empty 145 seagull
• table[144] == hawk (found!) 146
We use the same 147 bluejay
procedure for looking
148 owl
things up in the table as
we do for inserting them ...
Linear Probing and Deletion
If an item is placed in array[hash(key)+4],
then the item just before it is deleted
How will probe determine that the “hole” does not
indicate the item is not in the array?
Have three states for each location
• Occupied
• Empty (never used)
• Deleted (previously used)
Clustering
One problem with linear probing
technique is the tendency to form
“clusters”.
A cluster is a group of items not
containing any open slots
The bigger a cluster gets, the more likely
it is that new values will hash into the
cluster, and make it ever bigger.
Clusters cause efficiency to degrade.
Quadratic Probing
Quadratic probing uses different formula:
• Use F(i) = i2 to resolve collisions
• If hash function resolves to H and a search in cell
H is inconclusive, try H + 12, H + 22, H + 32, …
ProbeMore CS301 files
- CS301 & CS301P Short Notes By Qalb-e-Momin .pdf (PDF · Handout)
- CS301 Handouts (Updated) by MS.pdf (PDF · Handout)
- CS301 Handouts by MS S26.pdf (PDF · Handout)
- CS301 Handouts by MS.pdf (PDF · Handout)
- CS301 Handouts by MS.pdf (PDF · Handout)
- CS301 HighLight Notes.pdf (PDF · Handout)
- CS301 Highlight Handout By Vu Topper RM.pdf (PDF · Handout)
- CS301 Highlight Handout By Vu Topper RM.pdf (PDF · Handout)