Python
Python Basics
- Introduction to Python and Its History
- Python Syntax and Indentation
- Python Variables and Data Types
- Dynamic and Strong Typing
- Comments and Docstrings
- Taking User Input (input())
- Printing Output (print())
- Python Operators (Arithmetic, Logical, Comparison)
- Type Conversion and Casting
- Escape Characters and Raw Strings
Data Structures in Python
- Strings and String Manipulation in Python
- Python Lists: A Guide to `list` and List Methods
- Tuples in Python: Immutable Sequences Made Easy
- Dictionaries in Python: Key-Value Pairs Explained Simply
- Python Sets: Unordered Collections Made Simple
- List Comprehensions and Generator Expressions in Python
- Dictionary Comprehensions in Python
- Set Comprehensions in Python
- String Formatting in Python: f-strings, format(), and % Operator
- Indexing and Slicing in Python: Lists, Strings, and Tuples
Python Core Concepts
Python Collections
- Python collections ChainMap
- Python collections
- Python collections ChainMap<
- Python counters
- Python deque
- Python dictionary
- Python Lists
Python Programs
- 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 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
- Program: Calculate Pi in Python
- String Formatting in Python
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]