+ 2

Need urgent help !!!Median of two sorted arrays in logarithmic time .Pls tell how to correct this runtime error here 🥺

https://code.sololearn.com/cWFqz09fjFfE/?ref=app It's showing runtime error (heap overflow ) in coding platform like leetcode But gives correct output . Logic --- take some element from array a and remaining element from array b so that if we imagined two sorted arrays as one sorted arrays then that one sorted imagined array must have same no of elements before median including itself .

7th May 2022, 8:47 AM
Srishti Jaiswal
Srishti Jaiswal - avatar
15 Answers
0
I think, you need Instead of #include<bits/stdc++.h> use only needed Libraries.. And initialize variables na, nb before out of loop
7th May 2022, 9:13 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 na,nb, depends on mid index of array named a in binary search that will change within loop each time ACC to mid .They can't be placed outside of loop
7th May 2022, 9:18 AM
Srishti Jaiswal
Srishti Jaiswal - avatar
0
Srishti Jaiswal I mean initialization, not assignment. Like int na, nb; while(...) { ... } Am not sure it works but inside loop, it will create new variable in each iteration. But out side loop will be created only once..
7th May 2022, 9:52 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 corrected but same runtime error
7th May 2022, 9:55 AM
Srishti Jaiswal
Srishti Jaiswal - avatar
0
Did you changed header files? If you are sure about heap overfolw then try : Not to use recurision. Instead call in main like if(n<m) meadian(b, a) else meadian(a, b) ; Try to reduce other variables use... like directly print cout<<meadian(a, b)
7th May 2022, 10:40 AM
Jayakrishna 🇮🇳
0
There isn't any problem in header file in bits/.....header file vector 's header file is already included Jayakrishna🇮🇳
7th May 2022, 11:27 AM
Srishti Jaiswal
Srishti Jaiswal - avatar
0
There isn't any problem in using recursion for only one time
7th May 2022, 11:29 AM
Srishti Jaiswal
Srishti Jaiswal - avatar
0
Heap overflow occurs when we do something like this vector_name[index]=invalid means we are accessing content of array which does not exist
7th May 2022, 11:30 AM
Srishti Jaiswal
Srishti Jaiswal - avatar
0
bits/ file includes all header files in c++ so when you run program it includes in the temp file so it unnecessary inclusions will make program run slover due to large memory.. So It is just needed to include for practices.. Recursion also make more pushes of data into stacks.. So larger recursion will take more time.. As you not using inner recursion call. Oh this may cause program if n<m actually, you are not using this return value. Think here again logic.. Each call returns a value, which one you are printing..? Heap overfolw means it asking more n Memory than available Heap memory.. Heap memory is used for temporary memory utilization... Invalid access means null value access error. It because may be your 'a' vector have do data.. Hope this helps to solve it..
7th May 2022, 11:51 AM
Jayakrishna 🇮🇳
0
vector<int>a={1,2,3,4,5}; vector<int>b={1,2}; Jayakrishna🇮🇳 at this input though if condition in which written m+n%2!=0, is satisfying and immediately control should return value but control is still not returning value ,it is still moving in loop . But why ?????🤔🤔🤔🤔🤔
7th May 2022, 1:41 PM
Srishti Jaiswal
Srishti Jaiswal - avatar
0
Srishti Jaiswal It returning.. But you have recursion function, and it's working next.. That's what I mentioned about you are "not using inner function call".
7th May 2022, 1:51 PM
Jayakrishna 🇮🇳
0
Hey guys need help please, I keep an syntax error msg in the “else” statement and not sure what is going. What do i do to fix it?
7th May 2022, 2:34 PM
Shingy
0
Shingy you have to tell at which point syntax error and share link of your code here
7th May 2022, 2:37 PM
Srishti Jaiswal
Srishti Jaiswal - avatar
0
Jayakrishna🇮🇳 Thanks there will be return work where I had called function recursively
7th May 2022, 6:28 PM
Srishti Jaiswal
Srishti Jaiswal - avatar
0
Srishti Jaiswal Yes. That works fine.. You're welcome...
7th May 2022, 6:37 PM
Jayakrishna 🇮🇳