Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitwise Algorithm and Linear Search updated #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions algorithms/bit manipulation/twice_unique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def twice_unique(arr:list) :
unique = 0
for i in arr:
unique ^= i
return unique
if __name__=="__main__":
array = list(map(int,input().split()))
#sample input
# 1 2 2 3 4 4 3
element = twice_unique(array)
print(f"Unique element in the array {array} is {element}")
11 changes: 11 additions & 0 deletions algorithms/bit manipulation/xor_swap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def swap(a:int,b:int) -> list :
a=a^b
b=b^a
a=a^b
return [a,b]

if __name__=="__main__":
a=int(input("Enter Number 1 : "))
b = int(input("Enter Number 2 : "))
AfterSwap= swap(a,b)
print(f"After Swap : {AfterSwap[0],AfterSwap[1]}")
2 changes: 1 addition & 1 deletion algorithms/searches/linear_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ def linear_search(arr, item):

# Tests

print(search([1,2,3,4,5], 3))
print(linear_search([1,2,3,4,5], 3))