Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

benjaminf Group Title

Ex1.3 in SICP: We're supposed to define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. How do you treat the case {0,0,1}? In that case there _aren't_ two larger numbers. If you tried this question did you have to make (unjustified?) assumptions? Thanks.

  • one year ago
  • one year ago

  • This Question is Closed
  1. azka.niazi Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    If your algorithm works perfectly for all inputs, then giving 0,0 and 1 as arguments must give you the answer: \[0^{2}+1^{1}\] There could be another way to debate about the correctness of the answers. Logically speaking, the two numbers which the program picks as the greater two should, at least, not be less than the third number (whose square hasn't been included in answer). Because when it comes to equality, whatever you pick, it doesn't really matter. That should be natural assumption I believe. Although mathematically speaking, if a number x is not greater than y, then it can be either equal to y or less than it. So, the equality x=y is included in negation of x>y. But in the end, i would close my answer on a pretty satisfying statement: Our program has to give us an answer. It has to use the highest two values it has to give an answer i.e. do the best with whatever it has got. So what are its highest two numbers, the sum of the squares of those two will be our answer. No real need to make an additional assumption. Hope that answers your question!

    • one year ago
  2. azka.niazi Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    sorry, thats \[0^{2}+1^{2}\]

    • one year ago
  3. benjaminf Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Okay, you're right. But just to be annoying about it...what if the purpose of this excise was to start building a program that would help you choose the shortest traveling distance between two islands (via other islands.) Then it's not just a matter of what the sum-of-squares value is, but also how you got it, i.e. which numbers (directional parameters) you chose. At least, that what it seems like to me! but I'll be using your interpretation, so thank you.

    • one year ago
  4. azka.niazi Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Well, it is not annoying actually. Answering questions has its own pleasure. I must admit some confusion about this shortest distance thing you mentioned. Not that I don't understand the problem, but because the nature of the problem seems very different to me. Ex 1.3 is a far simpler problem (it is chapter 1 after all!). Other than that shortest distance problem is quantified in terms of numerical values which is the sum of all the distances it has to cover over a path. The least sum out of all possible paths will be the answer. I think you are worried about how to keep track of the path itself (which has the shortest distance). There are algorithms for that too - Google-ing might help. But more important are the Data Structures which are used to represent maps/graphs. Anyway, the book, in a later chapter, does talk about trees and graphs. p.s. you're welcome! :)

    • one year ago
  5. benjaminf Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I thought the distance example would be handy to show that (0,0,1) and (0,1,0) are different, maybe not when you're calculating the sum of squares, but definitely when you have to make a choice between them. But that, like you said, is a different kind of problem. Instead, the exercise just asks for the sum of squares of the two larger numbers. You rightly point out that it doesn't matter which {0} I pick, the answer is the same, and I went with that for my solution. But I think it's also valid to say that in a case where there _aren't_ two larger numbers it's _not possible_ to return the sum-of-squares for two larger numbers and returning some version NOT DEFINED might also be okay.

    • one year ago
  6. azka.niazi Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    yes you're absolutely right. i have no reason to disagree.

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.