Find missing number in an array(using summation and XOR operation)

Find the missing number in the array which contains a series of consecutive numbers in range from 1 to n. Use summation formula for natural numbers 1 to n. We can also use the XOR operation.

Пікірлер: 59

  • @LarryRuane
    @LarryRuane7 жыл бұрын

    This is great, thanks! Another advantage of XOR is that there no possibility of overflow, as there is with summation. (One very minor mistake is at 4:55 you wrote "0 XOR a = 0".)

  • @nasirshah5744
    @nasirshah57445 жыл бұрын

    4:37 best way to understand XOR of n variables is that for odd number of ones(a in your case) the result is one(or a ) else it is 0. If numbers are not sorted and duplicate entries are also there. How we can find the missing number in linear time and constant space ?

  • @naboulsikhalid7763
    @naboulsikhalid77634 ай бұрын

    always great and concise. thank you. I would like to see the algorithm implemented in c code.

  • @lodashnotebook5390
    @lodashnotebook53905 жыл бұрын

    Exactly what I needed. Thanks!

  • @abhijayrajvansh
    @abhijayrajvansh3 жыл бұрын

    This is great video, exactly what i needed. Indian teachers are ❤️

  • @indianmusicsongssaregama1406
    @indianmusicsongssaregama14066 жыл бұрын

    If we have scanner class then how to get sum of number.

  • @manishswarnakar6993
    @manishswarnakar69936 жыл бұрын

    How to find multiple missing number in array ? like an array is= {4,3,5} so the missing numbers is = {1,6}

  • @Blingblingblingling
    @Blingblingblingling6 жыл бұрын

    nice video! problem statement can be made a bit clearer: "find missing number in unsorted array", since for sorted array as in example input, it's too easy, if a[i+1] != a[i]+1 then return a[i]+1

  • @sanapalavenkatesh5273
    @sanapalavenkatesh52733 жыл бұрын

    you are put the add right time by the way thanks for nice explanation .............

  • @mangeshkumargabhane4671
    @mangeshkumargabhane46716 жыл бұрын

    Very clear, I am looking for implementation of algorithm using any programming language. Please help if possible, Thank you very much for good algorithm videos.

  • @PradeepSingh-vm1gl
    @PradeepSingh-vm1gl3 жыл бұрын

    Love you brother. You explained so nicely. Thank you so much.

  • @sakshimittal1166
    @sakshimittal1166 Жыл бұрын

    That makes a lot of sense. Thank you sir!

  • @skkar2k2
    @skkar2k24 жыл бұрын

    In video at (4:56), in XOR table 0 ^ a = a, while explaining 0 ^ a = 0. But I liked the explanation. It's too nicely explained.

  • @mustapharaimilawal8053
    @mustapharaimilawal80535 жыл бұрын

    Thank you so much for making this video, awesome.

  • @aaatatataapaatuuuu987
    @aaatatataapaatuuuu9875 жыл бұрын

    Why we did xor of given numbers within same array .we can find the xor of given array and expected array. Can anyone explain me pls

  • @tapanjeetroy8266
    @tapanjeetroy82665 жыл бұрын

    Thanks a lot sir.. You are doing a great job

  • @lojian
    @lojian7 жыл бұрын

    Very clear. I have a question, for your example case, could we just search from 1, to 2, to 3, until 5, when we look at 3,we know next one should be 4, and but it is actually 5; --- this assumes that array is sorted. will XOR algo work even when array is not sorted?

  • @vivekanandkhyade

    @vivekanandkhyade

    7 жыл бұрын

    yes XOR will work on unsorted array too..

  • @sivaganesh4489

    @sivaganesh4489

    4 жыл бұрын

    Even 1st approach also work for unsorted array but it must be sequence for both methods

  • @maheshwars.j6195
    @maheshwars.j61955 жыл бұрын

    What if multiple numbers are missing

  • @ibrahimkhaleel2822
    @ibrahimkhaleel2822 Жыл бұрын

    Sir, I have a doubt how can i ask you❓️ Pls rply

  • @rohitdas6005
    @rohitdas60055 жыл бұрын

    How to find multiple missing numbers in array?

  • @nagesh007
    @nagesh0075 ай бұрын

    Awesome Sir

  • @Copernicus_Song
    @Copernicus_Song4 жыл бұрын

    very good explain, thx a lot!!

  • @karan6551
    @karan65513 жыл бұрын

    Love u bro.. awesome ❤️❤️❤️

  • @durgabhavani9955
    @durgabhavani99554 жыл бұрын

    Sir ,can you provide how to find third largest element in an array logic

  • @harshivam

    @harshivam

    Жыл бұрын

    just store max and second max in a variable and like how you find max just use a if statement where you check the third ma != max1,max2

  • @kirtivardhan80
    @kirtivardhan806 жыл бұрын

    Asymptotically both gives O(n) But logically 2nd one will have to iterate 2 times. So first one must be efficient, logically.

  • @darshank3012

    @darshank3012

    3 жыл бұрын

    If the n value is high, the summation might cross the integer's max value limit, then the first approach might not work well.

  • @mohamedmusaraf675
    @mohamedmusaraf6754 жыл бұрын

    Superb sir!!!!

  • @salmankhatik4985
    @salmankhatik49852 жыл бұрын

    but how to code this in xor

  • @odalyspaz959
    @odalyspaz9597 жыл бұрын

    Thanks for the explanation :)

  • @vivekanandkhyade

    @vivekanandkhyade

    7 жыл бұрын

    welcome Odalys..!

  • @adarshnair9846
    @adarshnair98466 жыл бұрын

    0 XOR a = a. U wrote it as 0 XOR a = 0 by mistake right?

  • @fuadhasan0362
    @fuadhasan03626 жыл бұрын

    thank you sir...

  • @vickyjain3403
    @vickyjain34035 жыл бұрын

    sir, if you take 1 instead of ' a ' it is better for understand to us.

  • @kumarvivek02
    @kumarvivek026 жыл бұрын

    Aren't you assuming here that your array is sorted? What if it is not?

  • @arindam_.

    @arindam_.

    5 жыл бұрын

    So the assumption is that the array is sorted. If not, sort the array first and then start your operation.

  • @NoorAli-uh4uq
    @NoorAli-uh4uq4 жыл бұрын

    Thank you a-lot.

  • @akashgowda6923
    @akashgowda69234 жыл бұрын

    Explanation s super but write full java code we can understand better

  • @techdiscussion3617
    @techdiscussion36176 жыл бұрын

    thanks sir

  • @cengizandak4241
    @cengizandak42415 жыл бұрын

    The quickest way is the binary search which is logn

  • @vikrammehta5874
    @vikrammehta58744 жыл бұрын

    I know this method Any other method??

  • @sachiiinnnn9734
    @sachiiinnnn97343 жыл бұрын

    thanks

  • @santhosh........
    @santhosh........5 жыл бұрын

    Super sir

  • @columbiars
    @columbiars6 жыл бұрын

    I don't see why the second solution is better than the first one in terms of time complexity.

  • @ramakantasamal7482

    @ramakantasamal7482

    6 жыл бұрын

    Agree on time complexity it does not help much but 1st one could cause overflow while summing

  • @AnkitRaj-jn8ew
    @AnkitRaj-jn8ew4 жыл бұрын

    Both logic has O(n) time complexity. Why not just traverse and check if a[i] != a[i-1] + 1 from (i = 1 to n-1). When the condition is true, a[i-1] is the answer. This approach is far easier and has O(n) time complexity as well. We can also use binary search and get O(log n ) time complexity.

  • @jaybhatt6775

    @jaybhatt6775

    3 жыл бұрын

    binary search has higher space complexity

  • @AnkitRaj-jn8ew

    @AnkitRaj-jn8ew

    3 жыл бұрын

    @@jaybhatt6775 Not necessarily. You can use an iterative approach for binary search to avoid stack trace. It won't need any extra space and will be more efficient than the 2 approaches discussed here.

  • @SonuGupta-wj6dg
    @SonuGupta-wj6dg2 жыл бұрын

    nice

  • @nileshandakshat3713
    @nileshandakshat37134 жыл бұрын

    some problems in this video

  • @nileshandakshat3713
    @nileshandakshat37134 жыл бұрын

    give me reply

  • @shubhamsunny6024
    @shubhamsunny60245 жыл бұрын

    (n+1)*(n+2)/2 is actual formula, let say we have 7 is absent from range 1-9, with your formula (n*n+1)/2) 36 is coming and my array sum is 38 ,now result is 2, which is wrong.

  • @getItToDeepak

    @getItToDeepak

    5 жыл бұрын

    n = 9, so 9*10/2 = 45, sum of numbers = 38. Now 45-38 = 7. You got the answer

  • @bryand7958

    @bryand7958

    5 жыл бұрын

    (n * n + 1) /2 is not the formula n * (n + 1) / 2 ==> (n^2 + n)/2

  • @anerdwitdacamera204
    @anerdwitdacamera2046 жыл бұрын

    1 2 3 4…… 5 6 7 8 Ms in my bank account

  • @kumargourav4976
    @kumargourav49766 жыл бұрын

    thank you sir,