Python
- key differences between List and Arrays
- Python collections ChainMap
- Array : Find median in an integer array
- Array : Find middle element in an integer array
- Array : Find out the duplicate in an array
- Array : Find print all subsets in an integer array
- Program : Array : Finding missing number between from 1 to n
- Array : Gap and Island problem
- Python collections
- Python Program stock max profit
- Reverse words in Python
- Python array duplicate program
- Coin change problem in python
- Python Write fibonacci series program
- Array : find all the pairs whose sum is equal to a given number
- Find smallest and largest number in array
- Iterate collections
- List comprehensions in Python
- key differences between List and Arrays
- Program: Calculate Pi in Python
- String Formatting in Python
- Python counters
- python tuples
- Python deque
- Python dictionary
- Python Lists
- python namedtuple
Array : Finding missing number between from 1 to n
In this article, we delve into the problem of finding the missing number in an integer array containing elements from 1 to n. We present an efficient algorithm in Python to identify the missing number and explain the underlying logic step-by-step. By leveraging the concept of arithmetic progression and using the sum formula, we can quickly locate the missing element in the array. This technique is particularly useful when dealing with datasets where one or more numbers are missing, and it helps ensure data integrity and completeness. Learn how to tackle the missing number problem and gain insights into its applications in data analysis and algorithmic problem-solving.
## code
def find_missing_numbers(arr):
n = 100 # Highest number in the range
presence = [False] * n # Array to mark the presence of numbers
# Mark numbers present in the array
for num in arr:
presence[num - 1] = True
missing_numbers = []
# Find missing numbers
for i in range(n):
if not presence[i]:
missing_numbers.append(i + 1)
return missing_numbers
#Array
array = [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
missing_numbers = find_missing_numbers(array)
print("Missing Numbers:", missing_numbers)
Output :
Missing Numbers: [5, 12]