首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
C200留学生编程辅导、讲解Java,c++程序语言、Python程序辅导 辅导留学生 Statistics统计、回归、迭代|辅导留学生Prolog
项目预算:
开发周期:
发布时间:
要求地区:
C200 Final Fall 2020
School of Informatics, Computing, and Engineering
Contents
Introduction 1
Problem 1: Pagerank 3
Starting Code for Problem 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Output for Problem 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Deliverables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Problem 2: Reverse Polish Notation 5
Starting Code to Problem 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Output for Problem 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Deliverables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Problem 3: Database Queries 8
Output to Problem 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Deliverables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Starting Code to Problem 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Final Fall 2020 Page 1
Introduction
This is your final. You are required to work on this by yourself. You must implement the programs
on your own–do 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 not
in your repository, please let us know on Piazza.
For grading purposes (as you have seen in the previous assignments), there will be additional
tests that we will run. These parameters we pass in will not be edge cases, just a variation in
values (that logically fit with the problem).
There will be no grade request for this Final. Please ensure the file is in GitHub and is
pushed 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. Each
problem will be looked over, however syntax errors that prevent the file or function from running
will significantly reduce the partial credit. It is better to have a function that gives back incorrect
values versus a function that does not let the program run.
You will complete this before 11pm, Sunday, December 13th 2020.
Final Fall 2020 Page 2
Problem 1: PageRank
Read the accompanying lecture notes from Cornell University on the pagerank algorithm (which
we will try to attach to the Canvas Assignment). While it is somewhat old, it still forms, more or
less, the foundation for internet search. Your task is to implement the algorithm shown in the
Dynamical 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 have
a sequence of vectors v0, v1, v2, . . . and are interested in observing how vi+1 changes from vi
. If
the change decreases monotonically (as we’ve discussed in class), then we can write a bound.
How can we measure a change? We use Euclidean distance (which we’ve 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 with
matrix multiplication while the norm of the difference is greater than tau.
1 def convergence(matrix, vector, tau):
Problem 2: Reverse Polish Notation
Please read the notes Reverse Polish Notation to understand how RPN (Reverse Polish Notation)
works. These also describe the algorithm. To simplify the problem, we’ll assume the
numbers are integers, not floats. The only additional modifications you have to address are:
• negative numbers
• a new operator abs
You can use .isdigit() to discover whether a string is a non-negative number:
1 >>> "0".isdigit()
2 True
3 >>> "1".isdigit()
4 True
5 >>> "*".isdigit()
6 False
7 >>> "-2".isdigit()
8 False
We can determine if a string is a negative number by using in. We’ll let you read about this
function (we covered this early on). We assume that a negative number has only one negative
value, i.e., -1, -2, -3, . . .. You can use string functions to remove the negation and change the
sign of the number. For example,
1 >>> x = "-2"
2 >>>
3 -2
4 >>>
Here are the expressions, and intermediate values, for the RPN:
1 3, 1, 2, +, * evaluates:
2 3,1,2,+
3 3,3,*
4 9
5
6 4, 2, 5, *, +, 1, 3, 2, *, +, / evaluates:
7 4, 2, 5, *
8 4,10,+
9 14
10 14,1,2,3,*
11 14,1,6,+
12 14,7,/
13 2
Final Fall 2020 Page 5
14
15 3 4 + 5 2 - * evaluates:
16 3,4,+
17 7,5,2,-
18 7,3,*
19 21
20
21 -2, -2, * evaluates
22 -2, -2, *
23 4
24
25 -200 abs 2 / evaluates:
26 -200 abs
27 200, 2, /
28 100
A 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**3
4 True
Lastly, 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 a
list (another hint).
RPN
1 class stack:
2 """
3 DO NOT MODIFY, only use this class
4 """
5 # Code omitted for space in PDF
6
7 class RPS_calculator:
8 def __init__(self, exp):
9 """
10 TODO: complete the constructor
11
12 Parameter: A string representing RPN
13 No return statement
14 """
15 pass
16
Final Fall 2020 Page 6
17
18 def run(self):
19 """
20 TODO: complete the function
21
22 Parameter: No parameters
23 Returns: A numberical value from the expression
24 """
25 pass
26
27
28 def __str__(self):
29 """
30 DO NOT MODIFY
31 """
32 return str(self.calc)
33
34
35 if __name__=="__main__":
36 print("\n"*3)
37 print("Problem 2")
38 RPSlist = ["3 1 2 + *", "4 2 5 * + 1 3 2 * + /", \
39 "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 Output
Problem 2
RPN: 3 1 2 + * Run: 9.0
RPN: 4 2 5 * + 1 3 2 * + / Run: 2.0
RPN: 3 4 + 5 2 - * Run: 21.0
RPN: -2 -2 * Run: 4.0
RPN: -200 abs 2 / Run: 100.0
Programming Problem 2
• Complete the RPN class
Final Fall 2020 Page 7
Problem 3: Queries
In class we were introduced to SQL and the relational model. Create a relation G with the data
shown 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 you’ve created and populated your table, write the following queries:
1. Select all the tuples
2. Select all the tuples whose edges are greater than 2
3. Select all the paths of length 2
4. Select the path of length 2 that has the greatest sum and display the sum–a hint, you can
add values in the SELECT clause – investigate this on your own.
5. Give the average of the edge weights
6. Give the edges whose values are greater than the average weight
The average of the edge weights is:
ave(edges) = (1 + 3 + 5 + 5 + 2)/5 = 3.2
In Python:
1 >>> edge = [1,3,5,5,2]
2 >>> sum(edge)/len(edge)
3 3.2
Final Fall 2020 Page 8
Output
Problem 3
Query 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 9
Programming 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 file
SQL Queries
1 import sqlite3
2 def createTable():
3 """
4 THIS FUNCTION ONLY RETURNS A STRING.
5 Do NOT call any ‘sqlite3‘ functions here
6
7 EXAMPLE: Complete the creating of a table
8 """
9 return "CREATE TABLE G (X text, Y text, Value real)"
10
11
12 def insert1():
13 # Comment omitted in PDF for space
14 return ""
15
16 def insert2():
Final Fall 2020 Page 10
17 # Comment omitted in PDF for space
18 return ""
19
20 def insert3():
21 # Comment omitted in PDF for space
22 return ""
23
24 def insert4():
25 # Comment omitted in PDF for space
26 return ""
27
28 def insert5():
29 # Comment omitted in PDF for space
30 return ""
31
32
33 def query1():
34 """
35 THIS FUNCTION ONLY RETURNS A STRING.
36 Do NOT call any ‘sqlite3‘ functions here
37
38 TODO: Complete the QUERY 1
39 """
40 return ""
41
42 def query2():
43 # Comment omitted in PDF for space
44 return ""
45
46 def query3():
47 # Comment omitted in PDF for space
48 return ""
49
50 def query4():
51 # Comment omitted in PDF for space
52 return ""
53
54 def query5():
55 # Comment omitted in PDF for space
56 return ""
57
58 def query6():
59 # Comment omitted in PDF for space
60 return ""
61
62
63 if __name__=="__main__":
Final Fall 2020 Page 11
64 ####
65 # DO NOT MODIFY CODE IN THIS SECTION
66 # No code will be graded in this section
67 #
68 # All code must be answered in the functions above
69 ####
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())
76
77 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()
83
84
85 #QUERY 1 Select All the tuples
86 print("Query 1")
87 for i in my_cursor.execute(query1()):
88 print(i)
89
90 print("*"*30)
91 #QUERY 2 Select All the edges greater than 2
92 print("Query 2")
93 for i in my_cursor.execute(query2()):
94 print(i)
95
96 print("*"*30)
97 #QUERY 3 Select All the paths of length 2
98 print("Query 3")
99 for i in my_cursor.execute(query3()):
100 print(i)
101
102 print("*"*30)
103 #QUERY 4 Select the path of length
104 # 2 that has the greatest sum and display the sum
105 print("Query 4")
106 for i in my_cursor.execute(query4()):
107 print(i)
108
109 print("*"*30)
110 #QUERY 5 Give the average of the edge weights
Final Fall 2020 Page 12
111 print("Query 5")
112 for i in my_cursor.execute(query5()):
113 print(i)
114
115
116 print("*"*30)
117 #QUERY 6 Give the edges whose values are greater than the average ←-
weight
118 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
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做 program、代写 c++设计程...
2024-12-23
comp2012j 代写、代做 java 设...
2024-12-23
代做 data 编程、代写 python/...
2024-12-23
代做en.553.413-613 applied s...
2024-12-23
代做steady-state analvsis代做...
2024-12-23
代写photo essay of a deciduo...
2024-12-23
代写gpa analyzer调试c/c++语言
2024-12-23
代做comp 330 (fall 2024): as...
2024-12-23
代写pstat 160a fall 2024 - a...
2024-12-23
代做pstat 160a: stochastic p...
2024-12-23
代做7ssgn110 environmental d...
2024-12-23
代做compsci 4039 programming...
2024-12-23
代做lab exercise 8: dictiona...
2024-12-23
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!