Skip to content

Commit

Permalink
Merge pull request #330 from TesseractCoding/master
Browse files Browse the repository at this point in the history
mpr
  • Loading branch information
JayantGoel001 authored May 22, 2021
2 parents baf3751 + 46b15b0 commit 05ad95a
Show file tree
Hide file tree
Showing 32 changed files with 2,176 additions and 119 deletions.
18 changes: 18 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,24 @@
"contributions": [
"code"
]
},
{
"login": "anshika272",
"name": "Anshika Dubey",
"avatar_url": "https://avatars.githubusercontent.com/u/61225173?v=4",
"profile": "https://devpost.com/anshika15-dubey?ref_content=user-portfolio&ref_feature=portfolio&ref_medium=global-nav",
"contributions": [
"code"
]
},
{
"login": "mehak2323",
"name": "Mehak",
"avatar_url": "https://avatars.githubusercontent.com/u/76546415?v=4",
"profile": "https://github.com/mehak2323",
"contributions": [
"code"
]
}
],
"repoType": "github",
Expand Down
42 changes: 23 additions & 19 deletions C-Plus-Plus/Bit--Manipulation/Brian_Kernighan's_Algorithm.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
//Brian Kernighan’s Algorithm: To get the number of set bits
//For eg :- 5 can be represented as 101 number of set bits are 2
//Time Complexity: O(logn)
//Space Complexity: O(1)

/*Sample Input:
Example 1:-
Enter number
5
Example 2:-
Enter number
987
Sample Output:
Example 1:- 2
Example 2:- 8
/*
Brian Kernighan’s Algorithm: To get the number of set bits
For eg :- 5 can be represented as 101 number of set bits are 2
*/

#include<bits/stdc++.h>
using namespace std;
int main()
Expand All @@ -28,7 +16,23 @@ int main()
c++;
}
cout<< c;



}

/*
Time Complexity: O(logn)
Space Complexity: O(1)
*/

/*Sample Input:
Example 1:-
Enter number
5
Example 2:-
Enter number
987
Sample Output:
Example 1:- 2
Example 2:- 8
*/

58 changes: 31 additions & 27 deletions C-Plus-Plus/Bit--Manipulation/Check_kth_bit_is_set_or_not.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
//Check if the kth bit is set or not
//Time Complexity: O(1)
//Space Complexity: O(1)

//Sample Input:
/*Example 1:-
Enter number
8
Enter bit no
4
Example 2:-
Enter number
50
Enter bit no
4
Sample Output:
Example 1:-
Using Left Shift operator Yes
Using Right Shift operator Yes
Example 2:-
Using Left Shift operator No
Using Right Shift operator No
*/

#include<bits/stdc++.h>
using namespace std;
Expand All @@ -47,6 +22,35 @@ int main()
else
cout<<"No"<<"\n";



}

/*
Time Complexity: O(1)
Space Complexity: O(1)
*/

/*
Test cases:
Example 1:-
Enter number
8
Enter bit no
4
Example 2:-
Enter number
50
Enter bit no
4
Sample Output:
Example 1:-
Using Left Shift operator Yes
Using Right Shift operator Yes
Example 2:-
Using Left Shift operator No
Using Right Shift operator No
*/

38 changes: 20 additions & 18 deletions C-Plus-Plus/Bit--Manipulation/Count_no_of_set_bits.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
//Count No of Set Bits
//Simple Method
//Time Complexity: O(logn)
//Space Complexity: O(1)

/*Sample Input:
Example 1:-
Enter number
5
Example 2:-
Enter number
987
Sample Output:
Example 1:- 2
Example 2:- 8
*/
#include<bits/stdc++.h>
using namespace std;
int main()
Expand All @@ -28,7 +13,24 @@ int main()
res = res + (n & 1);
n=n>>1;
}
cout<<res;


cout<<res;
}

/*
Time Complexity: O(logn)
Space Complexity: O(1)
*/

/*
Sample Input:
Example 1:-
Enter number
5
Example 2:-
Enter number
987
Sample Output:
Example 1:- 2
Example 2:- 8
*/
49 changes: 29 additions & 20 deletions C-Plus-Plus/Bit--Manipulation/One_odd_occuring.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
// Only one odd ocurring number
//Using Xor Operation as Xor of two numbers gives zero
//Time Complexity: O(n)
//Space Complexity: O(1)

/*Sample Input:
Example 1:-
Enter number of elements
5
1 1 2 3 3
Example 2:-
Enter number of elements
7
71 4 9 71 9 7 7
Sample Output:
Example 1:- 2
Example 2:- 4
/*
Only one odd ocurring number
Using Xor Operation as Xor of two numbers gives zero
*/

#include<bits/stdc++.h>
using namespace std;
//to find missing number xor the array elements
// xor all elements from 1 to N
// Xor both the above two steps
int main()
{
int n;
Expand All @@ -38,6 +28,25 @@ int main()
cout<<res<<endl;

}
//to find missing number xor the array elements
// xor all elements from 1 to N
// Xor both the above two steps


/*
Time Complexity: O(n)
Space Complexity: O(1)
*/

/*
Sample Input:
Example 1:-
Enter number of elements
5
1 1 2 3 3
Example 2:-
Enter number of elements
7
71 4 9 71 9 7 7
Sample Output:
Example 1:- 2
Example 2:- 4
*/

6 changes: 6 additions & 0 deletions C-Plus-Plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
- [Find all unique prime factor of any number n](cp/Unique_prime_factors.cpp)
- [Find the maximum number formed from 2-digit numbers in an array](cp/maxNumber.cpp)
- [Plus One Problem](cp/Plus_One.cpp)
- [Maximum Pairwise Product In Array](cp/maximum_pairwise_product.cpp)
- [Minimum indexed character](cp/Minimum_indexed_character.cpp)
- [Power Of Numbers](cp/Power_of_numbers.cpp)
- [Geek-onacci Number](cp/Geek-onacci_Number.cpp)
Expand Down Expand Up @@ -174,6 +175,7 @@
- [Strange Hotel](cp/strange_hotel.cpp)
- [Find subtrees with total nodes sum equal to x](cp/total_subtrees.cpp)
- [Remove cycle in a tree to form a linked list](cp/remove_cycle.cpp)
- [Largest BST in binary tree](cp/largest_bst_in_btree.cpp)
- [Total Pairs Chosen](cp/total_pairs_chosen.cpp)

## Data Structures
Expand Down Expand Up @@ -260,6 +262,7 @@
- [Check if two given trees are Quasi Isomorphic or not](ds/Quasi_Isomorphic_Binary_Trees.cpp)
- [Build a Balanced BST with given vector of values](ds/Balanced_BST_From_a_vector_of_values.cpp)
- [Given a BST check if it is AVL Tree or not](ds/AVL_Tree_or_not.cpp)
- [Next Larger Element-tree](ds/Next_Larger_Element-tree_using_CPP.cpp)
- [Swapping Node of Linked List](ds/Sawpping_Nodes_of_Linked_list-Using_CPP.cpp)
- [Auto Complete - Using Trie](ds/Auto_complete.cpp)
- [Append Last N To First](ds/Append_Last_N_To_First.cpp)
Expand Down Expand Up @@ -328,6 +331,8 @@
- [3 Cycle](graphs/3Cycle.cpp)
- [Iterative procedure for dfs traversal](graphs/Iterative_dfs.cpp)
- [Center of Star Graph](graphs/Center_of_Star_Graph.cpp)
- [Subtree size of each node](graphs/subtree_size.cpp)


## Searching

Expand Down Expand Up @@ -538,6 +543,7 @@ _add list here_
- [Interleaving strings](dp/Interleaving_strings.cpp)
- [Minimum Insertion Steps to make string palindrome](dp/Minimum_Insertion_Steps_to_make_Palindrome.cpp)
- [Longest Bitonic Subsequence](dp/Longest_bitonic_subsequence.cpp)
- [Rod Cutting Problem](dp/Rod_cutting_problem.cpp)

## Bit - Manipulation

Expand Down
Loading

0 comments on commit 05ad95a

Please sign in to comment.