” C200留学生编程 辅导、 写作Java,c++程序语言C200 Final Fall 2020School of Informatics, Computing, and EngineeringContentsIntroduction 1Problem 1: Pagerank 3Starting Code for Problem 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Output for Problem 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Deliverables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Problem 2: Reverse Polish Notation 5Starting Code to Problem 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Output for Problem 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Deliverables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Problem 3: Database Queries 8Output to Problem 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Deliverables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Starting Code to Problem 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Final Fall 2020 Page 1IntroductionThis is your final. You are required to work on this by yourself. You must implement the programson your owndo not copy any existing programs (if they, indeed, do exist).We will not be answering questions on Piazza that will lead to an answer. If the files are notin your Repository, please let us know on Piazza.For grading purposes (as you have seen in the previous assignments), there will be additionaltests that we will run. These parameters we pass in will not be edge cases, just a variation invalues (that logically fit with the problem).There will be no grade request for this Final. Please ensure the file is in GitHub and ispushed before the due date and there are no syntax errors.For all problems, we will be giving partial credit based on the correctness of logic. Eachproblem will be looked over, however syntax errors that prevent the file or function from runningwill significantly reduce the partial credit. It is better to have a function that gives back incorrectvalues versus a Function that does not let the program run.You will complete this before 11pm, Sunday, December 13th 2020.Final Fall 2020 Page 2Problem 1: PageRankRead the accompanying lecture notes from Cornell University on the pagerank algorithm (whichwe will try to attach to the Canvas Assignment). While it is somewhat old, it still forms, more orless, the foundation for internet search. Your task is to implement the algorithm shown in theDynamical systems point of view. We will add a little to help you.The algorithm does not give a way to converge. We will describe it here. Suppose you havea sequence of vectors v0, v1, v2, . . . and are interested in observing how vi+1 changes from vi. Ifthe change decreases monotonically (as weve discussed in class), then we can write a bound.How can we measure a change? We use Euclidean distance (which weve seen):We show this is correct using the console:We can simplify using the linear algebra from numpy to find the norm:You will, therefore, we comparing the last vector with the current vector and continue withmatrix multiplication while the norm of the difference is greater than tau.1 def convergence(matrix, vector, tau):Problem 2: Reverse Polish NotationPlease read the notes Reverse Polish Notation to understand how RPN (Reverse Polish Notation)works. These also describe the algorithm. To simplify the problem, well assume thenumbers are integers, not floats. The only additional modifications you have to address are: negative numbers a new operator absYou can use .isdigit() to Discover whether a string is a non-negative number:1 0.isdigit()2 True3 1.isdigit()4 True5 *.isdigit()6 False7 -2.isdigit()8 FalseWe can determine if a string is a negative number by using in. Well let you read about thisfunction (we covered this early on). We assume that a negative number has only one negativevalue, i.e., -1, -2, -3, . . .. You can use string functions to remove the negation and change thesign of the number. For example,1 x = -22 A Python Expression you create3 -24 Here are the expressions, and intermediate values, for the RPN:1 3, 1, 2, +, * evaluates:2 3,1,2,+3 3,3,*4 956 4, 2, 5, *, +, 1, 3, 2, *, +, / evaluates:7 4, 2, 5, *8 4,10,+9 1410 14,1,2,3,*11 14,1,6,+12 14,7,/13 2Final Fall 2020 Page 51415 3 4 + 5 2 – * evaluates:16 3,4,+17 7,5,2,-18 7,3,*19 212021 -2, -2, * evaluates22 -2, -2, *23 42425 -200 abs 2 / evaluates:26 -200 abs27 200, 2, /28 100A hint on simplifying the problem. We Can envision a dictionary that maps strings to functions.For example,1 d = {**:lambda x,y: x**y}2 s = **3 d[s](2,3) == 2**34 TrueLastly, we assume the input is a string where values and operators are separated by spaces.For example, 3 4 + would be the string 3 4 +. You know several ways to turn this string into alist (another hint).RPN1 class stack:2 3 DO NOT MODIFY, only use this class4 5 # Code omitted for space in PDF67 class RPS_calculator:8 def __init__(self, exp):9 10 TODO: complete the constructor1112 Parameter: A string representing RPN13 No return statement14 15 pass16Final Fall 2020 Page 61718 def run(self):19 20 TODO: Complete the function2122 Parameter: No parameters23 Returns: A numberical value from the expression24 25 pass262728 def __str__(self):29 30 DO NOT MODIFY31 32 return str(self.calc)333435 if __name__==__main__:36 print(\n*3)37 print(Problem 2)38 RPSlist = [3 1 2 + *, 4 2 5 * + 1 3 2 * + /, \\r39 3 4 + 5 2 – *, -2 -2 *, -200 abs 2 /]40 for rpn in RPSlist:41 x = RPS_calculator(rpn)42 print(RPN:, rpn, \t Run:, x.run())Program OutputProblem 2RPN: 3 1 2 + * Run: 9.0RPN: 4 2 5 * + 1 3 2 * + / Run: 2.0RPN: 3 4 + 5 2 – * Run: 21.0RPN: -2 -2 * Run: 4.0RPN: -200 abs 2 / Run: 100.0Programming Problem 2 Complete the RPN classFinal Fall 2020 Page 7Problem 3: QueriesIn class we were introduced to SQL and the relational model. Create a relation G with the datashown in Table 1 that describes the distance traveling from destination X to destinate Y in miles.Table 1: Relation G and distances from X to Y in miles.Once youve created and populated your table, write the following queries:1. Select all the tuples2. Select all the tuples Whose edges are greater than 23. Select all the paths of length 24. Select the path of length 2 that has the greatest sum and display the suma hint, you canadd values in the SELECT clause investigate this on your own.5. Give the average of the edge weights6. Give the edges whose values are greater than the average weightThe average of the edge weights is:ave(edges) = (1 + 3 + 5 + 5 + 2)/5 = 3.2In Python:1 edge = [1,3,5,5,2]2 Sum(edge)/len(edge)3 3.2Final Fall 2020 Page 8OutputProblem 3Query 1(A, B, 1.0)(A, C, 2.0)(A, D, 5.0)(B, D, 3.0)(C, D, 5.0)******************************Query 2(A, D, 5.0)(B, D, 3.0)(C, D, 5.0)******************************Query 3(A, B, D)(A, C, D)******************************Query 4(A, C, D, 7.0)******************************Query 5(3.2,)******************************Query 6(A, D)(C, D)Final Fall 2020 Page 9Programming Problem 3 Finish the SQL queries for the functions in the assignment document All of the functions return strings and do not use any functions from sqlite3 We created the table (createTable), all you have to do is insert and query. Insert the rows into the data insert1 insert2 insert3 insert4 insert5 Queries listed in the problem statement query1 query2 query3 query4 query5 query6 There are no Test cases in the test fileSQL Queries1 import sqlite32 def createTable():3 4 THIS FUNCTION ONLY RETURNS A STRING.5 Do NOT call any sqlite3 functions here67 EXAMPLE: Complete the creating of a table8 9 return CREATE TABLE G (X text, Y text, Value real)101112 def insert1():13 # Comment omitted in PDF for space14 return 1516 def insert2():Final Fall 2020 Page 1017 # Comment omitted in PDF for space18 return 1920 def insert3():21 # Comment omitted in PDF for space22 return 2324 def insert4():25 # Comment omitted in PDF for space26 return 2728 def insert5():29 # Comment omitted in PDF for space30 return 313233 def query1():34 35 THIS FUNCTION ONLY RETURNS A STRING.36 Do NOT call any sqlite3 functions here3738 TODO: Complete the QUERY 139 40 return 4142 def query2():43 # Comment Omitted in PDF for space44 return 4546 def query3():47 # Comment omitted in PDF for space48 return 4950 def query4():51 # Comment omitted in PDF for space52 return 5354 def query5():55 # Comment omitted in PDF for space56 return 5758 def query6():59 # Comment omitted in PDF for space60 return 616263 if __name__==__main__:Final Fall 2020 Page 1164 ####65 # DO NOT MODIFY CODE IN THIS SECTION66 # No code will be graded in this section67 #68 # All code must be answered in the functions above69 ####70 print(\n*3)71 print(Problem 3)72 connection = sqlite3.connect(final.db)73 my_cursor = connection.cursor()74 my_cursor.execute(DROP TABLE IF EXISTS G)75 my_cursor.execute(createTable())7677 my_cursor.execute(insert1())78 my_cursor.execute(insert2())79 my_cursor.execute(insert3())80 my_cursor.execute(insert4())81 my_cursor.execute(insert5())82 connection.commit()838485 #QUERY 1 Select All the tuples86 print(Query 1)87 for i in my_Cursor.execute(query1()):88 print(i)8990 print(**30)91 #QUERY 2 Select All the edges greater than 292 print(Query 2)93 for i in my_cursor.execute(query2()):94 print(i)9596 print(**30)97 #QUERY 3 Select All the paths of length 298 print(Query 3)99 for i in my_cursor.execute(query3()):100 print(i)101102 print(**30)103 #QUERY 4 Select the path of length104 # 2 that has the greatest sum and display the sum105 print(Query 4)106 for i in my_cursor.execute(query4()):107 print(i)108109 print(**30)110 #QUERY 5 Give the average of the edge weightsFinal Fall 2020 Page 12111 print(Query 5)112 for i in my_cursor.execute(query5()):113 print(i)114115116 print(**30)117 #QUERY 6 Give the edges whose values are greater than the average -weight118 print(Query 6)119 for i in my_cursor.execute(query6()):120 print(i)121 Connection.close()Final Fall 2020 Page 13如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。