Skip to content

Commit dd7b12f

Browse files
committed
bitAlgo:Checking even or odd
1 parent 5101265 commit dd7b12f

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Diff for: README.md

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The solutions are easy to understand and complete.
77
* [Searching](#searching)
88
* [Sorting](#sorting)
99
* [Arrays](#arrays)
10+
* [Hashing](#hashing)
1011
* [Stacks](#stacks)
1112
* [Bit Algorithms](#bitAlgo)
1213
* [Mathematics](#maths)
@@ -98,6 +99,13 @@ The solutions are easy to understand and complete.
9899
35. [Find the median of two sorted array of equal size](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/arrays/MedianOf2SortedArrays.rb)
99100
36. [Given a 2D array,print its all elements in spiral order](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/arrays/PrintMatrixInSpiralOrder.rb)
100101

102+
<a name="hashing"/>
103+
### Hashing ###
104+
105+
1. [Find pair in array with sum equal to given value(Approach 1)](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/arrays/ChekPairWithGivenSum.rb)
106+
2. [Find pair in array with difference equal to given value(Approach 2)](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/arrays/ChekPairWithGivenDiff.rb)
107+
3. [Sort a given array by frequency of elements](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/arrays/SortArrayByFrequency.rb)
108+
101109
<a name="stacks"/>
102110
### Stacks ###
103111

@@ -107,6 +115,8 @@ The solutions are easy to understand and complete.
107115
### Bit Algorithms ###
108116

109117
1. [Check if a given number is power of 2 or not](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/bitAlgorithms/CheckForPowerOfTwo.rb)
118+
2. [Check if a given number is even or odd](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/bitAlgorithms/CheckIfEvenOrOdd.rb)
119+
3. [Find missing number in array(Approach 2)](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/arrays/FindMissingNumber.rb)
110120

111121
<a name="maths"/>
112122
### Mathematics ###

Diff for: arrays/TripletWithGivenSum.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Given an array and a value, find if there is a triplet in array whose sum is equal to the given value.
1+
#Given an array and a value, find if there is a triplet in array whose sum is equal to the given value.
22
#Time-complexity: O(n^2),Auxiliary-space:O(1)
33
#Algorithm:Sort,fix element then search in the array using two pointers left and right
44

Diff for: bitAlgorithms/CheckIFEvenOrOdd.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Given a number,check if it is even or odd using bit operations.
2+
#Algorithm: let num be x
3+
#find x&1 ,if result is 0 then even else odd.
4+
#The Least significant bit of odd number is always 1 and even is always 0,hence x&1 will be 0 if even else odd.
5+
6+
def check_evenOdd(x)
7+
if x&1==0
8+
print "#{x} is even"
9+
else
10+
print "#{x} is odd"
11+
end
12+
end

0 commit comments

Comments
 (0)