Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

translate this python code into Java code lastest version: import urllib file = urllib.request.urlopen('...') words = [] for line in file: decoded_line = line.decode(utf-8) words.append(decoded_line[:-1])

 translate this python code into Java code lastest version:


import urllib file = urllib.request.urlopen('...') words = [] for line in file: decoded_line = line.decode("utf-8") words.append(decoded_line[:-1]) ma_size = len(words) + int(len(words)/5) my_hash_table = [[] for _ in range(ma_size)] n_collisions = 0 def Hash(ss): ans = 0 jj = 1 for i in range(len(ss)): ans = ans + (i+jj)*ord(ss[i]) jj = 2*jj + 3 return ans%ma_size def insert_word(my_hash_table, value): my_key = Hash(value) my_hash_table[my_key].append(value) def number_collisions(): n_collisions = 0 for i in range(hs_size): if(len(my_hash_table[i])>1): n_collisions+= len(my_hash_table[i])-1 return n_collisions

for w in words: insert_word(my_hash_table,w) print("Total percentage of collisions are : ",100*number_collisions()/len(words),"%")

Step by Step Solution

3.48 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

Here is the equivalent Java code for the provided Python code using the latest version of Java Java ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Analytics Data Analysis And Decision Making

Authors: S. Christian Albright, Wayne L. Winston

7th Edition

0357109953, 978-0357109953

More Books

Students also viewed these Programming questions

Question

Quadrilateral EFGH is a kite. Find mG. E H Answered: 1 week ago

Answered: 1 week ago