TheAlgorithms / MATLAB-Octave

This repository contains algorithms written in MATLAB/Octave. Developing algorithms in the MATLAB environment empowers you to explore and refine ideas, and enables you test and verify your algorithm.
MIT License
364 stars 173 forks source link

Add more algorithms! #9

Open cozek opened 4 years ago

cozek commented 4 years ago

EDIT 6/10/20: If you are making a PR for hacktoberfest, please say so in your PR description so that I can add the hacktoberfest-accepted label.

This repo needs more algorithms. If you see any missing algorithms, kindly contribute. Hackotberfest participants are welcome! I will list some of the algorithms that are up for grabs. However, please check if the algorithm is already in our repo before you begin working. Feel free to help me add more items to the list. If you have any questions, ask away!

Some Guidelines:

  1. Please create 1 pull request per algorithm for ease of review.
  2. Please do not plagiarise. Implementations must be your own. If you have used help from some article (say Wikipedia), give credit in your script in a comment.
  3. Give a brief explanation/links of what your script does.
  4. Give helpful comments where you deem necessary. Don't add comments where it's trivial such as x = y + z % adds two numbers or is unnecessary.
  5. Use proper variable names and filename. If you are working on prime check, please use a proper file name such as prime_check.m rather than primec.m
  6. Incase your algorithm required multiple files, create a subdirectory, for example, the kmeans algorithm requires two files, so we have a subdirectory for it. Try not to add unnecessary files.
  7. This repo is for educational purposes. Please keep that in mind when you are working on a contribution to this repo.
  8. Following this coding style guideline is recommended for all PRs.

Sorting Algorithms:

Searching Algorithms:

Math:

Machine Learning: NOTE: Please try to use standard datasets for these problems that are freely available and perhaps popular, such as the iris dataset. Or datasets that are already inbuilt in Matlab/Octave.

MaSi-dev commented 4 years ago

Dear @cozek , I've sent PR for adding Fibonacci series to Math. please feel free to comment or ask for any changes.

MaSi-dev commented 4 years ago

I've also sent PR for adding algorithm of factorial to Math.

cozek commented 4 years ago

I've also sent PR for adding algorithm of factorial to Math.

I have merged your PR. Thank you for your contribution!

MaSi-dev commented 4 years ago

Thanks for your kind response. You should actually notice that you mustn't change the file name from factor.m to factorial.m, because Matlab already has a function with the same name and our factorial function will be unusable!

cozek commented 4 years ago

Thanks for your kind response. You should actually notice that you mustn't change the file name from factor.m to factorial.m, because Matlab already has a function with the same name and our factorial function will be unusable!

Seems like I did an oopsie. Hahaha. No matter, the name change is just for indexing purpose. I am sure our readers will notice the problem and change the file/function names accordingly. Or perhaps, we should leave a comment in the script making our readers aware.

EDIT: i changed it to find_factorial. I think that solves the issue.

cozek commented 4 years ago

@atousa1 @MaSi-dev I have added more problems to the math section, have a look! :)

MatteoRaso commented 4 years ago

I made a PR for an insertion sorting algorithm.

cozek commented 4 years ago

Hi, I will review it soon. Thanks!

On Sun, 2 Feb 2020 at 13:18, MatteoRaso notifications@github.com wrote:

I made a PR for an insertion sorting algorithm.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TheAlgorithms/MATLAB-Octave/issues/9?email_source=notifications&email_token=ACXBUNMJPJM2CTOUIMJ2S3LRAZ3GHA5CNFSM4I7HDDMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKRQEMY#issuecomment-581108275, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACXBUNPLAAMW4GTWPNV4CL3RAZ3GHANCNFSM4I7HDDMA .

navkiran commented 4 years ago

I made a PR for two image processing algorithms. Please review. I missed the guideline of 1 PR per algorithm, I'll keep it in mind for the future.

harshitpant1 commented 3 years ago

Hi all, I want to contribute the jump search algorithm:

function found_at = jump_search(arr, value)
  % Contributed by   - Harshit Pant, harshitpant83@gmail.com

  % arr       - The input array, should be sorted in ascending order.
  %             'arr' can contain -ve numbers as well as non-integers.
  % value     - The value to be searched in the array.
  % found_at  - The index at which 'value' is found in 'arr'.
  %             -1 is returned if 'value' is not found in 'arr'.

  n = length(arr);

  % 'm' holds the block size
  m = sqrt(n); 
  m = round(m); 
  low = 1;
  high = 1 + m;

  found_at = -1; 

  while arr(min(high, n)) < value
      low = high;
      high = high + m;
      if low >= n
          return;
      endif;
  endwhile;

  while arr(low) < value
      low = low + 1;
      if low > min(high, n)
          return;
      endif;
  endwhile;

  if arr(low) == value
      found_at = low;
  endif;

endfunction;

% TEST: 
% Save this file to your local computer, then use the command:
% jump_search([-11.1, -3.3, -1.3, 0.1, 1.5, 3.5, 3.9, 5.5, 7.5, 9.6, 13.7, 21.3, 35.9], 7.5)
% This should return, ans = 9.
% TODO - Transfer this test when automated testing functionality is added to this repository.

Is anyone available to review? I'd like to send a PR. Thankyou. (/cc @cozek, @Panquesito7 @ayaankhan98)

ayaankhan98 commented 3 years ago

Hi all, I want to contribute the jump search algorithm:

function found_at = jump_search(arr, value)
  % Contributed by   - Harshit Pant, harshitpant83@gmail.com

  % arr       - The input array, should be sorted in ascending order.
  %             'arr' can contain -ve numbers as well as non-integers.
  % value     - The value to be searched in the array.
  % found_at  - The index at which 'value' is found in 'arr'.
  %             -1 is returned if 'value' is not found in 'arr'.

  n = length(arr);

  % 'm' holds the block size
  m = sqrt(n); 
  m = round(m); 
  low = 1;
  high = 1 + m;

  found_at = -1; 

  while arr(min(high, n)) < value
      low = high;
      high = high + m;
      if low >= n
          return;
      endif;
  endwhile;

  while arr(low) < value
      low = low + 1;
      if low > min(high, n)
          return;
      endif;
  endwhile;

  if arr(low) == value
      found_at = low;
  endif;

endfunction;

% TEST: 
% Save this file to your local computer, then use the command:
% jump_search([-11.1, -3.3, -1.3, 0.1, 1.5, 3.5, 3.9, 5.5, 7.5, 9.6, 13.7, 21.3, 35.9], 7.5)
% This should return, ans = 9.
% TODO - Transfer this test when automated testing functionality is added to this repository.

Is anyone available to review? I'd like to send a PR. Thankyou. (/cc @cozek, @Panquesito7 @ayaankhan98)

Make a proper PR, maintainers will review.

harshitpant1 commented 3 years ago

Ok, thanks.

AstroDude01 commented 2 years ago

I have created a PR. Would you please review and suggest if any changes are required Thank you