1. Homepage
  2. Programming
  3. COMPSCI220 - CS220 Algorithms and Data Structures - Assignment 4: Arithmetic trees

COMPSCI220 - CS220 Algorithms and Data Structures - Assignment 4: Arithmetic trees

Engage in a Conversation
COMPSCI 220CS220Algorithms and Data StructuresAssignmentPythonAucklandAustralia

Computer Science 220, S1 2023 CourseNana.COM

Assignment 4 (traversal and optimisation) See Canvas for due dates CourseNana.COM

This assignment requires you to submit programs in Python that you have written yourself to the automarker, https://www.automarker.cs.auckland.ac.nz. Your implementation must be from first principles and cannot use an existing library methods that might solve the problem (eg performs graph operations etc). CourseNana.COM

The automarker runs on a Linux box. Read the automarker help and FAQ for more details. CourseNana.COM

Please submit only Python source code (.py extensions only). 1. Arithmetic trees 30 marks CourseNana.COM

You are given an input file with multiple pairs of input lines. The first line of each pair is a tree given as a predecessor array. The second line is the value at the corresponding node. Values at leaf nodes (nodes with no children) are integers. At non-leaf nodes, the two possible values are + or . CourseNana.COM

The tree represents an arithmetic expression where the value at a non-leaf node u is the sum of values at the children of u in the case of +, or the product of values at the children of u in the case of . CourseNana.COM

You need to calculate the value at each node and output the calculated value at the root. The tree is not constrained to be binary. CourseNana.COM

Input format: Input consists of m pairs of lines of comma separated values, so 2m lines in total. The first line is each pair is a comma separated list of integers representing a tree in predecessor array format where 1 represents null. CourseNana.COM

The second line in each pair is a comma separated list of integers and the symbols + and . The ith item on the list is the value or operator at the ith node in the tree. CourseNana.COM

For example: CourseNana.COM

     -1,0,0,0,1,1
     +,*,2,3,0,7
     2,0,-1,0
     +,3,*,3

Output format: For each pair of input lines, output a line containing the value calculated at the root of the tree. CourseNana.COM

For the example input above, output would be: CourseNana.COM

CourseNana.COM

2. Optimisation 30 Marks CourseNana.COM

A frog needs to navigate its way from its current position to its next meal through a dangerous landscape. To do so, it leaps from boulder to boulder, but it can jump at most 1m. Your aim is to find the length of the shortest path to get the frog to its next meal using only boulders. CourseNana.COM

The landscape is a n × n square (units are cm) with boulders at exact positions given by coordinates (x,y) where 0 x,y n. Boulders are scattered across the landscape. Use Euclidean distance to calculate the distance between boulders. CourseNana.COM

Input format: The input is taken from the keyboard (e.g. by sys.stdin) as multiple lines of comma separated integers. Each line has 2p + 1 numbers where p 2. The first number on each line is the size of the landscape, n. CourseNana.COM

The following 2p numbers give locations of p boulders, so the jth boulder is at (2j, 2j + 1). CourseNana.COM

The first position listed on each line is the frog’s current position, the final position listed is the target boulder where the frog will find its next meal. CourseNana.COM

For example: CourseNana.COM

  100,0,0,0,100,100,100
  1000,20.892,986,602,138.97,206.2,10.44
  200,25,25,10,1,50,25,140,30

Output format: For each line of input, output a single number to the console which is the length of the shortest path from the starting position to the next meal. Use str.format to give this value to 2 decimal places. Precisely, format x using CourseNana.COM

’{:.2f}’.format(x). Do not use any other rounding throughout your algorithm. If the next meal is unreachable from the origin, output -1. CourseNana.COM

For the example input above, output would be: CourseNana.COM

  200.00
  -1
  115.14

Marking CourseNana.COM

The maximum number of submissions for each problem is fixed at 12. Each problem has three test cases associated with it worth one third of the marks for that problem. Some of the test cases will be large to test for efficiency. You get full marks if you pass all test cases. CourseNana.COM

CourseNana.COM

Get in Touch with Our Experts

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