Understanding Recursive Methods and Sorting Algorithms

  • Thread starter courtrigrad
  • Start date
In summary, the conversation discusses the difference between various sorting and searching methods, and the use of recursion in programming. While there is no easy way to determine the number of calls needed for a recursive method without tracing it, insertion sort is a simple sorting method that does not use recursion.
  • #1
courtrigrad
1,236
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
  • #2
any ideas?

thanks
 
  • #3
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:
 

1. What is a recursive method?

A recursive method is a function that calls itself to solve a smaller version of the same problem, until it reaches a base case that can be solved directly.

2. How do recursive methods work?

Recursive methods work by breaking down a complex problem into smaller, simpler versions of the same problem. These smaller versions are solved using the same method until a base case is reached, at which point the solutions are combined to solve the original problem.

3. What is the purpose of using recursive methods?

The main purpose of using recursive methods is to solve problems that can be divided into smaller subproblems. They also allow for elegant and concise code, as well as efficient solutions to certain types of problems.

4. What is the difference between iterative and recursive methods?

Iterative methods use loops to repeat a set of instructions until a certain condition is met, while recursive methods call themselves to solve smaller versions of the same problem. Additionally, recursive methods are usually more concise but may require more memory and time compared to iterative methods.

5. What are sorting algorithms and why are they important?

Sorting algorithms are a set of steps used to arrange a collection of data in a specific order. They are important because they allow for efficient searching and organizing of data, which is a crucial aspect of data processing in various fields such as computer science, statistics, and data analysis.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
18
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
942
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Programming and Computer Science
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
Replies
9
Views
1K
  • Programming and Computer Science
Replies
3
Views
3K
  • Introductory Physics Homework Help
Replies
8
Views
2K
Back
Top