-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1probingpython
More file actions
52 lines (43 loc) · 1.31 KB
/
1probingpython
File metadata and controls
52 lines (43 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def kmodn(k, n):
return k % n
def linear_probing(key, value, arr):
count = 0
key_n = key
while arr[key_n] != -1:
count += 1
key_n = (key + count) % len(arr)
arr[key_n] = value
def quadratic_probing(key, value, arr):
count = 0
key_n = key
while arr[key_n] != -1:
count += 1
key_n = (key + count ** 2) % len(arr)
arr[key_n] = value
user_inp = int(input("Enter the number of clients: "))
tele_book = [-1 for _ in range(user_inp)]
temp = {}
for i in range(user_inp):
x = int(input("Enter telephone number: "))
loc = kmodn(x, user_inp)
print(f"Initial location: {loc}")
if tele_book[loc] == -1:
tele_book[loc] = x
else:
if x in temp:
temp[x] += 1
else:
temp[x] = 1
print(f"Collision occurred at location {loc}")
print("Choose probing method:")
print("1. Linear Probing")
print("2. Quadratic Probing")
probe_choice = int(input("Enter your choice: "))
if probe_choice == 1:
linear_probing(loc, x, tele_book)
elif probe_choice == 2:
quadratic_probing(loc, x, tele_book)
else:
print("Invalid choice! Please select 1 or 2.")
print("Current telephone book:", tele_book)
print("Collision count:", temp)