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

Adding for GFG POTD 17thFeb2024 | Does Array Represent Heap- Solution2 #40

Open
wants to merge 7 commits into
base: main
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Winner of an Election
# Does Array Represent Heap

> Level: Easy

Expand Down
32 changes: 32 additions & 0 deletions Platform-Wise/GeeksForGeeks/POTD/DoesArrayRepresentHeap/sol2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Solution:

#Complete this function

#Function to return the name of candidate that received maximum votes.
def isMaxHeap(self,arr,n):
# Your code goes here

"""
To verify if a given array is a max-heap,
we need to check whether each node satisfies
the max-heap property, that is,
that key[Parent(i)]≥key[i] for all nodes i
except for the root.
"""

for i in range(1, n):
parent_node=(i+1)//2
if arr[parent_node-1]<arr[i]:
return False
return True

# {
# Driver Code Starts
if __name__=="__main__":
t=int(input())
for tcs in range(t):
n=int(input())
arr=[int(x) for x in input.split()]
ob=Solution()
print(ob.isMaxHeap(arr, n))
# } Driver Code Ends
Loading