|
51 | 51 | - [Quick Sort](#quick-sort)
|
52 | 52 | - [Why Quick sort is used in Array and Merge Sort in Linked List?](#why-quick-sort-is-used-in-array-and-merge-sort-in-linked-list)
|
53 | 53 | - [Mathematics & Stats You should know](#mathematics--stats-you-should-know)
|
| 54 | + - [XOR operator](#xor-operator) |
| 55 | + - [Different Numbers can be solved by XOR](#different-numbers-can-be-solved-by-xor) |
54 | 56 | - [How to initialize array of size n?](#how-to-initialize-array-of-size-n)
|
55 | 57 | - [How many zeros in 1 Billion](#how-many-zeros-in-1-billion)
|
56 | 58 | - [How many zeros in 1 Million](#how-many-zeros-in-1-million)
|
@@ -660,8 +662,33 @@ When Browser's are not using Merge sort they most of the time use Quick sort var
|
660 | 662 |
|
661 | 663 | In Quick sort we do not create auxiliary arrays. Therefore, it is good choice for Array to use quick sort. However in merge sort we create 2 auxiliary arrays. Therefore, linked list is a good choice.
|
662 | 664 |
|
| 665 | + |
| 666 | + |
663 | 667 | ## Mathematics & Stats You should know
|
664 | 668 |
|
| 669 | + |
| 670 | +### XOR operator |
| 671 | + |
| 672 | +XOR represents the inequality function, i.e., the output is true if the inputs are not alike otherwise the output is false. A way to remember XOR is "must have one or the other but not both". XOR can also be viewed as addition modulo 2. |
| 673 | + |
| 674 | +#### Different Numbers can be solved by XOR |
| 675 | + |
| 676 | +Find how many different numbers in the array. |
| 677 | + |
| 678 | +Input =[3, 5, 6, 3, 3 , 9, 5] |
| 679 | + |
| 680 | +answer = 4 |
| 681 | + |
| 682 | +There are 4 values 3,5, 6,9. |
| 683 | + |
| 684 | +```js |
| 685 | +x =0; |
| 686 | +array.forEach(num=> x ^= num); |
| 687 | +return x; |
| 688 | +``` |
| 689 | + |
| 690 | +`^=` [XOR assignment operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR). |
| 691 | + |
665 | 692 | ### How to initialize array of size n?
|
666 | 693 |
|
667 | 694 | Example create an array containing numbers from 0 to 9.
|
|
0 commit comments