Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add manacher's algorithm #1577

Merged
merged 6 commits into from
Aug 31, 2021
Merged

Conversation

riti2409
Copy link
Contributor

@riti2409 riti2409 commented Aug 29, 2021

Description of Change

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes: This is an implementation of the Manacher's Algorithm which is used to find the longest substring in linear time.

b30wulffz
b30wulffz previously approved these changes Aug 29, 2021
Copy link

@b30wulffz b30wulffz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

vid-7695
vid-7695 previously approved these changes Aug 29, 2021
assert(strings::manacher::manacher("abababc") == "ababa");
assert(strings::manacher::manacher("cbaabd") == "baab");
assert(strings::manacher::manacher("xacdedcax") == "xacdedcax");
assert(strings::manacher::manacher("xacddcax") == "xacddcax");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some test cases with Upper , Mixed, camel Case. Test Cases format seem to be repeativie.

strings/manacher_algorithm.cpp Show resolved Hide resolved
Copy link

@shikhar-psyduck shikhar-psyduck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Panquesito7 Panquesito7 added the enhancement New feature or request label Aug 30, 2021
Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, @riti2409! Thanks for reviewing, @b30wulffz, @vid-7695, and @shikhar-psyduck. 🙂
Also, please fix clang-tidy warnings.

@@ -0,0 +1,165 @@
/**
* @file
* @brief Implementation of the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @brief Implementation of the
* @brief Implementation of

Comment on lines 14 to 15
#include <cassert> // for asserting test cases
#include <iostream> // for IO operations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <cassert> // for asserting test cases
#include <iostream> // for IO operations
#include <cassert> /// for assert
#include <iostream> /// for IO operations

#include <cassert> // for asserting test cases
#include <iostream> // for IO operations
#ifdef _MSC_VER
#include <string> // required for MS Visual C++
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <string> // required for MS Visual C++
#include <string> /// required for MS Visual C++

#ifdef _MSC_VER
#include <string> // required for MS Visual C++
#else
#include <cstring>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a one-line description here as in line 17.

/**
* @brief A function that implements Manacher's algorithm
* @param prototype is the string where algorithm finds a palindromic substring.
* This string can contain any character except @ # &
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This string can contain any character except @ # &
* This string can contain any character except `@` `#` `&`

int main() {
test(); // run self-test implementations
return 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

@Panquesito7 Panquesito7 added requested changes changes have been requested automated tests are failing Do not merge until tests pass labels Aug 30, 2021
@riti2409 riti2409 dismissed stale reviews from shikhar-psyduck, vid-7695, and b30wulffz via 6da2c55 August 30, 2021 17:33
@riti2409 riti2409 requested a review from Panquesito7 August 30, 2021 17:34
@riti2409
Copy link
Contributor Author

@Panquesito7 I have incorporated all the suggestions. Please review.

Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! 😄


#include <cassert> /// for assert
#include <iostream> /// for IO operations
#include <vector> /// for vector STL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <vector> /// for vector STL
#include <vector> /// for std::vector STL

@riti2409
Copy link
Contributor Author

@Panquesito7 Done 😀

b30wulffz
b30wulffz previously approved these changes Aug 30, 2021
@Panquesito7 Panquesito7 removed the automated tests are failing Do not merge until tests pass label Aug 30, 2021
// stuffed string). This value will be lower bound of half
// length since single character is a palindrome in itself.

int bigger_center =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using uint64_t for non-negative values (or their appropriate size: uint32_t, uint16_t, uint8_t) or int64_t for negative values. Check other parts of the code (reference). 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Panquesito7 Sure, Updated

Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work, @riti2409! Thanks for your contribution! 😄👍🎉

Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you just missed one thing: please fix clang-tidy warnings.

@Panquesito7 Panquesito7 added the automated tests are failing Do not merge until tests pass label Aug 30, 2021
@riti2409
Copy link
Contributor Author

riti2409 commented Aug 30, 2021

@Panquesito7 Compile checks for "Awesome CI Workflow / Compile checks (windows-latest) (pull_request)" failed to run because of some server issue in the VM. Is it possible to rerun the checks?
As per the logs it can be verified that freeglut download failed while setting up VM in Awesome CI Workflow for windows.

Edit: I am pushing a small commit to rerun the checks.

@riti2409 riti2409 requested a review from Panquesito7 August 30, 2021 20:42
@Panquesito7 Panquesito7 removed the automated tests are failing Do not merge until tests pass label Aug 30, 2021
Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work, @riti2409! It's been great for your first contribution here! Thank you; we hope you keep contributing. 😄 👍 🎉

@Panquesito7 Panquesito7 added approved Approved; waiting for merge and removed requested changes changes have been requested labels Aug 30, 2021
Copy link
Member

@ayaankhan98 ayaankhan98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@ayaankhan98 ayaankhan98 merged commit 70868f2 into TheAlgorithms:master Aug 31, 2021
@riti2409
Copy link
Contributor Author

@Panquesito7 Thanks for encouraging :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved; waiting for merge enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants