Coding question need to do. Asap.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Coding question need to do. Asap. 

 

Python solution without table (~156ms):
def multiply(self, a, b):
type A: List[List[int]]
type B: List[List[int]]
:rtype: List[List[int]]
if a is None orb is None:
return None
m, n, l = len (a), len(b[0]), len (b[0])
if len (b) != n:
raise Exception ("A's column number must be equal to B's row number.")
c = [[0 for _ in range(1)] for _ in range(m)]
for i, row in enumerate(a):
for k, eleA in enumerate(row):
if eleA:
for j, eleB in enumerate(b[k]):
if eleB:
c[i][j] += eleA * eleB
return c
#Python solution with only one table for B (~196ms):
def multiply(self, a, b):
type A: List[List[int]]
type B: List[List[int]]
rtype: List[List[int]]
if a is None or b is None:
return None
m, n, l =len (a), len(a[0]), len (b[0])
if len (b) != n:
raise Exception ("A's column number must be equal to B's row number.")
c = [[0 for _ in range(l)] for _ in range(m)]
table_b={
for k, row in enumerate(b):
table_b[k] =
forj, eleB in enumerate (row):
if eleB:
table_b[k] [j] = eleB
for i, row in enumerate(a):
for k, eleA in enumerate(row):
if eleA:
for j, eleB in table_b[k].iteritems():
c[i][j] += eleA * eleB
return c
# Python solution with two tables (~196ms):
def multiply(self, a, b):
type A: List[List[int]]
type B: List[List[int]]
rtype: List[List[in t]]
if a is None or b is None:
return None
m, n = len (a), len(b[0])
if len (b) != n:
raise Exception ("A's column number must be equal to B's row number.")
1 = len(b[0])
table_a, table_b= }, {
for i, row in enumerate(a):
for j, ele in enumerate(row):
if ele:
if i not in table_a:
table_a[i] = {
table_a[i][i] = ele
for i, row in enumerate(b):
forj, ele in enumerate(row):
if ele:
if i not in table_b:
table_b[i] = {
table_b[i][j] = ele
c = [[0 for j in range(1)] for i in range(m)]
fori in table_a:
fork in table_a[i]:
if k not in table_b:
Transcribed Image Text:Python solution without table (~156ms): def multiply(self, a, b): type A: List[List[int]] type B: List[List[int]] :rtype: List[List[int]] if a is None orb is None: return None m, n, l = len (a), len(b[0]), len (b[0]) if len (b) != n: raise Exception ("A's column number must be equal to B's row number.") c = [[0 for _ in range(1)] for _ in range(m)] for i, row in enumerate(a): for k, eleA in enumerate(row): if eleA: for j, eleB in enumerate(b[k]): if eleB: c[i][j] += eleA * eleB return c #Python solution with only one table for B (~196ms): def multiply(self, a, b): type A: List[List[int]] type B: List[List[int]] rtype: List[List[int]] if a is None or b is None: return None m, n, l =len (a), len(a[0]), len (b[0]) if len (b) != n: raise Exception ("A's column number must be equal to B's row number.") c = [[0 for _ in range(l)] for _ in range(m)] table_b={ for k, row in enumerate(b): table_b[k] = forj, eleB in enumerate (row): if eleB: table_b[k] [j] = eleB for i, row in enumerate(a): for k, eleA in enumerate(row): if eleA: for j, eleB in table_b[k].iteritems(): c[i][j] += eleA * eleB return c # Python solution with two tables (~196ms): def multiply(self, a, b): type A: List[List[int]] type B: List[List[int]] rtype: List[List[in t]] if a is None or b is None: return None m, n = len (a), len(b[0]) if len (b) != n: raise Exception ("A's column number must be equal to B's row number.") 1 = len(b[0]) table_a, table_b= }, { for i, row in enumerate(a): for j, ele in enumerate(row): if ele: if i not in table_a: table_a[i] = { table_a[i][i] = ele for i, row in enumerate(b): forj, ele in enumerate(row): if ele: if i not in table_b: table_b[i] = { table_b[i][j] = ele c = [[0 for j in range(1)] for i in range(m)] fori in table_a: fork in table_a[i]: if k not in table_b:
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY