Skip to content

Commit

Permalink
Added Moore Algorithm in Python
Browse files Browse the repository at this point in the history
I have solved the issue HarshCasper#1439 in which i have written code in python for Moore Algorithm.
  • Loading branch information
aeyshubh authored and JayantGoel001 committed Dec 31, 2020
1 parent 959dfdf commit 678c11a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Python/other/Moore_Algorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## This Program Checks the maximum occurence of a number in a array/list
def counting_fun(array):
count_temp = 0 #For storing the occurence of a number
for i in range(0,len(array)):
count_temp = array.count(array[i]) # Counts the occurence
if count_temp > number/2:
print(f"Number occuring more than n/2 is :{array[i]}") ##Prints the number with max occurence
count_temp = "True"
break
if(count_temp != "True"):
print("No Element occuring more than n/2")

#Read Program from Here ->
number = int(input("Enter Number of values you will enter(eg. 6) : "))
i=0
list_1 = [] # List Declaration
print(f"Enter {number} values: ")
for i in range(0, number):
elements = int(input())
list_1.append(elements) # adding element to the list

counting_fun(list_1)

#Go to the line 1 for reading function


## Output :

/* Enter 6 values:
1
1
1
1
4
2
Number occuring more than n/2 is :1 */

0 comments on commit 678c11a

Please sign in to comment.