AA_Assignement1234567
AA_Assignement1234567
AA_Assignement1234567
MODULE 1
1) A hash table uses open addressing with linear probing. Write algorithms
for INSERT and SEARCH operations in Linear Probing. Given a hash
function h(x) = x mod 10, insert the following keys into the table and
resolve collisions using linear probing:
Keys: 14,51,30,21,59,32,31,79 in order.
Show the final state of the hash table after all insertions.
6) Given a set of keys {10, 22, 31, 4, 15, 28, 17, 88, 59}, show how they
would be stored in a hash table of size 10 using a division hash function
h(k) = k mod 10 and handle collisions using separate chaining.
7) Consider the hash function of size 13. Apply chaining technique to insert
the following keys 18,41,22,44,59,32,31,73,55 into the hash table having
a hash function h(x)=x mod 13. Comment on the time complexity of
dictionary operations when chaining is used
8) Consider a hash table that uses open addressing with linear probing.
Assume the hash table has a size of 10 and uses the hash function h(k)=k
mod 10. You are given the following sequence of keys to insert into the
hash table: 21, 10, 31, 25, 33, 12, and 44.
a) Show the state of the hash table after inserting each key, using linear
probing to resolve collisions. Clearly indicate how collisions are handled
for each insertion.
a) Explain the concept of Perfect Hashing. How does it differ from other
hashing techniques like open addressing and separate chaining?
10) Consider a static set of distinct keys: {21, 34, 48, 59, 72, 85}.
Design a two-level perfect hashing scheme for this set using an
appropriate first-level and second-level hash function. Provide detailed
steps in your design.
11) Insert the following sequence of numbers into an empty Red-Black
Tree: 10, 20, 30, 15, 25, 40, 50, 35. Show the tree after each insertion and
colour adjustment, detailing any rotations or recoloring.
12) Consider the hash function of size 11. Apply chaining technique to
insert the following keys 10,22,31,4,15,28,17,88,59 into the hash table
having a hash function h(k)=kmod 11. Comment on the time complexity
of dictionary operations when chaining is used
MODULE 2
1) A rod of length 8 and price list [1, 5, 8, 9, 10, 17, 17, 20].
What is the maximum profit that can be obtained by cutting the rod?
2) Given a rod of length 8 and the following prices for each length of the
rod, determine the maximum obtainable profit using dynamic
programming.
Length 1 2 3 4 5 6 7 8
Price 1 5 8 9 10 17 17 20
3) Construct an OBST for the keys [5, 10, 15, 20] with search probabilities
[0.1, 0.2, 0.4, 0.3] & dummy node probabilities [0.05, 0.1, 0.1, 0.05,
0.05]. How do the dummy nodes affect the overall search cost compared
to the case without dummy nodes?
4) Consider the keys K={1,2,3,4}, with P={0.1,0.2,0.4,0.3} and
Q={0.05,0.1,0.05,0.05,0.1}. Compute the OBST and draw its structure.
What is the expected cost of the tree?
6) Construct the Huffman Tree for the given characters and their
frequencies.
Given character frequencies:
Character Frequency
A 5
B 9
C 12
D 13
E 16
F 45
(b) Based on the tree you constructed, assign Huffman codes to each
character.
(c) What is the average length of the Huffman code? Show your
calculations.
(d) Compare the total number of bits required to encode the message
using Huffman coding versus a fixed-length code.
6) Given the following set of activities with their start and finish times. Find
the maximum number of activities that can be performed by a single person,
assuming that a person can only work on one activity at a time.
Activity A1 A2 A3 A4 A5 A6
Start 1 3 0 5 5 8
Finish 2 4 6 7 9 9
Solve this using the greedy method and explain the reasoning behind your
selection of activities.
C1 C2 C3 C4
C1 0 10 15 20
C2 10 0 35 25
C3 15 35 0 30
C4 20 25 30 0