Top Banner
Assignment 10 Sample problems
23

Assignment 10 Sample problems

Feb 23, 2016

Download

Documents

isaura

Assignment 10 Sample problems. Generalized Manhattan. Consider a generalized form of Manhattan where n streets and n avenues form a square grid graph. That is, every block is a perfect square with the same area. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Assignment 10  Sample problems

Assignment 10 Sample problems

Page 2: Assignment 10  Sample problems

Generalized Manhattan

Page 3: Assignment 10  Sample problems

• Consider a generalized form of Manhattan where n streets and n avenues form a square grid graph. That is, every block is a perfect square with the same area.

For each of the following walking paths, choose the corresponding distanced walked in big O notation. (The length of one block is one unit.)

Page 4: Assignment 10  Sample problems

Start in the southwest corner. Walk north four blocks, east two blocks, south two blocks, west one block.

Page 5: Assignment 10  Sample problems

Start in the southwest corner. Walk north four blocks, east two blocks, south two blocks, west one block.

The answer is O(1)

Page 6: Assignment 10  Sample problems

How can we get ?

4+2+2+1=9=O(1)

Page 7: Assignment 10  Sample problems

Start in the southwest corner. Walk diagonally to the northeast corner.

Page 8: Assignment 10  Sample problems

Start in the southwest corner. Walk diagonally to the northeast corner.

The answer is O(n)

Page 9: Assignment 10  Sample problems

How can we get ?

n+n=2n=O(n)

Page 10: Assignment 10  Sample problems

Start in the southwest corner. Repeat walk up to the north (n-1) street, then turn right to walk east one block, down to the southern-most street and left one block. Stop when the most right southeast avenue is reached.

Page 11: Assignment 10  Sample problems

Start in the southwest corner. Repeat walk up to the north (n-1) street, then turn right to walk east one block, down to the southern-most street and left one block. Stop when the most right southeast avenue is reached.

The answer is O(n²)

Page 12: Assignment 10  Sample problems

How can we get ?

n*(n-1)+n=n²=O(n²)

Page 13: Assignment 10  Sample problems

Average Waiting Time

Page 14: Assignment 10  Sample problems

Consider the word “blueberry". Suppose we repeatedly pick a single letter at random from anywhere in the word. (Please enter any fractional answers in their decimal form.)

1) How many times, on average, do we pick before we get the letter “b"?

2) How many times, on average, do we pick before we get the letter “u"?

3) How many times, on average, do we pick before we get one of the letters in the word “beer"?

Page 15: Assignment 10  Sample problems

Consider the word “blueberry". Suppose we repeatedly pick a single letter at random from anywhere in the word. (Please enter any fractional answers in their decimal form.)

1) How many times, on average, do we pick before we get the letter “b"? The answer is 4.5

2) How many times, on average, do we pick before we get the letter “u"? The answer is 9

3) How many times, on average, do we pick before we get one of the letters in the word “beer"? The answer is 1.5

Page 16: Assignment 10  Sample problems

How can we get ?

1: p=2/9, so the answer is 1/p=4.5

2: p=1/9, so the answer is 1/p=9

3: p=2/9+2/9+2/9=6/9, so the answer is 1/p=9/6=1.5

Page 17: Assignment 10  Sample problems

Number of Bisections

Page 18: Assignment 10  Sample problems

Suppose you have a bag of 512 chocolates. You decide to give them to your friends by dividing the chocolates into half. For example, you give half of these chocolates to your best friend, then give another half of leftover chocolates to your another friend. Each time, you just give half of the leftover chocolates to one of your friend. How many times total can you divide like this before you only have one chocolate left?

Page 19: Assignment 10  Sample problems

Suppose you have a bag of 512 chocolates. You decide to give them to your friends by dividing the chocolates into half. For example, you give half of these chocolates to your best friend, then give another half of leftover chocolates to your another friend. Each time, you just give half of the leftover chocolates to one of your friend. How many times total can you divide like this before you only have one chocolate left?

The answer is 9

2.^9=512

Page 20: Assignment 10  Sample problems

Find the Biggest Element

Page 21: Assignment 10  Sample problems

1) What is the minimum number of operations to find the biggest element in an unsorted list of size n?

2) What is the minimum number of operations required to find the biggest element of a sorted (ascending) list of length n?

Page 22: Assignment 10  Sample problems

1) What is the minimum number of operations to find the biggest element in an unsorted list of size n? The answer is n-1

2) What is the minimum number of operations required to find the biggest element of a sorted (ascending) list of length n?The answer is 0

Page 23: Assignment 10  Sample problems

How can we get ?

1:for unsorted list, you need compare n-1 times to find the maximum number

2: for sorted list, you do not need compare them again, you can directly get the maximum number from the end of the sorted list