searching Algorithm

The Searching in Sorted Matrix Algorithm is an efficient technique used to search for a target value in a sorted matrix, which is a two-dimensional array where each row and column is sorted in ascending order. This algorithm is particularly useful when dealing with large datasets, as it significantly reduces the time complexity of searching compared to other linear or brute-force methods. The key to this algorithm is taking advantage of the sorted property of the matrix, which allows for a more systematic and directed search. The algorithm essentially starts at the top-right corner of the matrix and moves either downwards or leftwards based on the comparison between the target value and the current element. If the target value is greater than the current element, the algorithm moves one row down, as it eliminates the need to search the current row further since all elements in that row will be smaller than the target value. On the other hand, if the target value is smaller than the current element, the algorithm moves one column to the left, as it eliminates the need to search the current column further since all elements in that column will be greater than the target value. This process is repeated until the target value is found or the algorithm goes out of the matrix bounds, indicating that the target value is not present in the matrix. The time complexity of this algorithm is O(m + n), where m is the number of rows and n is the number of columns in the matrix.
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;
char paragraph;

int main()
{
    string paragraph;
    cout << "Please enter your paragraph: \n";
    getline(cin, paragraph);
    cout << "\nHello, your paragraph is:\n " << paragraph << "!\n";
    cout << "\nThe size of your paragraph = " << paragraph.size() << " characters. \n\n";

    if (paragraph.empty())
    {
        cout << "\nThe paragraph is empty" << endl;
    }
    else
    {
        while (true)
        {
            string word;
            cout << "Please enter the word you are searching for: ";
            getline(cin, word);
            cout << "Hello, your word is " << word << "!\n";
            if (paragraph.find(word) == string::npos)
            {
                cout << word << " does not exist in the sentence" << endl;
            }
            else
            {
                cout << "The word " << word << " is now found at location " << paragraph.find(word) << endl
                     << endl;
            }
            system("pause");
        }
    }
}

LANGUAGE:

DARK MODE: