Copy of Homework-Set-02-Solutions.pdf - ICS 311 Spring 2019 Problem Set 02 ​3 4 Solutions(27 pts Copyright(c 2016-18 Daniel D Suthers Nodari

# Copy of Homework-Set-02-Solutions.pdf - ICS 311 Spring 2019...

• Homework Help
• 4
• 100% (1) 1 out of 1 people found this document helpful

This preview shows page 1 - 3 out of 4 pages.

ICS 311, Spring 2019, Problem Set 02, 3 & 4 Solutions (27 pts) Copyright (c) 2016-18 Daniel D. Suthers, Nodari Sitchinava and J. Stelovsky. All rights reserved. These solution notes may only be used ONLY by students in ICS 311 Spring 2019 at the University of Hawaii. #1. Proofs of Asymptotic Bounds ( 6 points) Continuing in the style of our in-class exercise, fill in the table for these pairs of functions with "Yes" or "No" in each empty box. Then, for each row, justify your choice, preferably by showing mathematical relationships (e.g., transforming one expression into another, or into expressions that are more easily compared). Asymptotic Relations f(n) g(n) O? o? Ω? ω? Θ? a. 4 n 2 4 lg n Y N Y N Y b. 2 lg n lg 2 n N N Y Y N c. n n sin n N N N N N (a) Justify row a.: or = Θ(n 2 ) 4 lgn = (2 ) * 2 lgn = 2 lgn * 2 lgn = n * n = n 2 4 lgn = 2 2 lgn = (2 ) lgn 2 = n 2 and 4 n 2 = Θ(n 2 ) Since f(n) = Θ(g(n)), it follows that f(n) will also be in O and Ω. (b) Justify row b.: = n and any polynomial grows larger than any poly-logarithmic. 2 lgn See also Class Problems for Topic 3 Asymptotic Analysis problem 2. (c) Justify row c.: As sin n oscillates between -1 and 1, n sin n oscillates between 1/ n and n while for n > 1, is n always greater than 1/ n and less than n : thus they cannot be compared.
#2. Tree Traversals ( 8 points-- 5 for code in (a), 3 for explanation in (b)) In class you wrote a recursive procedure for traversal of a binary tree in O(n) time, printing out the keys of the nodes. Here you write two other tree traversal procedures. The first is a variation of what you wrote in class; the second is on a different kind of tree that you read about pages 248-249 and in my lecture notes and screencast. (a) Write an O( n )-time non-recursive procedure that, given an n -node binary tree, prints out the key of each node of the tree in preorder . Assume that trees consist of vertices of class TreeNode with instance variables parent , left , right , and key . Your procedure takes a TreeNode

#### You've reached the end of your free preview.

Want to read all 4 pages?

• Fall '08
• Barjaktarovic,M

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes