+ 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 .
15 Réponses
0
I think, you need
Instead of #include<bits/stdc++.h>
use only needed Libraries..
And initialize variables na, nb before out of loop
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
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..
0
Jayakrishna🇮🇳 corrected but same runtime error
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)
0
There isn't any problem in header file in bits/.....header file vector 's header file is already included Jayakrishna🇮🇳
0
There isn't any problem in using recursion for only one time
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
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..
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 ?????🤔🤔🤔🤔🤔
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".
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?
0
Shingy you have to tell at which point syntax error and share link of your code here
0
Jayakrishna🇮🇳 Thanks there will be return work where I had called function recursively
0
Srishti Jaiswal Yes. That works fine..
You're welcome...