From d0246d606cadc386ee8b892e36786674f3827289 Mon Sep 17 00:00:00 2001 From: sudheerxdev Date: Thu, 30 Apr 2026 16:41:37 +0000 Subject: [PATCH 1/4] Added recursive binary search implementation --- search/recursive_binary_search.cpp | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 search/recursive_binary_search.cpp diff --git a/search/recursive_binary_search.cpp b/search/recursive_binary_search.cpp new file mode 100644 index 00000000000..a47919c42da --- /dev/null +++ b/search/recursive_binary_search.cpp @@ -0,0 +1,53 @@ +/** + * @file recursive_binary_search.cpp + * @brief Recursive Binary Search implementation + */ + +#include +#include +#include + +namespace search { + +namespace recursive_binary_search { + +int binarySearch(const std::vector& arr, + int left, + int right, + int target) { + if (left > right) { + return -1; + } + + int mid = left + (right - left) / 2; + + if (arr[mid] == target) { + return mid; + } + + if (arr[mid] > target) { + return binarySearch(arr, left, mid - 1, target); + } + + return binarySearch(arr, mid + 1, right, target); +} + +} // namespace recursive_binary_search + +} // namespace search + +static void test() { + std::vector arr = {1, 2, 3, 4, 5, 6, 7}; + + int result = search::recursive_binary_search::binarySearch( + arr, 0, arr.size() - 1, 5); + + assert(result == 4); + + std::cout << "Test passed!\n"; +} + +int main() { + test(); + return 0; +} \ No newline at end of file From 6dd3c760dba66c379d0d4930ea436052d628843c Mon Sep 17 00:00:00 2001 From: sudheerxdev Date: Thu, 30 Apr 2026 17:20:07 +0000 Subject: [PATCH 2/4] Fix trie deleteString logic to preserve shared prefix words - Only prune child nodes when they are truly empty (no children, not terminal) - Separate deletion success from node pruning logic - Add regression test for prefix case (Hell/Hello) --- data_structures/trie_tree.cpp | 49 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/data_structures/trie_tree.cpp b/data_structures/trie_tree.cpp index b7b4ce5fd5e..f50de164dfb 100644 --- a/data_structures/trie_tree.cpp +++ b/data_structures/trie_tree.cpp @@ -29,6 +29,16 @@ class trie { std::array, NUM_CHARS << 1> arr; bool isEndofWord = false; ///< identifier if a node is terminal node + /** @brief Check whether the current trie node has any children */ + bool hasChildren() const { + for (const auto& child : arr) { + if (child) { + return true; + } + } + return false; + } + /** * @brief Convert a character to integer for indexing * @@ -137,36 +147,22 @@ class trie { return false; } isEndofWord = false; - // following lines - possible source of error? - // for (int i = 0; i < NUM_CHARS; i++) - // if (!arr[i]) - // return false; return true; } int j = char_to_int(str[index]); if (!arr[j]) { return false; } - bool var = deleteString(str, index + 1); - if (var) { + bool deleted = arr[j]->deleteString(str, index + 1); + if (!deleted) { + return false; + } + + if (!arr[j]->isEndofWord && !arr[j]->hasChildren()) { arr[j].reset(); - if (isEndofWord) { - return false; - } else { - int i = 0; - for (i = 0; i < NUM_CHARS; i++) { - if (arr[i]) { - return false; - } - } - return true; - } } - /* should not return here */ - std::cout << __func__ << ":" << __LINE__ - << "Should not reach this line\n"; - return false; + return true; } }; } // namespace data_structures @@ -192,10 +188,13 @@ static void test() { assert(root.search("World", 0)); std::cout << "World - " << root.search("World", 0) << "\n"; - // Following lines of code give erroneous output - // root.deleteString("hello", 0); - // assert(!root.search("hello", 0)); - // std::cout << "hello - " << root.search("world", 0) << "\n"; + root.insert("Hell"); + assert(root.search("Hell", 0)); + assert(root.search("Hello", 0)); + + assert(root.deleteString("Hello", 0)); + assert(!root.search("Hello", 0)); + assert(root.search("Hell", 0)); } /** From 1f0a6124e4a4f1c2843615167dffc75135e9fc70 Mon Sep 17 00:00:00 2001 From: sudheerxdev Date: Thu, 30 Apr 2026 17:21:56 +0000 Subject: [PATCH 3/4] Fix signed/unsigned comparison warnings in trie deletion --- data_structures/trie_tree.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data_structures/trie_tree.cpp b/data_structures/trie_tree.cpp index f50de164dfb..7999868296c 100644 --- a/data_structures/trie_tree.cpp +++ b/data_structures/trie_tree.cpp @@ -65,7 +65,7 @@ class trie { */ bool search(const std::shared_ptr& root, const std::string& str, int index) { - if (index == str.length()) { + if (index == (int)str.length()) { if (!root->isEndofWord) { return false; } @@ -115,7 +115,7 @@ class trie { * @returns `false` if not found */ bool search(const std::string& str, int index) { - if (index == str.length()) { + if (index == (int)str.length()) { if (!isEndofWord) { return false; } @@ -142,7 +142,7 @@ class trie { * @returns `false` if unsuccessful */ bool deleteString(const std::string& str, int index) { - if (index == str.length()) { + if (index == (int)str.length()) { if (!isEndofWord) { return false; } From 663f37cdab616777bd09e7321ad456e8d56be01d Mon Sep 17 00:00:00 2001 From: sudheerxdev Date: Thu, 30 Apr 2026 17:34:15 +0000 Subject: [PATCH 4/4] Fix CI workflow to create PR instead of direct push to protected branch - Replace direct git push with create-pull-request action - Fixes issue #2411: CI unable to push to master - PR-based approach is safer and aligns with GitHub best practices - CI now creates automatic PRs for formatting/linting fixes - Maintainers can review before merge --- .github/workflows/awesome_workflow.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 473d7940663..fcf7bada175 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -41,11 +41,22 @@ jobs: - name: Lint modified files shell: bash run: python3 scripts/file_linter.py - - name: Commit and push changes - run: | - git diff DIRECTORY.md - git commit -am "clang-format and clang-tidy fixes for ${GITHUB_SHA::8}" || true - git push origin HEAD:$GITHUB_REF || true + - name: Create Pull Request for automated fixes + uses: peter-evans/create-pull-request@v5 + with: + commit-message: 'chore: clang-format and clang-tidy fixes for ${{ github.sha }}' + title: 'chore: Automated formatting and linting fixes' + body: | + ## Automated Changes + This PR contains automated formatting and linting fixes generated by the CI workflow. + + - clang-format applied + - clang-tidy checks fixed + - filename formatting applied + branch: automated-fixes-${{ github.run_number }} + delete-branch: true + author: 'github-actions[bot] ' + committer: 'github-actions[bot] ' build: name: Compile checks