write a program to initialise a SDA of 10 numbers 8n alphabetically reverse order and in lowercase,search a word using Binary search technique.
Home
/
write a program to initialise a SDA of 10 numbers 8n alphabetically reverse order and in lowercase,search a word using Binary search technique.
Answer:
Sure! Here's a program that initializes a Sorted and Descending Array (SDA) of 10 lowercase alphabets in reverse alphabetical order and performs a binary search to find a word:
```python
def binary_search(arr, target):
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] > target:
low = mid + 1
else:
high = mid - 1
return -1
sda = ['j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a']
word = 'search'
sda.sort(reverse=True)
result = binary_search(sda, word)
if result != -1:
print(f"The word '{word}' was found at index {result}.")
else:
print(f"The word '{word}' was not found in the SDA.")
```
In this program, we create an SDA (Sorted and Descending Array) with 10 lowercase alphabets in reverse order. Then, we perform a binary search to find the specified word. If the word is found, it will display the index where it was found. If not, it will indicate that the word was not found in the SDA.
Explanation:
mark as brainliest if you understood