Every genuine coin weighs 10 grams every fake weighs

  • No School
  • AA 1
  • 32

This preview shows page 26 - 32 out of 32 pages.

Every genuine coin weighs 10 grams; every fake weighs 11 grams. You have an analytical scale that can determine the exact weight of any number of coins.
Image of page 26
Fake Coins Devise a brute force algorithm to identify the stack with the fake coins and determine its worst- case efficiency class. Devise a clever algorithm with the minimum number of weighings needed to identify the stack with the fake coins? Magic with numbers ……
Image of page 27
Fake Coins A = 10n(n+1)/2 = 5n(n+1) B = Weight of all the coins from 1 to n stack, taking 1 coin from stack 1 and 2 coins from stack 2 and so on, taking n coins from stack n B – A will yield the number of stack with fake coins
Image of page 28
Design Problem Suppose you have an array of n distinct elements. Write an algorithm that picks ith array element and place it at the position such that all array elements present at left are less than it and all array elements present at right are greater than it. Also gives the time complexity of your algorithm in notation.
Image of page 29
Design Problem A man put a pair of rabbits in a place surrounded by a wall. How many pairs of rabbits will be there in a year if the initial pair of rabbits (male and female) are newborn and all rabbit pairs are not fertile during their first month of life but thereafter give birth to one new male/female pair at the end of every month? 30
Image of page 30
Computing the nth Fibonacci Number F(n) = F(n − 1) + F(n − 2) for n > 1 F(0) = 0, F(1) = 1. Exponentiation problem: compute a n for nonzero number a and nonnegative integer n . By the definition of exponentiation 31
Image of page 31
Not a source of clever and efficient algorithm But….. the brute-force approach should not be overlooked as an important algorithm design strategy applicable to a very wide variety of problems 32
Image of page 32

You've reached the end of your free preview.

Want to read all 32 pages?

  • Fall '19

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

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