Understanding Recursive Methods and Sorting Algorithms

  • Thread starter Thread starter courtrigrad
  • Start date Start date
Click For Summary
SUMMARY

This discussion focuses on the differences between various sorting algorithms, including merge sort, selection sort, binary search, linear search, and insertion sort. It also addresses the challenges of understanding recursive methods, specifically a provided example of a recursive function in Java. The participants highlight that tracing the recursive calls is often necessary to determine the number of calls made, as there is no straightforward formula applicable in all cases. The conversation emphasizes the complexity of recursion and the need for a solid understanding of sorting techniques.

PREREQUISITES
  • Understanding of sorting algorithms such as merge sort and insertion sort
  • Familiarity with recursive programming concepts
  • Basic knowledge of Java programming language
  • Experience with algorithm analysis techniques
NEXT STEPS
  • Study the differences between merge sort and quick sort algorithms
  • Learn about the time complexity of recursive functions
  • Explore the implementation of binary search in Java
  • Investigate techniques for visualizing recursive calls in algorithms
USEFUL FOR

Software developers, computer science students, and anyone interested in mastering sorting algorithms and recursive programming techniques.

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 [tex]2^{k} - 1[/tex]?

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 [tex]2^{k} - 1[/tex]?

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:
 

Similar threads

  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 0 ·
Replies
0
Views
464
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K