Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

As started here with the Tower of Hanoi, this thread will be for lower bounds proofs. Lower bounds are used to tell how difficult a problem is. The solution to the TOH was in the form of 2^n meaning that no matter what you do, you can't solve it faster than 2^n steps. If, for example, you could solve it in n steps, we would say this is a much easier problem.

So the question is where to go from here. Most lower bounds proofs have to do with things in computer science: insert, sort, search, etc on different data structures. For example, proving that (with a few basic and almost trivial assumptions) you can't sort any faster than n*log(n).

So the question is do you want to look at computer science related questions, or should we keep this more general? In the mean time, here is a problem to keep you busy while we decide.

You have a robot in an infinitely long hallway and your task is to find a door in the wall. You may walk how ever far you wish to your left or right, and turn around whenever you please. Each time you take a step, you check to see if the door is in your new location. The door is an unknown (but finite) number of steps away. What is the minimum number of steps you must take? That is, using the best algorithm, what is the most number of steps you will ever possibly have to take?

a. You know the door is to your left.

b. You don't know what direction the door is, but you do know it is n steps away.

c. You don't know where the door is, but it is within n steps away.

d. You neither know where the door is, nor how far away it is.

"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..."

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

cool stuff, ricky.

For anyone who does this, please use the hide tag as not to spoil it for others.

A logarithm is just a misspelled algorithm.

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

Okay, here is

and

still thinking on c and d.

again i don't know much about how non mathematical proofs are done so i apologize for any noobishness. If i'm making some assumptions on a and b, please tell me and give me a hint or two, ricky. Hopefully it will help me get the hang of these.

*Last edited by mikau (2007-07-12 17:32:45)*

A logarithm is just a misspelled algorithm.

Offline

**mathsyperson****Moderator**- Registered: 2005-06-22
- Posts: 4,900

Ricky wrote:

The solution to the TOH was in the form of 2^n meaning that no matter what you do, you can't solve it faster than 2^n steps.

I can do it in (2^n)-1.

For the robot-door problem, do the steps have to be one wide? For example, if you make the robot walk a distance of 2 but don't care about whether or not there is a door at the intermediate position, then would that count as one step or 2 steps?

Also, does the robot need to be next to the door to finish or is it enough for you to just know where the door is?

Why did the vector cross the road?

It wanted to be normal.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

You know the door is a finite distance away, so it might make sense to let the door be d steps away, then express your answer in terms of d. So far you're 1/2 mikau. I would have said 2/2, but in light of mathsyperson's question below, b is wrong.

I can do it in (2^n)-1.

I was writing in big-theta notation...

For the robot-door problem, do the steps have to be one wide? For example, if you make the robot walk a distance of 2 but don't care about whether or not there is a door at the intermediate position, then would that count as one step or 2 steps?

Nope, every step you take is one step, and on that step you always check.

Also, does the robot need to be next to the door to finish or is it enough for you to just know where the door is?

Wow! I'll accept knowing where the door is. Never thought of that one, great job. Of course, you can only use it on one of them.

"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..."

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

are you saying b is wrong because we now want how many steps to find the door instead of how many to reach the door?

*Last edited by mikau (2007-07-13 06:57:29)*

A logarithm is just a misspelled algorithm.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

No answers to (c) or (d)?

"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..."

Offline

**mathsyperson****Moderator**- Registered: 2005-06-22
- Posts: 4,900

Why did the vector cross the road?

It wanted to be normal.

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

I was away all weekend, and haven't had much time to think on this one.

is this right, ricky?

edit:

I'll work on C tommorow.

*Last edited by mikau (2007-07-15 14:10:57)*

A logarithm is just a misspelled algorithm.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

Thanks, Ricky!

*Last edited by mikau (2007-07-16 14:51:23)*

A logarithm is just a misspelled algorithm.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

The previous problem asked you to do a worst-case analysis of an algorithm for a problem. In this, you are simply looking at what the worst possible situation for your algorithm is and how much it "costs". It is very useful because as it is the worst case, any time you are asked to solve the problem, it must cost less than this.

However, there are other types of analysis. Best case cost is what it will cost in the best case for a given problem. This isn't quite as useful, but it can be used to compare two different algorithm. Again, remember that best case cost is algorithm specific. What is best for one algorithm need not be best for another.

Then of course, there is the average case cost. Typically, the average is hard to compute, even for simple problems, until you get used to summation notation and evaluation. Like worst-case cost, it can be extremely useful in determining if one algorithm is "better" than another.

Do the robot problem above, but instead, for best cost with the algorithm you've used. Then do average cost for parts (a), (b), and (c). You can try (d) if you wish, but I'm fairly certain it won't be easy. When doing this, can you think of a better algorithm in each part? Note by better, I'm referring to in the best and then average case only.

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

x_x NOOOO!!! (dies)

A logarithm is just a misspelled algorithm.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Too much? Want to move on to a different problem and away from robots? Just say the word.

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

Mmmm... I would like to see something different now actually. I'll think about those later I guess. The reason they frighten me is they obviously involve probability and permutations. Things I haven't done since precalc and i don't know much beyond what you'd learn at that level.

*Last edited by mikau (2007-07-17 17:20:59)*

A logarithm is just a misspelled algorithm.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Not exactly. Assume the door occurs in position n. f(n) is the cost of finding the door there. Then the average cost is:

But I'll post another problem dealing with this in the morning. Computer science related questions are ok, I take it?

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

certainly!

A logarithm is just a misspelled algorithm.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Here is some code for bubble sort:

```
swapMade = true
While swapMade is true
swapMade = false
for j = 0 to j = list.size-1
if list[j] < list[j+1] //This is the only list comparison
swap list[j] with list[j+1] //This is the only swap made on the list
swapMade = true
endif
endfor
endwhile
```

Find out what the best and worst case are for this sort, and find the cost in number of comparisons between list elements. I'll be attempting to work out the average case, so feel free to do that as well if you want to give it a shot.

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

the old bubble sort, eh?

Well i'll work on it when i get some time. I've been teaching myself linnear algebra and C++ over the summer and its consuming a lot of my freetime. I'll tackle this next chance I get.

Question, i'm not sure what language you are using. Do I need to consider that a for loop makes a comparison for the entry condition on every itteration of the loop?

A logarithm is just a misspelled algorithm.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Nope, it's only comparisons between list elements. Note my comment on line 4.

Offline

**John E. Franklin****Member**- Registered: 2005-08-29
- Posts: 3,552

**Read Me--Editted also**

Just one more thing Ricky...

Subtract one more at the end of the inner loop so when the comparison is made on the last two elements, you don't overstep the array boundary.

Isn't it neat the way items get moved along and dropped when a more significant value is found and then that is moved along and dropped off?? Pretty cool and easy to write.

*Last edited by John E. Franklin (2007-07-21 03:16:30)*

**igloo** **myrtilles** **fourmis**

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Actually, best to take out the outer loop and change it to a while. Changes made.

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

hey, Ricky! I finally got a chance to work on this. here are my solutions

A logarithm is just a misspelled algorithm.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Your worst case is right, but what happened with your best case? You talk about swapping, but I need a number of comparisons.

Offline