CS 211 Assignment 4

CS 211 Assignment 4 - CS 211 Assignment 4 Fall 2007 Due...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 211 Assignment 4, Fall 2007 Due October 25, 2007 11:59:59 PM 1 Big-O Running Time Ordering Arrange the following functions in increasing order of growth rate (where n is the input size): n 2 , 2 n , n log n, 100000000, 5000 log n, n log log n, n!, n log n , n n . 2 Big-O Running Time Determine the running time for the following pieces of code. No explanation is needed. (i) for(int i=0; i<n; i++) total++; (ii) for(int i=0; i<n; i++) { for(int j=0; j<n; j++) total++; } for(int k=0; i<100000000000*n; i++) total++; (iii) for(int i=0; i<n; i++) { for(int j=0; j<n/2; j++) { n = j%n; } n = i%(n+1); } (iv) Assume g(n) is a function that takes O(n) for(int i=0; i< n; i++) for(int j=0; j<i; j++) for(int k=0; k<j; k++) g(n); (v) Assume p>=0 for(int i=0; i < n; i++) { while(i>p) i++; n++; } 3 Nearest Neighbor Problem 3.1 Introduction
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
how to use interfaces. To get a better understanding of why tree is a useful data structure, you will implement an Nearest Neighbor algorithm (locating the nearest point to a given point) in two ways: a linked list and a 2D tree. 3.2 2D Trees Two-dimensional trees are dynamic, adaptable data structures which are very similar to binary trees but divide up a geometric space in a manner convenient for use in range searching and other problems. The idea is to build binary search trees with points in the nodes, using the x or y coordinate of the points as keys in an alternating sequence. The algorithm used for inserting points into 2D trees is the same as for normal binary search trees with a small modification: Suppose we want to insert a point p with coordinates ( x; y ) into a 2D tree with root node r . 1. At the root, if p has a smaller y coordinate than the point at the root, recrusively call insert method with p on r ’s left subtree (if one doesn’t exist, set r ’s left child to be p ); else recursively call insert method with p on r ’s right subtree (again, if it doesn’t exist, set p to be r ’s right child). 2. At each level alternate which coordinate is used for checking which subtree to go to: if in the previous level of the tree we used the y coordinate as the key, then in this level use the x coordinate, and in the next level use the y coordinate again, etc.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 6

CS 211 Assignment 4 - CS 211 Assignment 4 Fall 2007 Due...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online