-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathnames.py
More file actions
31 lines (24 loc) · 1018 Bytes
/
names.py
File metadata and controls
31 lines (24 loc) · 1018 Bytes
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
import time
from binary_search_tree import BSTNode
start_time = time.time()
f = open('names_1.txt', 'r')
names_1 = f.read().split("\n") # List containing 10000 names
f.close()
f = open('names_2.txt', 'r')
names_2 = f.read().split("\n") # List containing 10000 names
f.close()
duplicates = [] # Return the list of duplicates in this data structure
# Replace the nested for loops below with your improvements
bst = BSTNode("Name")
for name in names_1:
bst.insert(name)
for name in names_2:
if bst.contains(name):
duplicates.append(name)
end_time = time.time()
print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
print (f"runtime: {end_time - start_time} seconds")
# ---------- Stretch Goal -----------
# Python has built-in tools that allow for a very efficient approach to this problem
# What's the best time you can accomplish? Thare are no restrictions on techniques or data
# structures, but you may not import any additional libraries that you did not write yourself.