Code Sniff Et
Code Sniff Et
Code Sniff Et
Prefix form: - + p q * r s
Postfix form: p q + r s * -
def countingSort(array, place):
size = len(array)
output = [0] * size
count = [0] * 10
# Calculate count of elements
for i in range(0, size):
index = array[i] // place
count[index % 10] += 1
# Calculate cumulative count
for i in range(1, 10):
count[i] += count[i - 1]
# Place the elements in sorted order
i = size - 1
while i >= 0:
index = array[i] // place
output[count[index % 10] - 1] = array[i]
count[index % 10] -= 1
i -= 1
for i in range(0, size):
array[i] = output[i]
# Main function to implement radix sortdef radixSort(array):
# Get maximum element
max_element = max(array)
array[j + 1] = key
data = [9, 5, 1, 4, 3]
insertionSort(data)print('Sorted Array in Ascending Order:')
print(data)
• In a complete binary tree (where all levels are filled except possibly
the last level, which is filled from left to right), the number of null
pointers can vary depending on the structure of the tree. However, in
the worst case scenario, where the last level is half-full, a complete
binary tree with n nodes has floor(n/2) + 1 null pointers.
The minimum number of AVL nodes is Fib(h+2)-1
Minimum Nodes in an AVL tree with height n is H(n)=H(n−1)+H(n−2)+1.
H(0)=1. H(3)=H(2)+H(1)+1=4+2+1=7. So, the max height with 7 nodes is 3.