1. Homepage
  2. Programming
  3. COMPSCI220 - CS220 Algorithms and Data Structures - Assignment 1

COMPSCI220 - CS220 Algorithms and Data Structures - Assignment 1

Engage in a Conversation
COMPSCI 220CS220Algorithms and Data StructuresAssignmentPythonAuckland澳洲

Compsci 220 CourseNana.COM

Assignment 1 CourseNana.COM

Due: Monday, 8th August, by 10pm. Semester 2, 2022 CourseNana.COM

There are five problems listed below. To get full credit for this assignment you need to complete all of them! CourseNana.COM

If you are stuck or confused by any of the problems, feel free to post on Piazza! CourseNana.COM

Show all working; if you do not show your work the mark will be reduced. You should submit via Canvas a single PDF file containing the answers to the written questions. A scanned handwritten submission is acceptable if and only if it is very neatly written (if it’s hard to read, it will not be marked). If typing the assignment, do the best you can with mathematical symbols. For exponents, write something like CourseNana.COM

2^n CourseNana.COM

if using plain text. Use LaTeX if you really want it to look good.
Answers to programming questions must be submitted via the automated marker system:
CourseNana.COM

Please try to submit your assignments no later than 5 min before the due time. Even though the time is a universal thing your watch and Canvas built-in clock could show the different time. It is quite possible that you might be on time on your watch and late on Canvas. To avoid these kind of situation submit the assignments at least 5 min before the due time. CourseNana.COM

Please note that late assignments cannot be marked under any circumstances. (With that said: if you find yourself unable to complete this assignment due to illness, injury, or personal/familial misfortune, please email us as soon as possible. We can come up with solutions to help you succeed in CS220!) CourseNana.COM

Best of luck, and enjoy the problems! CourseNana.COM

1. (10 marks) Suppose you are given 3 algorithms A1, A2 and A3 solving the same problem. You know that in the the running times are CourseNana.COM

T1(n) = n5n,    T2(n) = 210n2 + n3,    T3(n) = 105 log10(nn)

CourseNana.COM

(a) Which algorithm is the fastest for very large inputs? Which algorithm is the slowest forvery large inputs? (Justify your answer.) CourseNana.COM

(b) For which problem sizes is A2 the better than A1? (Justify your answer.) CourseNana.COM

(c) For which problem sizes is A2 the better than A3? (Justify your answer.) CourseNana.COM

2. (10 marks) Asymptotic Notations: CourseNana.COM

1.     (a)  Prove using definitions only that nnlog(n) is not O(nn). (HINT: proof by contradiction) CourseNana.COM

2.     (b)  Prove that n3 50 is Ω(n2), either with limit laws or definitions. CourseNana.COM

3.     (c)  Prove that ?(15)n2 log(5n) + 0.4n + n is Θ(n2 log(n)) using definitions only. CourseNana.COM

4.     (d)  Suppose that f, h, g, k are functions and that f = h · g + k. Suppose further, that h is O(n2), g is Θ(log(n)) and k is Ω(n). What do we know about f? State everything we can determine for full marks. CourseNana.COM

3. (10 marks) Elementary operations and algorithms: CourseNana.COM

(a) Work out the number of elementary operations in the following algorithm. For this exercise only count the constant number C of elementary operations as executed on lines 2 and 4. CourseNana.COM

1   function Blah (positive integer n) CourseNana.COM

2       fori2 to n do CourseNana.COM

3       Constant number C of elementary operations. CourseNana.COM

4           for j 1 to i do CourseNana.COM

5           Constant number C of elementary operations.

CourseNana.COM

(b) Work out the number of elementary operations the following algorithm uses in an average case. You can assume that the probability of getting a number divisible by 3 is 1/ 3 CourseNana.COM

1    function Meh (positive integer n) CourseNana.COM

2       ifn%3=0do CourseNana.COM

3           for i 0 to n 1 do CourseNana.COM

4               for j 0 to n 1, j j + 2 do CourseNana.COM

5                   if i=j do CourseNana.COM

6                       for k0 to n4, kk+n2 do CourseNana.COM

7                         Constant number C of elementary operations. CourseNana.COM

8                   else CourseNana.COM

9                     Constant number C of elementary operations. CourseNana.COM

10     else CourseNana.COM

11        Execute Meh(3n2)

CourseNana.COM

4. (10 marks) Elementary operations and algorithms: CourseNana.COM

(a)  What is the explicit form of the following recurrence relation: T(n) = 3T(n/3) + 1; T(1) = 1. CourseNana.COM

(b)  What is the explicit form of the following recurrence relation: T(n) = T(n 1) + log2 n; T(0) = 0. Hint n! is approximately CourseNana.COM

  CourseNana.COM

5. (10 marks) Programming question: CourseNana.COM

·      Question: Write a program that takes an input as described below, and prints an output also as described below. The program must work with the automated marker. This question is purely for you to obtain familiarity with the automated marker system which will be used more in later assignments. CourseNana.COM

·      Input: Input consists of many lines. At the end of each line there is hash symbol #. For example:
blah#
45 67#
CourseNana.COM

ddgfh fjhg gjkhgk# CourseNana.COM

·      Output: Output consists of the same lines as the input but without #. For example, for the input given above the output should be:
blah
45 67
CourseNana.COM

ddgfh fjhg gjkhgk CourseNana.COM

·      Language: You can use Python, Python, Python, or Python, whichever you fancy the most! CourseNana.COM

·      Number of attempts: There is a limit of 10 submission attempts for this assignment in order to get full mark. The last submission submitted before the assignment deadline will be the one marked. Beyond 10 submissions, a penalty will apply, but every student who eventually submits a correct answer on time will get 75% for this question. In future assignments, restrictions and penalties may be stronger. CourseNana.COM

·      Useful information: You can assume that input will come from standard input (stdin) in a stream that represents one string per line. Output should be sent to standard output. In the automarker, the input will come from a file that is piped to standard in and the output redirected to a file, but your program shouldn’t know that. CourseNana.COM

Your answer to each question should be a single file (containing all nonstandard classes you use). You may assume that the automarker has access to all standard libraries. CourseNana.COM

If your submission was put in the queue before the assignment due time then it will be accepted. All submissions after the assignment due time will not be considered. Exceptions: people who have an extension. CourseNana.COM

Start early! Lots of students will be submitting their work closer to the deadline so it may take 30 min before your program will be executed and you will see the results. CourseNana.COM

Your output should exactly match the one in the system for the submission to be correct. So be careful with the printing. No extra symbols! It may look the same on the first glance but may have a different end of line character or extra space. CourseNana.COM

Please test at the command-line like the following. CourseNana.COM

python3 task1.py < canvas.in > myout1.txt diff myout1.txt canvas.out1 CourseNana.COM

If you are on a Windows platform you may need to download diff.exe or use alternatives fc or comp. CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
COMPSCI 220代写,CS220代写,Algorithms and Data Structures代写,Assignment代写,Python代写,Auckland代写,澳洲代写,COMPSCI 220代编,CS220代编,Algorithms and Data Structures代编,Assignment代编,Python代编,Auckland代编,澳洲代编,COMPSCI 220代考,CS220代考,Algorithms and Data Structures代考,Assignment代考,Python代考,Auckland代考,澳洲代考,COMPSCI 220help,CS220help,Algorithms and Data Structureshelp,Assignmenthelp,Pythonhelp,Aucklandhelp,澳洲help,COMPSCI 220作业代写,CS220作业代写,Algorithms and Data Structures作业代写,Assignment作业代写,Python作业代写,Auckland作业代写,澳洲作业代写,COMPSCI 220编程代写,CS220编程代写,Algorithms and Data Structures编程代写,Assignment编程代写,Python编程代写,Auckland编程代写,澳洲编程代写,COMPSCI 220programming help,CS220programming help,Algorithms and Data Structuresprogramming help,Assignmentprogramming help,Pythonprogramming help,Aucklandprogramming help,澳洲programming help,COMPSCI 220assignment help,CS220assignment help,Algorithms and Data Structuresassignment help,Assignmentassignment help,Pythonassignment help,Aucklandassignment help,澳洲assignment help,COMPSCI 220solution,CS220solution,Algorithms and Data Structuressolution,Assignmentsolution,Pythonsolution,Aucklandsolution,澳洲solution,