{"id":82231,"date":"2021-07-27T09:00:09","date_gmt":"2021-07-27T03:30:09","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=82231"},"modified":"2021-07-27T09:00:09","modified_gmt":"2021-07-27T03:30:09","slug":"merge-sort","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/","title":{"rendered":"Merge Sort in Data Structure"},"content":{"rendered":"<p>Merge sort is a sorting algorithm based on the Divide and conquer strategy. It works by recursively dividing the array into two equal halves, then sort them and combine them. It takes a time of (n logn) in the worst case.<\/p>\n<h3>What is Merge Sort?<\/h3>\n<p>The merge sort algorithm is an implementation of the divide and conquer technique. Thus, it gets completed in three steps:<\/p>\n<p><strong>1. Divide:<\/strong> In this step, the array\/list divides itself recursively into sub-arrays until the base case is reached.<\/p>\n<p><strong>2. Recursively solve:<\/strong> Here, the sub-arrays are sorted using recursion.<\/p>\n<p><strong>3. Combine:<\/strong> This step makes use of the <strong>merge(<\/strong> ) <strong>function<\/strong> to combine the sub-arrays into the final sorted array.<\/p>\n<h3>Algorithm for Merge Sort<\/h3>\n<p>Step 1: Find the middle index of the array.<br \/>\nMiddle = 1 + (last &#8211; first)\/2<br \/>\nStep 2: Divide the array from the middle.<br \/>\nStep 3: Call merge sort for the first half of the array<br \/>\nMergeSort(array, first, middle)<br \/>\nStep 4: Call merge sort for the second half of the array.<br \/>\nMergeSort(array, middle+1, last)<br \/>\nStep 5: Merge the two sorted halves into a single sorted array.<\/p>\n<h3>Pseudo-code for Merge Sort<\/h3>\n<p>Consider an array Arr which is being divided into two sub-arrays left and right. Let L1 = Number of elements in the left sub-array; and L2 = Number of elements in the right sub-array.<\/p>\n<p>Let variable i point to the first index of the left sub-array and j point to the first index of the right sub-array. Then, the pseudo-code for the merge( ) function will be:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">procedure merge(Arr[], lt, mid, rt):\n    int L1 = mid - lt + 1\n    int L2 = rt-mid\n    int left[L1], right[L2]\n    \n    for i = 0 to L1:\n        left[i] = Arr[lt + i]\n    END for loop\n    \n    for j = 0 to L2:\n        right[j] = Arr[mid+1+j]\n    END for loop\n    \n    while(left and right hve elments):\n        if(left[i] &lt; right[j])\n            Add left[i] to the end of Arr\n        else\n            Add right[i] to the end of Arr\n    END while loop\n    \nEND procedure    \n\nprocedure Merge_sort(Arr[]):\n    l1 = Merge_sort(L1)\n    l2 = Merge_sort(L2)\n    return merge(l1, l2)\nEND procedure\n<\/pre>\n<h3>Working of Merge Sort<\/h3>\n<p>Consider an array having the following elements: 1,6,3,2,7,5,8,4. We need to sort this array using merge sort.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82958\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image01.jpg\" alt=\"Merge Sort Example\" width=\"465\" height=\"66\" \/><\/a><\/p>\n<p>There is a total of 8 elements in the array. Thus, mid = 4. So we will first divide this array into two arrays of size 4 as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82959\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image02.jpg\" alt=\"Merge Sort Working\" width=\"500\" height=\"66\" \/><\/a><\/p>\n<p>Next, we recursively divide these arrays into further halves. The half of 4 is 2. So, now we have 4 arrays of size 2 each.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image03.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82960\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image03.jpg\" alt=\"Merge Sort Iterations\" width=\"549\" height=\"66\" \/><\/a><\/p>\n<p>We will keep on dividing into further halves until we have reached an array length of size 1 as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image04.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82961\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image04.jpg\" alt=\"Iterations in merge Sort\" width=\"637\" height=\"66\" \/><\/a><\/p>\n<p>After this, we have the combining step. We will compare each element with its consecutive elements and arrange them in a sorted manner.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image05.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82962\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image05.jpg\" alt=\"Merge sort Working\" width=\"541\" height=\"66\" \/><\/a><\/p>\n<p>In the next iteration, we will compare two arrays and sort them as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image06.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82963\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image06.jpg\" alt=\"Merge Sort Iterations\" width=\"500\" height=\"66\" \/><\/a><\/p>\n<p>Finally, we will compare the elements of the two arrays each of size 4 and we will get our resultant sorted array as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image07.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82964\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TechVidvan-Merge-sort-normal-image07.jpg\" alt=\"Merge Sort Output\" width=\"465\" height=\"66\" \/><\/a><\/p>\n<h3>Characteristics of Merge Sort<\/h3>\n<p><strong>1. External sorting algorithm:<\/strong> Merge sort can be used when the data size is more than the RAM size. In such a case, whole data cannot come into RAM at once. Thus, data is loaded into the RAM in small chunks and the rest of the data resides in the secondary memory.<\/p>\n<p><strong>2. Non-inplace sorting algorithm:<\/strong> Merge sort is not an inplace sorting technique as its space complexity is O(n). Inplace or space-efficient algorithms are those whose space complexity is not more than O(logn).<\/p>\n<h3>Implementation of Merge Sort in C<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\nvoid Merge_sort(int[], int, int);\nvoid merge(int[], int, int, int);\n void Display_array(int[], int);\nint main()\n{\n    int array[] = {1,6,3,2,7,5,8,4};\n    int arr_size = sizeof(array) \/ sizeof(arr[0]);\n \n    printf(\"Given array is: \\n\");\n    Display_array(array, arr_size);\n    Merge_sort(array, 0, arr_size - 1);\n    printf(\"\\nSorted array is: \\n\");\n    Display_array(array, arr_size);\n    return 0;\n}\n\nvoid merge(int Arr[], int lt, int mid, int rt)\n{\n    int i, j, k;\n    int L1 = mid - lt + 1;\n    int L2 = rt - mid;\n    int left[L1], right[L2];    \/\/Creating temporary arrays, additional memory needed\n    for (i = 0; i &lt; L1; i++)\n        left[i] = Arr[lt + i];\n        \n    for (j = 0; j &lt; L2; j++)\n        right[j] = Arr[mid + 1 + j];\n    i = j = 0;\n    k = 1;\n    while (i &lt; L1 &amp;&amp; j &lt; L2) {\n        if (left[i] &lt;= right[j]) {\n            Arr[k] = left[i];\n            i++;\n        }\n        else {\n            Arr[k] = right[j];\n            j++;\n        }\n        k++;\n    }\n \n    while (i &lt; L1) \n        Arr[k++] = left[i++];\n \n    while (j &lt; L2) \n        Arr[k++] = right[j++];\n}\n\nvoid Merge_sort(int Arr[], int l, int r)\n{\n    if (l &lt; r) {\n        int mid = l + (r - l) \/ 2;\n        Merge_sort(Arr, l, mid);\n        Merge_sort(Arr, mid + 1, r);\n        merge(Arr, l, mid, r);\n    }\n}\n\nvoid Display_array(int a[], int size)\n{\n    for (int i = 0; i &lt; size; i++)\n        printf(\"%d \", a[i]);\n    printf(\"\\n\");\n}\n<\/pre>\n<h3>Implementation of Merge Sort in C++<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nvoid merge(int[], int, int, int);\nvoid Merge_sort(int[], int, int);\nvoid Display_array(int[], int);\n\nint main()\n{\n  int array[] = {1,6,3,2,7,5,8,4};\n  auto arr_size = sizeof(array) \/ sizeof(arr[0]);\n\n  cout &lt;&lt; \"Given array is: \\n\";\n  Display_array(array, arr_size);\n  Merge_sort(array, 0, arr_size - 1);\n\n  cout &lt;&lt; \"\\nThe sorted array is: \\n\";\n  Display_array(array, arr_size);\n  return 0;\n}\n\nvoid merge(int Arr[], int lt, int mid, int rt)\n{\n  L1 = mid - lt + 1;\n  L2 = rt - mid;\n    int i, j, k;\n  auto *left = new int[L1],\n    *rightArray = new int[L2];\n    \n  for (int i = 0; i &lt; L1; i++)\n    left[i] = Arr[lt + i];\n  for (int j = 0; j &lt; L2; j++)\n    right[j] = Arr[mid + 1 + j];\n    i = j = 0;\n    k = 1;\n\nwhile (i &lt; L1 &amp;&amp; j &lt; L2) {\n        if (left[i] &lt;= right[j]) {\n            Arr[k] = left[i];\n            i++;\n        }\n        else {\n            Arr[k] = right[j];\n            j++;\n        }\n        k++;\n    }\n \n    while (i &lt; L1) \n        Arr[k++] = left[i++];\n \n    while (j &lt; L2) \n        Arr[k++] = right[j++];\n\n}\n\nvoid Merge_sort(int Arr[], int l, int r)\n{\n    if (l &lt; r) {\n        int mid = l + (r - l) \/ 2;\n        Merge_sort(Arr, l, mid);\n        Merge_sort(Arr, mid + 1, r);\n        merge(Arr, l, mid, r);\n    }\n}\n\n\nvoid Display_array(int a[], int size)\n{\n  for (int i = 0; i &lt; size; i++)\n    cout &lt;&lt; a[i] &lt;&lt; \" \";\n}\n<\/pre>\n<h3>Merge Sort Implementation in Java<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class MergeSort\n{\n  void merge(int Arr[], int lt, int mid, int rt)\n  {\n    int L1 = mid - lt + 1;\n    int L2 = rt - mid;\n    int left[] = new int[L1];\n    int right[] = new int[L2];\n\n    for (int i = 0; i &lt; L1; i++)\n      left[i] = Arr[lt + i];\n    for (int j = 0; j &lt; L2; j++)\n      right[j] = Arr[mid + 1 + j];\n    int i = 0, j = 0;\n    int k = l;\n    while (i &lt; L1 &amp;&amp; j &lt; L2) {\n      if (left[i] &lt;= right[j]) {\n        Arr[k] = left[i];\n        i++;\n      }\n      else {\n        Arr[k] = right[j];\n        j++;\n      }\n      k++;\n    }\n\n    while (i &lt; L1) \n      Arr[k++] = left[i++];\n  \n    while (j &lt; L2) \n      Arr[k++] = right[j++];\n  }\n\n  void Merge_sort(int Arr[], int l, int r)\n  {\n    if (l &lt; r) {\n      int mid =l+ (r-l)\/2;\n      Merge_sort(Arr, l, mid);\n      Merge_sort(Arr, mid + 1, r);\n      merge(Arr, l, mid, r);\n    }\n  }\n\n  static void Display_array(int a[])\n  {\n    int n = a.length;\n    for (int i = 0; i &lt; n; ++i)\n      System.out.print(a[i] + \" \");\n    System.out.println();\n  }\n\n  public static void main(String args[])\n  {\n    int array[] = {1,6,3,2,7,5,8,4};\n    System.out.println(\"Given array is: \");\n    Display_array(array);\n    MergeSort ob = new MergeSort();\n    ob.Merge_sort(array, 0, array.length - 1);\n    System.out.println(\"\\nSorted array is: \");\n    Display_array(array);\n  }\n}<\/pre>\n<h3>Implementation of Merge Sort in Python<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def Merge_sort(Arr):\n  if len(Arr) &gt; 1:\n    mid = len(Arr)\/\/2\n    left = Arr[:mid]\n    right = Arr[mid:]\n    Merge_sort(left)\n    Merge_sort(right)\n\n    i = j = k = 0\n    while i &lt; len(left) and j &lt; len(right):\n      if len[i] &lt; right[j]:\n        Arr[k] = left[i]\n        i += 1\n      else:\n        Arr[k] = right[j]\n        j += 1\n      k += 1\n\n    while i &lt; len(left):\n      Arr[k] = left[i]\n      i += 1\n      k += 1\n\n    while j &lt; len(right):\n      Arr[k] = right[j]\n      j += 1\n      k += 1\n\ndef Display_list(a):\n  for i in range(len(a)):\n    print(a[i], end=\" \")\n  print()\n\nif __name__ == '__main__':\n  list = [1,6,3,2,7,5,8,4]\n  print(\"Given array is: \", end=\"\\n\")\n  Display_list(list)\n  Merge_sort(list)\n  print(\"Sorted array is: \", end=\"\\n\")\n  Display_list(list)<\/pre>\n<h3>Complexity of Merge Sort<\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Scenario<\/b><\/td>\n<td><b>Time complexity<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Worst case<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(n logn)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Average case<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(n logn)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Best case<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(n logn)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The space complexity of merge sort is O(n).<\/p>\n<h3>Applications of Merge Sort<\/h3>\n<p><strong>1. To sort linked lists in O(n logn) time:<\/strong> In the case of a linked list, we can insert the element in the middle or anywhere in between the linked list with time complexity of O(1). If we use merge sort to sort such a linked list, we can do so with the space complexity of O(1). Also, we cannot do random access in a linked list and merge sort also does not work well in case of random access. Thus, merge sort is the best algorithm to sort a linked list with the complexity of O(n logn).<\/p>\n<p><strong>2. Inversion count problem:<\/strong> Merge sort helps to solve this problem by telling the number of inversion pairs in an unsorted array. The inversion count problem tells how many pairs need to be swapped in order to get a sorted array. Merge sort works best for solving this problem.<\/p>\n<p><strong>3. External sorting:<\/strong> Merge sort is an external sorting technique. Thus, if we have data of 1GB but the available RAM size is 500MB, then we will use merge sort.<\/p>\n<h3>Drawbacks of Merge Sort<\/h3>\n<ul>\n<li>Merge sort is not a space-efficient algorithm. It makes use of an extra O(n) space.<\/li>\n<li>In the case of smaller input size, merge sort works slower in comparison to other sorting techniques.<\/li>\n<li>If the data is already sorted, merge sort will be a very expensive algorithm in terms of time and space. This is because it will still traverse the whole array and perform all the operations.<\/li>\n<\/ul>\n<h3>Conclusion<\/h3>\n<p>Merge sort is one of the most widely used algorithms in data structures. Although it is not a space-efficient algorithm, its time complexity is of the order O(n logn) which is better than most of the sorting algorithms. Whenever we have an input size larger than the RAM size, we use merge sort. Thus, merge sort is very well suited for larger datasets.<\/p>\n<p>In this article, we have studied what is merge sort, how it works, its applications, drawbacks as well as its implementation in various programming languages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Merge sort is a sorting algorithm based on the Divide and conquer strategy. It works by recursively dividing the array into two equal halves, then sort them and combine them. It takes a time&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":82956,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3555],"tags":[3840,3841,3842,3843,3844,3845],"class_list":["post-82231","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-structure","tag-applications-of-merge-sort","tag-merge-sort","tag-merge-sort-algorithm","tag-merge-sort-pseudo-code","tag-merge-sorting","tag-working-of-merge-sort"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Merge Sort in Data Structure - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn what is merge sort, how it works, its applications, drawbacks as well as its implementation in various programming languages.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/merge-sort\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Merge Sort in Data Structure - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn what is merge sort, how it works, its applications, drawbacks as well as its implementation in various programming languages.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/merge-sort\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-27T03:30:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TechVidvan-Merge-sort.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Merge Sort in Data Structure - TechVidvan","description":"Learn what is merge sort, how it works, its applications, drawbacks as well as its implementation in various programming languages.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/","og_locale":"en_US","og_type":"article","og_title":"Merge Sort in Data Structure - TechVidvan","og_description":"Learn what is merge sort, how it works, its applications, drawbacks as well as its implementation in various programming languages.","og_url":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-07-27T03:30:09+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TechVidvan-Merge-sort.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Merge Sort in Data Structure","datePublished":"2021-07-27T03:30:09+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/"},"wordCount":876,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TechVidvan-Merge-sort.jpg","keywords":["applications of merge sort","Merge sort","Merge sort algorithm","merge sort pseudo code","merge sorting","working of merge sort"],"articleSection":["Data Structure Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/merge-sort\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/","url":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/","name":"Merge Sort in Data Structure - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TechVidvan-Merge-sort.jpg","datePublished":"2021-07-27T03:30:09+00:00","description":"Learn what is merge sort, how it works, its applications, drawbacks as well as its implementation in various programming languages.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/merge-sort\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TechVidvan-Merge-sort.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TechVidvan-Merge-sort.jpg","width":1200,"height":628,"caption":"Merge sort"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/merge-sort\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Merge Sort in Data Structure"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/82231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=82231"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/82231\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/82956"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=82231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=82231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=82231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}