Binary Search Comparison Recurrence Relation: Solve and Prove Solution"

In summary, the recurrence relation gives you the 1st term in terms of the (i - 1)st term, but there is no way to calculate the C(2) term from the given information. You need to know C(7) to get to C(3).
  • #1
Gear2d
51
0

Homework Statement


Solve and prove your solution for the following recurrence relation for the number of comparisons in Binary Search:

C(21 - 1)=1
C(2i - 1) = 2 + C(2(i+1) - 1)

The Attempt at a Solution



The setup for this would be:

C(n)={ 1, n=1 and 2 + C(2(i+1) - 1), otherwise

From this I would do substitution and guessing, and then prove the guess with induction?
 
Physics news on Phys.org
  • #2
Are you sure you have your recurrence relation right? Usually the formula for the general term (the i-th term) is given in terms of the previous term, not the next term.
 
  • #3
I am assuming that is what the teacher wants. Could this be it:

C(n)={ 1, n=1 and C(n/2) + 2, otherwise
 
  • #4
Gear2d said:
I am assuming that is what the teacher wants. Could this be it:

C(n)={ 1, n=1 and C(n/2) + 2, otherwise

My question is not about what the teacher wants, but instead is about what exactly are you given to work with.

Clearly C(1) = 1 from the given information.
What is C(2) though? There is no way to calculate this according to the recurrence relation you show.
What about C(3)? To get this, you need to know C(7).

A recurrence relation usually gives a formula for the i-th term in the sequence in terms of the (i - 1)st term, and gives you the 1st term. From the recurrence formula you can work through and get C(2), C(3), C(4), and so on.

When I said this earlier, you came up with what looks like a different recurrent formula. At this point I'm less interested in what your teach wants than in what you're given to work with.
 
  • #5
Could take the log of the inside to get the i th term?

2i-1 - 1 = k (some constant)

Take lg of each side
2i-1 = k +1
i-1 = lg(k+1)

i = lg(k+1) + 1
 
  • #6
Gear2d said:
Could take the log of the inside to get the i th term?

2i-1 - 1 = k (some constant)

Take lg of each side
2i-1 = k +1
i-1 = lg(k+1)

i = lg(k+1) + 1

No. You have to take the log of each side of an equation, not just parts of it.

If you want me to answer any more questions, please answer the ones I have asked.
 

1. What is a recurrence relation?

A recurrence relation is a mathematical equation that describes a sequence of numbers or functions by relating each term to one or more previous terms.

2. How do you solve a recurrence relation?

There are multiple methods for solving a recurrence relation, including substitution, iteration, and the master theorem. The appropriate method depends on the specific form of the recurrence relation.

3. What is the purpose of a recurrence relation in mathematics?

Recurrence relations are commonly used in mathematics to model and describe real-life situations, such as population growth, compound interest, and algorithms. They also allow for the prediction and analysis of future terms in a sequence.

4. Can a recurrence relation have multiple solutions?

Yes, a recurrence relation can have multiple solutions. This occurs when the relation is not uniquely defined, or when there are multiple possible solutions that satisfy the given conditions.

5. What are some applications of recurrence relations in computer science?

Recurrence relations are widely used in computer science, particularly in the analysis of algorithms. They can help determine the time and space complexity of a given algorithm, as well as predict its performance for different input sizes.

Similar threads

  • Calculus and Beyond Homework Help
Replies
11
Views
1K
  • Calculus and Beyond Homework Help
Replies
7
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
506
  • Calculus and Beyond Homework Help
Replies
1
Views
501
  • Calculus and Beyond Homework Help
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
484
  • Calculus and Beyond Homework Help
Replies
3
Views
801
  • Calculus and Beyond Homework Help
Replies
1
Views
569
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
Replies
1
Views
1K
Back
Top