{"id":16629,"date":"2023-06-01T06:35:12","date_gmt":"2023-06-01T06:35:12","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=16629"},"modified":"2023-06-01T07:18:53","modified_gmt":"2023-06-01T07:18:53","slug":"median-of-two-sorted-arrays-of-different-size-in-c","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/","title":{"rendered":"Median of two Sorted Arrays of Different Size in C"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg\" alt=\"\" \/><\/p>\n<p>The aim is to determine the median of two sorted arrays, a[] and b[], where N is the number of items in the first array and M is the number of elements in the second array. In this post, we will look at numerous techniques to solve this problem.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre><code>Input format: arr1 = [1,4,7,10,12], arr2 = [2,3,6,15]<\/code><\/pre>\n<p><strong>Output format<\/strong>:<\/p>\n<pre><code>6.00000<\/code><\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nCombine the two arrays. The final array is [1,2,3,4,6,7,10,12,15]. We know that the mid element is used to calculate the median. Because the element&#8217;s size is unusual. According to the formula, the median will be at the [(n+1)\/2]th place in the final sorted array. In this case, the median is at [(9+1)\/2]th place, which equals [5]th = 6.<\/p>\n<p><strong>Example 2:<\/strong><\/p>\n<pre><code>Input: arr1 = [1], arr2 = [2]<\/code><\/pre>\n<p><strong>Output format:<\/strong> <\/p>\n<pre><code>1.50000<\/code><\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nCombine the two arrays. [1,2] is the final sorted array. We know that the mid element is used to calculate the median. Because the element&#8217;s size is consistent. The median is defined as the mean of the items in the [n\/2]th and [(n\/2)+1]th positions of the final sorted array. In this case, the median is (1+2)\/2 = 3\/2 = 1.50000.<\/p>\n<h2>Method 1 : Merging two sorted arrays in a third array<\/h2>\n<p>The idea is to merge them into third array and there are two cases:<\/p>\n<p><strong>Case 1:<\/strong> If the length of the third array is odd, then the median is at (length)\/2th index in the array obtained after merging both the arrays.<\/p>\n<p><strong>Case 2:<\/strong> If the length of the third array is even, then the median will be the average of elements at index ((length)\/2 ) and ((length)\/2 \u2013 1) in the array obtained after merging both arrays.<\/p>\n<h3>Algorithm to solve merging of two sorted arrays in a third array<\/h3>\n<ol>\n<li>Merge the two given arrays into one array.<\/li>\n<li>Then sort the third(merged) array<\/li>\n<li>If the length of the third array is even then: <\/li>\n<li>Divide the length of the array by 2. Return (arr[value]  + arr[value \u2013 1] \/ 2).<\/li>\n<li>If the length of the third array is odd then: <\/li>\n<li>Divide the length of the array by 2 and round that value and return the array[value]<\/li>\n<\/ol>\n<h3>Code implementation in C<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_16627 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_16627 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_16627 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_16627 .wpsm_nav-tabs > li.active > a, #tab_container_16627 .wpsm_nav-tabs > li.active > a:hover, #tab_container_16627 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_16627 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_16627 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_16627 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_16627 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_16627 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_16627 .wpsm_nav-tabs > li > a:hover , #tab_container_16627 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_16627 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_16627 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_16627 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_16627 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_16627 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_16627 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_16627 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_16627 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_16627 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_16627 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_16627 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_16627\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_16627\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_16627_1\" aria-controls=\"tabs_desc_16627_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_16627\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_16627_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\nint Solution(int arr[], int n)\r\n{\r\n    if (n % 2 == 0)\r\n    {\r\n        int z = n \/ 2;\r\n        int e = arr[z];\r\n        int q = arr[z - 1];\r\n        int ans = (e + q) \/ 2;\r\n        return ans;\r\n    }\r\n    else\r\n    {\r\n        int z = n \/ 2;\r\n        return arr[z];\r\n    }\r\n}\r\n\r\nint main()\r\n{\r\n    int arr1[] = {-5, 3, 6, 12, 15};\r\n    int arr2[] = {-12, -10, -6, -3, 4, 10};\r\n    int i = sizeof(arr1) \/ sizeof(arr1[0]);\r\n    int j = sizeof(arr2) \/ sizeof(arr2[0]);\r\n    int l = i + j;\r\n    int* arr3 = (int*)malloc(l * sizeof(int));\r\n    for (int k = 0; k &lt; i; k++)\r\n    {\r\n        arr3[k] = arr1[k];\r\n    }\r\n\r\n    int a = 0;\r\n    for (int k = i; k &lt; l; k++)\r\n    {\r\n        arr3[k] = arr2[a++];\r\n    }\r\n    for (int m = 0; m &lt; l - 1; m++)\r\n    {\r\n        for (int n = 0; n &lt; l - m - 1; n++)\r\n        {\r\n            if (arr3[n] &gt; arr3[n + 1])\r\n            {\r\n                int temp = arr3[n];\r\n                arr3[n] = arr3[n + 1];\r\n                arr3[n + 1] = temp;\r\n            }\r\n        }\r\n    }\r\n    int median = Solution(arr3, l);\r\n    printf(\"Median = %d&#92;n\", median);\r\n    free(arr3);\r\n    return 0;\r\n}<\/pre>\r\n&nbsp;\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_16627 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_16627 a\"),jQuery(\"#tab-content_16627\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><br \/>\nMedian = 4 <\/p>\n<h2>Method 2 : Merging two sorted arrays using recursion<\/h2>\n<p>The idea is simple, calculate the median of both arrays and discard one-half of each array. This approach takes into consideration the size of the arrays. The smaller-sized array is considered the first array in the parameter.<\/p>\n<h3>Algorithm to solve merging of two sorted arrays using recursion<\/h3>\n<ol>\n<li>Create a recursive function that takes two arrays and the sizes of both arrays.<\/li>\n<li>Take care of the base cases for the size of arrays less than 2. (previously discussed in Approach).Note: The first array is always the smaller array.<\/li>\n<li>Find the middle elements of both arrays. i.e element at (n \u2013 1)\/2 and (m \u2013 1)\/2 of first and second array respectively. Compare both elements.<\/li>\n<li>If the middle element of the smaller array is less than the middle element of the larger array then the first half of the smaller array is bound to lie strictly in the first half of the merged array. It can also be stated that there is an element in the first half of the larger array and the second half of the smaller array which is the median. So, reduce the search space to the first half of the larger array and the second half of the smaller array.<\/li>\n<li>Similarly, If the middle element of the smaller array is greater than the middle element of the larger array then reduce the search space to the first half of the smaller array and the second half of the larger array.<\/li>\n<\/ol>\n<h3>Code implementation in C<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_16630 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_16630 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_16630 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_16630 .wpsm_nav-tabs > li.active > a, #tab_container_16630 .wpsm_nav-tabs > li.active > a:hover, #tab_container_16630 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_16630 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_16630 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_16630 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_16630 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_16630 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_16630 .wpsm_nav-tabs > li > a:hover , #tab_container_16630 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_16630 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_16630 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_16630 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_16630 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_16630 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_16630 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_16630 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_16630 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_16630 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_16630 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_16630 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_16630\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_16630\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_16630_1\" aria-controls=\"tabs_desc_16630_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_16630\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_16630_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\r\nfloat MO2(int a, int b) { return (a + b) \/ 2.0; }\r\nfloat MO3(int a, int b, int c)\r\n{\r\n    return a + b + c - ((a &gt; b) ? a : b) - ((a &gt; c) ? a : c) - ((b &gt; c) ? b : c);\r\n}\r\nfloat MO4(int a, int b, int c, int d)\r\n{\r\n    int max_val = (a &gt; b) ? ((a &gt; c) ? ((a &gt; d) ? a : d) : ((c &gt; d) ? c : d)) : ((b &gt; c) ? ((b &gt; d) ? b : d) : ((c &gt; d) ? c : d));\r\n    int min_val = (a &lt; b) ? ((a &lt; c) ? ((a &lt; d) ? a : d) : ((c &lt; d) ? c : d)) : ((b &lt; c) ? ((b &lt; d) ? b : d) : ((c &lt; d) ? c : d));\r\n    return (a + b + c + d - max_val - min_val) \/ 2.0;\r\n}\r\nfloat medianSingle(int arr[], int n)\r\n{\r\n    if (n == 0)\r\n        return -1;\r\n    if (n % 2 == 0)\r\n        return (arr[n \/ 2] + arr[n \/ 2 - 1]) \/ 2.0;\r\n    return arr[n \/ 2];\r\n}\r\nfloat findMedianUtil(int A[], int N, int B[], int M)\r\n{\r\n    if (N == 0)\r\n        return medianSingle(B, M);\r\n\r\n    if (N == 1)\r\n    {\r\n        if (M == 1)\r\n            return MO2(A[0], B[0]);\r\n\r\n        if (M &amp; 1)\r\n            return MO2(B[M \/ 2], MO3(A[0], B[M \/ 2 - 1], B[M \/ 2 + 1]));\r\n\r\n        return MO3(B[M \/ 2], B[M \/ 2 - 1], A[0]);\r\n    }\r\n    else if (N == 2)\r\n    {\r\n        if (M == 2)\r\n            return MO4(A[0], A[1], B[0], B[1]);\r\n\r\n        if (M &amp; 1)\r\n            return MO3(B[M \/ 2], max(A[0], B[M \/ 2 - 1]), min(A[1], B[M \/ 2 + 1]));\r\n\r\n        return MO4(B[M \/ 2], B[M \/ 2 - 1], max(A[0], B[M \/ 2 - 2]), min(A[1], B[M \/ 2 + 1]));\r\n    }\r\n\r\n    int idxA = (N - 1) \/ 2;\r\n    int idxB = (M - 1) \/ 2;\r\n\r\n    if (A[idxA] &lt;= B[idxB])\r\n        return findMedianUtil(A + idxA, N \/ 2 + 1, B, M - idxA);\r\n    return findMedianUtil(A, N \/ 2 + 1, B + idxA, M - idxA);\r\n}\r\n\r\nfloat findMedian(int A[], int N, int B[], int M)\r\n{\r\n    if (N &gt; M)\r\n        return findMedianUtil(B, M, A, N);\r\n\r\n    return findMedianUtil(A, N, B, M);\r\n}\r\n\r\nint main()\r\n{\r\n    int A[] = {900};\r\n    int B[] = {5, 8, 10, 20};\r\n    int N = sizeof(A) \/ sizeof(A[0]);\r\n    int M = sizeof(B) \/ sizeof(B[0]);\r\n    float median = findMedian(A, N, B, M);\r\n    printf(\"Median = %f&#92;n\", median);\r\n    return 0;\r\n}\r\n\r\n<\/pre>\r\n&nbsp;\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_16630 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_16630 a\"),jQuery(\"#tab-content_16630\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><\/p>\n<pre><code>Median = 10.000000<\/code><\/pre>\n<h2>Method 3 : Merging two sorted arrays using Binary Search<\/h2>\n<p>The given two arrays are sorted, so we can utilize the ability of Binary Search to divide the array and find the median. Median means the point at which the whole array is divided into two parts. Hence since the two arrays are not merged so to get the median we require merging which is costly. Hence instead of merging, we will use a modified binary search algorithm to efficiently find the median.<\/p>\n<h2>Method 3 : Algorithm to solve merging of two sorted arrays using Binary search<\/h2>\n<ol>\n<li>If we would have merged the two arrays, the median is the point that will divide the sorted merged array into two equal parts. So the actual median point in the merged array would have been (M+N+1)\/2;<\/li>\n<li>We divide A[] and B[] into two parts. We will find the mid value and divide the first array A[] into two parts and simultaneously choose only those elements from left of B[] array such that the sum of the count of elements in the left part of both A[] and B[] will result in the left part of the merged array. <\/li>\n<li>Now we have 4 variables indicating four values two from array A[] and two from array B[].<\/li>\n<li>leftA -&gt; Rightmost element in left part of A.<\/li>\n<li>leftb -&gt; Rightmost element in left part of B<\/li>\n<li>rightA -&gt; Leftmost element in right part of A<\/li>\n<li>rightB -&gt; Leftmost element in right part of B<\/li>\n<li>Hence to confirm that the partition was correct we have to check if leftA&lt;=rightB and leftB&lt;=rightA. This is the case when the sum of two parts of A and B results in the left part of the merged array.<\/li>\n<li>If the condition fails we have to find another midpoint in A and then left part in B[]. <\/li>\n<li>If we find leftA &gt; rightB. means we have to decrease the size of A\u2019s partition and shift to lesser value in A[]. <\/li>\n<li>So update the right pointer of to mid-1 else we will increase the left pointer to mid+1. <\/li>\n<li>Repeat the above steps with new partitions till we get the answers.<\/li>\n<li>If leftA \u2264 rightB and leftB \u2264 rightA, then we get the correct partition and our answer depends on the total size of the merged array (i.e. M+N). If (M+N) is even we take max(leftA, leftB) and min(rightA, rightB), add them and divide by 2 to get our answer, else we will just return the maximum of leftA and leftB.<\/li>\n<\/ol>\n<h3>Code implementation in C<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_16631 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_16631 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_16631 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_16631 .wpsm_nav-tabs > li.active > a, #tab_container_16631 .wpsm_nav-tabs > li.active > a:hover, #tab_container_16631 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_16631 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_16631 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_16631 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_16631 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_16631 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_16631 .wpsm_nav-tabs > li > a:hover , #tab_container_16631 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_16631 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_16631 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_16631 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_16631 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_16631 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_16631 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_16631 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_16631 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_16631 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_16631 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_16631 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_16631\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_16631\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_16631_1\" aria-controls=\"tabs_desc_16631_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_16631\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_16631_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\r\n#include &lt;limits.h&gt;\r\n\r\ndouble Median(int A[], int n, int B[], int m)\r\n{\r\n    if (n &gt; m)\r\n        return Median(B, m, A, n); \r\n    int start = 0;\r\n    int end = n;\r\n    int realmidinmergedarray = (n + m + 1) \/ 2;\r\n\r\n    while (start &lt;= end) {\r\n        int mid = (start + end) \/ 2;\r\n        int leftAsize = mid;\r\n        int leftBsize = realmidinmergedarray - mid;\r\n        int leftA = (leftAsize &gt; 0) ? A[leftAsize - 1] : INT_MIN; \/\/ checking overflow of indices\r\n        int leftB = (leftBsize &gt; 0) ? B[leftBsize - 1] : INT_MIN;\r\n        int rightA = (leftAsize &lt; n) ? A[leftAsize] : INT_MAX;\r\n        int rightB = (leftBsize &lt; m) ? B[leftBsize] : INT_MAX;\r\n\r\n        \/\/ if correct partition is done\r\n        if (leftA &lt;= rightB &amp;&amp; leftB &lt;= rightA) {\r\n            if ((m + n) % 2 == 0)\r\n                return (double)( (leftA &gt; leftB) ? leftA : leftB ) + ( (rightA &lt; rightB) ? rightA : rightB ) \/ 2.0;\r\n            return (double)( (leftA &gt; leftB) ? leftA : leftB );\r\n        }\r\n        else if (leftA &gt; rightB) {\r\n            end = mid - 1;\r\n        }\r\n        else {\r\n            start = mid + 1;\r\n        }\r\n    }\r\n    return 0.0;\r\n}\r\nint main()\r\n{\r\n    int arr1[] = { -5, 3, 6, 12, 15 };\r\n    int arr2[] = { -12, -10, -6, -3, 4, 10 };\r\n    int n = sizeof(arr1) \/ sizeof(arr1[0]);\r\n    int m = sizeof(arr2) \/ sizeof(arr2[0]);\r\n\r\n    printf(\"Median of the two arrays is: %.1f&#92;n\", Median(arr1, n, arr2, m));\r\n\r\n    return 0;\r\n}\r\n<\/pre>\r\n&nbsp;\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_16631 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_16631 a\"),jQuery(\"#tab-content_16631\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><\/p>\n<pre><code>Median of the two arrays is: 4.0<\/code><\/pre>\n<h2>Method 4 : Merging two sorted arrays using Priority Queue<\/h2>\n<p>In this Approach we have used Priority Queue (min Heap) to find out the median. The Idea is simple Just push the elements into a single Priority Queue from both arrays . Now we have to find median from priority queue by performing a simple traversal through it upto median.<\/p>\n<h3>Algorithm to solve merging of two sorted arrays using Priority Queue<\/h3>\n<ol>\n<li>Start the <code>Median<\/code> function with the two input vectors <code>A<\/code> and <code>B<\/code>.<\/li>\n<li>Create a priority queue (min heap) named <code>pq<\/code> and push all elements from vectors <code>A<\/code> and <code>B<\/code> into <code>pq<\/code>.<\/li>\n<li>Calculate the total number of elements (<code>n + m<\/code>) and store it in the variable <code>check<\/code>.<\/li>\n<li>Initialize variables <code>count<\/code> and <code>mid1<\/code> to -1.<\/li>\n<li>Iterate while <code>count<\/code> is less than <code>check\/2<\/code>.<br \/>\nIncrement <code>count<\/code> by 1.<br \/>\nStore the top element from <code>pq<\/code> in <code>mid1<\/code> if <code>count<\/code> is equal to <code>(check\/2)-1<\/code>.<br \/>\nPop the top element from <code>pq<\/code>.<\/li>\n<li>If the total number of elements is odd (<code>check % 2 != 0<\/code>), return the top element from <code>pq<\/code> as the median.<\/li>\n<li>If the total number of elements is even (<code>check % 2 == 0<\/code>), calculate the median by taking the average of <code>mid1<\/code> and the top element from <code>pq<\/code>.<\/li>\n<li>Return the calculated median.<\/li>\n<\/ol>\n<h3>Code implementation in C<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_16632 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_16632 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_16632 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_16632 .wpsm_nav-tabs > li.active > a, #tab_container_16632 .wpsm_nav-tabs > li.active > a:hover, #tab_container_16632 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_16632 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_16632 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_16632 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_16632 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_16632 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_16632 .wpsm_nav-tabs > li > a:hover , #tab_container_16632 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_16632 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_16632 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_16632 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_16632 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_16632 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_16632 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_16632 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_16632 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_16632 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_16632 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_16632 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_16632\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_16632\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_16632_1\" aria-controls=\"tabs_desc_16632_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_16632\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_16632_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\ndouble Median(int A[], int n, int B[], int m)\r\n{\r\n    int i;\r\n    priority_queue&lt;int, vector&lt;int&gt;, greater&lt;int&gt;&gt; pq;\r\n    for (i = 0; i &lt; n; i++)\r\n        pq.push(A[i]);\r\n\r\n    for (i = 0; i &lt; m; i++)\r\n        pq.push(B[i]);\r\n\r\n    int check = n + m;\r\n    double count = -1;\r\n    double mid1, mid2;\r\n\r\n    while (!pq.empty())\r\n    {\r\n        count++;\r\n        if (check % 2 != 0 &amp;&amp; count == check \/ 2)\r\n        {\r\n            double ans = pq.top();\r\n            return ans;\r\n        }\r\n        if (check % 2 == 0 &amp;&amp; count == (check \/ 2) - 1)\r\n            mid1 = pq.top();\r\n\r\n        if (check % 2 == 0 &amp;&amp; count == check \/ 2)\r\n        {\r\n            mid2 = pq.top();\r\n            double ans = (mid1 + mid2) \/ 2;\r\n            return ans;\r\n        }\r\n\r\n        pq.pop();\r\n    }\r\n\r\n    return 0.0;\r\n}\r\nint main()\r\n{\r\n    int arr1[] = {-2, 3, 4, 5};\r\n    int arr2[] = {-4, -1, 7, 8, 9};\r\n    int n = sizeof(arr1) \/ sizeof(arr1[0]);\r\n    int m = sizeof(arr2) \/ sizeof(arr2[0]);\r\n\r\n    printf(\"Median of the two arrays are&#92;n\");\r\n    printf(\"%f&#92;n\", Median(arr1, n, arr2, m));\r\n    return 0;\r\n}<\/pre>\r\n&nbsp;\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_16632 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_16632 a\"),jQuery(\"#tab-content_16632\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><\/p>\n<pre><code>Median of the two arrays are\n4.000000<\/code><\/pre>\n<p><strong>Conclusion<\/strong><br \/>\nWe have briefly discussed how to find the median of two sorted arrays of different sizes in C with a few examples. Then we have briefly discussed the various methods along with their algorithm, explaining the ways of how to solve this problem.<\/p>\n<h2>Frequently Asked Questions (FAQs)<\/h2>\n<p><strong>Q1. How can I find the median of two sorted arrays of different sizes in C?<\/strong><br \/>\nThere are multiple approaches to find the median of two sorted arrays in C. One common approach is to merge the arrays into a third array and then find the median based on the size of the merged array. Another approach involves using recursion to divide the arrays and find the median. Additionally, binary search and priority queues can also be used to find the median. The article provides code implementations and explanations for each of these approaches.<\/p>\n<p><strong>Q2.How does the merging of two sorted arrays in a third array help in finding the median?<\/strong><br \/>\nBy merging the two sorted arrays into a third array, you obtain a sorted array containing all the elements from both arrays. This sorted array allows you to easily determine the median. If the length of the merged array is odd, the median is the element at the (length\/2)th index. If the length is even, the median is the average of the elements at the (length\/2)th and ((length\/2) &#8211; 1)th indices.<\/p>\n<p><strong>Q3.What is the algorithm for merging two sorted arrays into a third array and finding the median?<\/strong><br \/>\nThe algorithm for merging two sorted arrays into a third array and finding the median involves the following steps:<\/p>\n<ol>\n<li>Merge the two arrays into a third array.<\/li>\n<li>Sort the third array.<\/li>\n<li>If the length of the third array is even, calculate the median as the average of the elements at the (length\/2)th and ((length\/2) &#8211; 1)th indices.<\/li>\n<li>If the length of the third array is odd, the median is the element at the (length\/2)th index.<\/li>\n<\/ol>\n<p><strong>Q4.How can I merge two sorted arrays using recursion to find the median?<\/strong><br \/>\nTo merge two sorted arrays using recursion, you can create a recursive function that takes both arrays and their sizes as parameters. The function handles base cases for arrays with sizes less than 2. It then finds the middle elements of both arrays and compares them. Based on the comparison, it recursively divides the arrays into smaller parts until it finds the correct partition. The function considers the size of the arrays and selects the median accordingly.<\/p>\n<p><strong>Q5.How does the binary search approach help in merging two sorted arrays and finding the median?<\/strong><br \/>\nThe binary search approach for merging two sorted arrays and finding the median utilizes the concept of partitioning the arrays. By choosing a mid-point in one array and selecting elements from the other array based on their positions relative to the mid-point, you can efficiently find the correct partition. The binary search technique helps in identifying the correct midpoint and adjusting the partition until the median is found.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The aim is to determine the median of two sorted arrays, a[] and b[], where N is the number of items in the first array and M is the number of elements in the second array. In this post, we will look at numerous techniques to solve this problem. Example 1: Input format: arr1 = [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-16629","post","type-post","status-publish","format-standard","hentry","category-c-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Median of two sorted arrays of different size in C<\/title>\n<meta name=\"description\" content=\"Median of two sorted arrays of different size in C can be solved by merging the arrays into a third array and then find the median\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Median of two sorted arrays of different size in C\" \/>\n<meta property=\"og:description\" content=\"Median of two sorted arrays of different size in C can be solved by merging the arrays into a third array and then find the median\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-01T06:35:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-01T07:18:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Median of two Sorted Arrays of Different Size in C\",\"datePublished\":\"2023-06-01T06:35:12+00:00\",\"dateModified\":\"2023-06-01T07:18:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/\"},\"wordCount\":1717,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg\",\"articleSection\":[\"C Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/\",\"name\":\"Median of two sorted arrays of different size in C\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg\",\"datePublished\":\"2023-06-01T06:35:12+00:00\",\"dateModified\":\"2023-06-01T07:18:53+00:00\",\"description\":\"Median of two sorted arrays of different size in C can be solved by merging the arrays into a third array and then find the median\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C Programming\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/c-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Median of two Sorted Arrays of Different Size in C\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Median of two sorted arrays of different size in C","description":"Median of two sorted arrays of different size in C can be solved by merging the arrays into a third array and then find the median","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:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/","og_locale":"en_US","og_type":"article","og_title":"Median of two sorted arrays of different size in C","og_description":"Median of two sorted arrays of different size in C can be solved by merging the arrays into a third array and then find the median","og_url":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2023-06-01T06:35:12+00:00","article_modified_time":"2023-06-01T07:18:53+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Median of two Sorted Arrays of Different Size in C","datePublished":"2023-06-01T06:35:12+00:00","dateModified":"2023-06-01T07:18:53+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/"},"wordCount":1717,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg","articleSection":["C Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/","url":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/","name":"Median of two sorted arrays of different size in C","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg","datePublished":"2023-06-01T06:35:12+00:00","dateModified":"2023-06-01T07:18:53+00:00","description":"Median of two sorted arrays of different size in C can be solved by merging the arrays into a third array and then find the median","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1685598291649-Median%20of%20two%20sorted%20arrays%20of%20different%20size%20in%20C.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/median-of-two-sorted-arrays-of-different-size-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"C Programming","item":"https:\/\/prepbytes.com\/blog\/category\/c-programming\/"},{"@type":"ListItem","position":3,"name":"Median of two Sorted Arrays of Different Size in C"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/16629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=16629"}],"version-history":[{"count":2,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/16629\/revisions"}],"predecessor-version":[{"id":16642,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/16629\/revisions\/16642"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=16629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=16629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=16629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}