Python

Search for question

Questions & Answers

Question 2. (15 pts) What is the asymptotic complexity of the following functions?


Introduction Welcome to your first coding project! In each of these we will ask you to write short programs that will enhance your understanding of networking fundamentals and possibly assist you in your future work. For these assignments, we will be asking for both your source code and a short writeup that includes directions on how to run your code and screenshots of your code running. We may try to run your code on our own machines, and if it doesn't work there will be a point reduction, or we will ask you to fix it, or both. Part 1: Using a socket to GET a file Part 2: GET the data for a large file Part 3: The world's simplest HTTP server


Activity #1: Shoelace formula - team This activity will help you practice writing functions while solving for the area of a simple polygon. The shoelace formula (https://en.wikipedia.org/wiki/Shoelace formula) is an algorithm to calculate the area of a simple polygon given the vertices. Its name comes from repeatedly cross-multiplying the coordinates, like threading shoelaces. The math behind the method works by taking each edge of the polygon, forming a triangle with the origin, taking the cross-product (which gives the area of a parallelogram), then dividing by 2. The component areas will overlap, however the areas outside of the polygon will cancel out leaving only the area inside remaining. You can view a nice video explanation here: https://www.youtube.com/watch?v=0KjG8Pg6LGk Create a program named shoelace_formula.py that utilizes the shoelace formula via the following steps: 1. Create a function named getpoints that takes in as an argument a string and returns a list of points of arbitrary length. The string passed to the function contains pairs of numbers separated by commas, with each pair separated by a space, as shown in the format below. Have the function convert it to a list of points (the polygon's vertices). Each element in the list of points should itself be a list of one point. For the example shown below, your function should return: [[3, 4], [5, 6], [9, 51, [12, 8], [5, 11]] 2. Create a function named cross that takes in two arguments, both of which are a list of one point, and returns the cross-product. This is one step of the shoelace method. For example, if the points [1, 2] and [3, 4] are passed to the function, in that order, it will return -2. Cross product: (14) - (23) = -2 3. Create a function named shoelace that takes in as an argument a list of points and returns the area of the polygon calculated via the shoelace formula. The list of points passed to the function is the same list returned by your getpoints function. Your shoelace function should call your cross function. 4. Create a function named main that does not take in any arguments nor return any values. This function should take as input from the user a string of pairs of numbers separated by commas and spaces, as shown in the format below, and print the area of the polygon. Your main function should call your getpoints and shoelace functions. Format your output as shown below. 5. Finally, in your main code type the following: if__name__==main_ ==! main () You should NOT include any other executable lines in your main code.


1. You must turn in one Python file. • You must comment on key aspects of code (function definitions, explain your logic before conditionals, comment inner and outer loops). You should briefly explain your logic and what's happening where you're commenting. 2. You must turn in 1 stack trace for your program. o You will complete stack traces for each function for one unique set of test data. o Where something is randomly generated, pick something yourself that is within scope. (So if randomly generated between 1-25, you can just pick 8 for the stack trace, etc.) o These functions repeat until either the player or computer has won the game.


Write a program that will gather titles and authors of classic books from a user, and populate them into a dictionary. The title should be the key in the dictionary and the author is the value. The program should repeatedly prompt for as many times as the user wants to add titles/authors, until they type "stop". After the user types "stop", print the dictionary. Below is a sample output.


Use any data structures or control flows as appropriate to complete the following prompt where you manipulate 2D LISTS.


Assignment-2 (35pts) Implement the vector clock algorithm to enable causally-ordered events in the distributed system. Similar to the previous assignment, we use multiple processes to emulate multiple nodes. Assume that all nodes are initiated to the same vector clock. After completing a local operation, each process sends its updated vector clock to all other processes. Follow the steps on slide 34 in Lecture 6 to implement the vector clock algorithm.


Problem 7.1 Make a function with two input integer parameters. The function will compare the two parameters and return the number that is larger.


Assignment-3 (30pts) Implement a locking scheme to protect a share file in your distributed system. While we use processes on a single machine to emulate the distributed system and there are shared-memory synchronization primitives available, you are required to implement one of the following distributed locking schemes: decentralized, distributed locking or the token ring algorithm. When a process acquires the lock, it simply opens the file, increments a counter in the file, and closes the file. Assume that all processes keep requesting the lock until successfully acquiring the lock for a predefined number of times.


Phase 1 1. Develop an algorithm/program to construct a connected graph on v vertices and e edges, where v and e are parameters and execute your algorithm/program and depict the results. Program's input and output are as follows: Inputs: o v: number of vertices o e: number of edges Outputs: o Constructed graph (Show the constructed graph as an adjacency list in an appropriate manner) o Running time for the algorithm


No Question Found forPython

we will make sure available to you as soon as possible.