{"componentChunkName":"component---src-templates-blog-post-jsx","path":"/blogs/stringMatchingUsingBruteForceTechnique","result":{"data":{"blog":{"frontmatter":{"title":"STRING MATCHING USING BRUTE FORCE TECHNIQUE","thumbnail":"blog67","date":"May 28, 2021","dsaCppCodeFile":"https://drive.google.com/file/d/1wqQunOFUdAldC4LtQE8J-c_OU22I12lg/view?usp=sharing"},"excerpt":"<div class=\"my-2 p-2\">\n              <h4>Introduction</h4>\n              <div class=\"m-2\">\n                <p>\n                  In string matching algorithm, we check whether a text T\n                  contains a pattern P(length of T>P) i.e to check whether P is\n                  a substring of T or not. Since we are trying to check a fixed\n                  string P, sometimes these algorithms are called exact string\n                  matching algorithms.\n                </p>\n                <p>\n                  In brute force method, for each possible in the text T(length\n                  n), we check whether the pattern P(length m) matches or not.\n                  We loop from start position of the text T and compare each\n                  position of the text with each position of the text. If a\n                  mismatch is found then we loop from second position and\n                  perform comparisons. It continues until the position n-m of\n                  the text.\n                </p>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Working Procedure</h4>\n              <p class=\"text-muted\">\n                Do refer the code available the end of this section to\n                understand the following theory.\n              </p>\n              <ol class=\"pl-4\">\n                <li>\n                  Let m and n be the lengths of pattern P and text T\n                  respectively.\n                </li>\n                <li>\n                  Loop from i=0 to n-m.\n                  <ol class=\"pl-4\">\n                    <li>\n                      Loop from j=0 to m.\n                      <ol class=\"pl-4\">\n                        <li>\n                          If P[j] == T[i+j] then continue looping. That is if\n                          the character in pattern and the character at\n                          corresponding position in text are matching correctly,\n                          so continue looping.\n                        </li>\n                        <li>\n                          Else break the loop, that is a mismatch was found.\n                        </li>\n                      </ol>\n                    </li>\n                    <li>\n                      If i==m then the pattern was successfully found at\n                      position i;\n                    </li>\n                  </ol>\n                </li>\n                <li>\n                  If you arrived at this step then it means that the pattern\n                  wasn't found, so return -1.\n                </li>\n              </ol>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Time Complexity: O(n*m)</h4>\n            </div>\n\t\t\t        <div class=\"my-2 p-2\">\n                <strong>Similar posts:</strong>\n                  <a href=\"/blogs/stringMatchingUsingHorspoolsAlgorithm\">String Matching Using Horspool's Algorithm</a>\n            </div>\n","html":"<div class=\"my-2 p-2\">\n              <h4>Introduction</h4>\n              <div class=\"m-2\">\n                <p>\n                  In string matching algorithm, we check whether a text T\n                  contains a pattern P(length of T>P) i.e to check whether P is\n                  a substring of T or not. Since we are trying to check a fixed\n                  string P, sometimes these algorithms are called exact string\n                  matching algorithms.\n                </p>\n                <p>\n                  In brute force method, for each possible in the text T(length\n                  n), we check whether the pattern P(length m) matches or not.\n                  We loop from start position of the text T and compare each\n                  position of the text with each position of the text. If a\n                  mismatch is found then we loop from second position and\n                  perform comparisons. It continues until the position n-m of\n                  the text.\n                </p>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Working Procedure</h4>\n              <p class=\"text-muted\">\n                Do refer the code available the end of this section to\n                understand the following theory.\n              </p>\n              <ol class=\"pl-4\">\n                <li>\n                  Let m and n be the lengths of pattern P and text T\n                  respectively.\n                </li>\n                <li>\n                  Loop from i=0 to n-m.\n                  <ol class=\"pl-4\">\n                    <li>\n                      Loop from j=0 to m.\n                      <ol class=\"pl-4\">\n                        <li>\n                          If P[j] == T[i+j] then continue looping. That is if\n                          the character in pattern and the character at\n                          corresponding position in text are matching correctly,\n                          so continue looping.\n                        </li>\n                        <li>\n                          Else break the loop, that is a mismatch was found.\n                        </li>\n                      </ol>\n                    </li>\n                    <li>\n                      If i==m then the pattern was successfully found at\n                      position i;\n                    </li>\n                  </ol>\n                </li>\n                <li>\n                  If you arrived at this step then it means that the pattern\n                  wasn't found, so return -1.\n                </li>\n              </ol>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Time Complexity: O(n*m)</h4>\n            </div>\n\t\t\t        <div class=\"my-2 p-2\">\n                <strong>Similar posts:</strong>\n                  <a href=\"/blogs/stringMatchingUsingHorspoolsAlgorithm\">String Matching Using Horspool's Algorithm</a>\n            </div>"},"thumbnail":{"childImageSharp":{"fluid":{"tracedSVG":"data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='225'%20viewBox='0%200%20400%20225'%20preserveAspectRatio='none'%3e%3cpath%20d='M44%2095c-4%200-5%200-5%202h-1c-1-3-7-3-9%200-3%203-2%207%201%209%204%203%204%204%200%204-3-1-5%201-2%203%202%201%207%201%208-1%203-2%202-7%200-8l-2-2h2l3-1%202-1c2%200%202%201%202%207%200%207%200%207%202%207%203%200%203%200%203-7s1-8%203-8%202-1%202-2c-1-3-1-3-9-2m25%201l-1%2010v8h11v-8l2%204c2%203%202%204%204%204s3-1%203-10v-9h-2c-3%200-3%200-3%203v4l-1-4c-2-4-7-4-7%200-1%202-1%202-1-1%200-2%200-3-2-3s-3%201-3%202m80-1c-5%200-5%200-5%203l2%202c2%200%202%201%202%207%200%207%200%207%203%207%202%200%202%200%202-7%200-8%200-8%203-8%202%200%202%200%202-2-1-3-1-3-9-2m14%200c-5%203-7%2013-3%2017s11%201%2011-3c0-3-2-3-4-1l-2%201v-8c0-3%202-2%202%200%200%201%201%202%203%202%203%200%203-5%200-7s-4-2-7-1m11%204l-1%2010c0%205%200%205%202%205%203%200%203-1%203-4%201-5%204-6%204%200%200%203%200%204%202%204h3v-10c0-10%200-10-2-10s-3%201-3%204l-2%204-1-4c0-3-1-4-3-4-1%200-2%201-2%205m15-3l-1%2010v8h11v-8l2%204c1%203%202%204%204%204s2%200%202-4l1-10c0-5%200-5-2-5-3%200-3%200-3%203v4l-1-4c-2-3-6-4-7-1-1%201-1%201-1-1%200-3-5-3-5%200M54%2098l-1%2010c0%206%200%206%202%206%203%200%203%200%203-3l1-3%202%203c1%203%201%203%204%202%202-1%202-1%201-4-2-2-2-3%200-4v-9l-7-1h-5v3m37%200c-3%204-3%2014%201%2015%205%203%2012-4%209-8-2-3-5-2-6%202l-1%202c-1-2%200-9%202-10l1%201c0%201%201%202%203%202s3-2%201-5-7-3-10%201m20%201l-1%209c0%206%200%206%203%206l2-2c0-2%200-2%202-1s2%201%203-1c2-1%202-1%201%201v3h6l6-1c0-3%204-3%204-1l3%202c3%200%203%200%202-5-1-11-2-13-5-14-3%200-4%200-6%206l-3%209c0%202-1%201-1-6%200-8-1-9-3-9l-4%204-1%204-1-4c-2-5-7-6-7%200m100-1c-4%205-3%2015%201%2016%206%201%2012-6%209-10-3-3-8%201-6%205l-1%201-1-3c0-4%202-8%203-7v1l2%201c4%200%205-2%203-5s-7-3-10%201m88%208l-1%208v7h9c8%200%209%201%209%203s0%202-2%202c-5-1-16%2013-21%2026l-3%2020%206-7c4-5%206-7%2010-8%206-3%206-2%206%201%200%202%200%202%201%201h3l-2-5-2-7-1-3v-3c3-2%2013-2%2013%200l-1%201h-2c0%202%203%202%204%201h1l-1%202-1%203-2%207-2%204h3c2%200%202-1%201-3%200-2%200-2%207%200%204%201%205%202%207%205l3%204%201%203%202%206%202%204%201%204c2%207-1%2010-9%208h-4v-24h-15v-3l-1-3-1%203v3h-17v7l-1%208c-2%202-2%203-1%203%202%200%203%204%202%206h-15c-2-3-2-5%201-8%204-6%202-7-2-2-3%203-4%205-4%207%200%203%200%203-9%204-9%200-9%200-9%202s1%203%205%203h5l-1%204v3h97l1-4c1-2%202-3%205-3%205-1%205-4%200-5h-3v-14c0-14-1-21-4-21l-2-2c-1-2-1-2-1%200%200%203-8%203-8-1%200-2%200-2%202-2%202%201%203%200%201-1-2-2-1-4%203-12%206-11%205-17-1-20l-3-2-1-1-1-4-1-5c-1-1-1%201-1%204v5l-3-1c-3-1-22%200-24%201-1%201-1-1-1-4v-5l-14-1-13%201m2%207v7h22v-3l1-3v-1l-1-3v-3h-22v6m-31%2028l1%209h12v-18h-13v9m3%2023l-1%205c0%203%200%204-1%203%200-4-2-3-3%200l2%204%202%203%203%201c2%200%202%200%202-3%200-2%200-3%202-3s2-1%202-4l-1-4-1%203c0%203-2%202-2-2%200-3-1-4-4-3'%20fill='%23d3d3d3'%20fill-rule='evenodd'/%3e%3c/svg%3e","aspectRatio":1.7699115044247788,"src":"/static/de05d7676d00345787adb52ca4f13f5f/ee604/blog67.png","srcSet":"/static/de05d7676d00345787adb52ca4f13f5f/69585/blog67.png 200w,\n/static/de05d7676d00345787adb52ca4f13f5f/497c6/blog67.png 400w,\n/static/de05d7676d00345787adb52ca4f13f5f/ee604/blog67.png 800w,\n/static/de05d7676d00345787adb52ca4f13f5f/f3583/blog67.png 1200w,\n/static/de05d7676d00345787adb52ca4f13f5f/e4d72/blog67.png 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"pageContext":{"blog":"stringMatchingUsingBruteForceTechnique","thumbnail":"thumbnails/blog67.png"}},"staticQueryHashes":["2987289216","63159454"]}