Understanding Recursive Methods and Sorting Algorithms

  • Thread starter Thread starter courtrigrad
  • Start date Start date
AI Thread Summary
The discussion focuses on the differences between various sorting algorithms, including merge sort, selection sort, binary search, linear search, and insertion sort. It highlights that insertion sort operates without recursion, relying on iterative searching to organize data. The thread also addresses the challenge of determining the number of calls made by a recursive method without tracing, noting that each recursive case can vary significantly. The formula 2^k - 1 is mentioned as a potential tool for understanding recursive calls, although its applicability is questioned. Overall, the complexities of recursion and sorting methods are emphasized as key points of concern.
courtrigrad
Messages
1,236
Reaction score
2
Hello all

What is the difference between merge sort, selection sert,binary search , linear search and insertion sort? Also if you are given a recursive method, is there an easy way without tracing the method to find how many calls you need to make? For example:

Code:
public int A(int a, int b )
{
   if ( a< 0 )
           return (b);
   else if  (b < 1)
          return (a);
   else
           return(A(a-2, b-4) + A(a-1, b-2));
}

I know that you work from the left to the right. Could you somehow use the formula 2^{k} - 1?

Thanks a lot guys :smile:
 
Physics news on Phys.org
any ideas?

thanks
 
courtrigrad said:
Hello all

What is the difference between merge sort, selection sert,binary search , linear search and insertion sort? Also if you are given a recursive method, is there an easy way without tracing the method to find how many calls you need to make? For example:

Code:
public int A(int a, int b )
{
   if ( a< 0 )
           return (b);
   else if  (b < 1)
          return (a);
   else
           return(A(a-2, b-4) + A(a-1, b-2));
}

I know that you work from the left to the right. Could you somehow use the formula 2^{k} - 1?

Thanks a lot guys :smile:
I personally HATE recursion of all types, mainly because it is so hard to implement and to trace. I don't think there is an easier way to find out how many calls it needs to make other than tracing the program. Since each case is different, the function will have to call itself different numbers of times. All of the sorting methods I know are bubble sort, insertion sort and quick sort. Insertion sort doesn't use recursion. It simply consists of searching through the list (could be an array, for example) for the smallest number (using for loops and if statements) and copying that number in a new array. You do this until the new array contains the numbers in order. Then, you copy the values from the nuw array to the original array. Hope this helps... :smile:
 
Kindly see the attached pdf. My attempt to solve it, is in it. I'm wondering if my solution is right. My idea is this: At any point of time, the ball may be assumed to be at an incline which is at an angle of θ(kindly see both the pics in the pdf file). The value of θ will continuously change and so will the value of friction. I'm not able to figure out, why my solution is wrong, if it is wrong .
TL;DR Summary: I came across this question from a Sri Lankan A-level textbook. Question - An ice cube with a length of 10 cm is immersed in water at 0 °C. An observer observes the ice cube from the water, and it seems to be 7.75 cm long. If the refractive index of water is 4/3, find the height of the ice cube immersed in the water. I could not understand how the apparent height of the ice cube in the water depends on the height of the ice cube immersed in the water. Does anyone have an...

Similar threads

Replies
5
Views
3K
Replies
6
Views
2K
Replies
3
Views
4K
Replies
4
Views
3K
Replies
17
Views
2K
Back
Top