Indian drone regulations (DGCA rules) in Drone Programming - Time & Space Complexity
When programming drones under Indian DGCA rules, it is important to understand how the time taken by your code grows as you handle more drone data or rules.
We want to know how the program's work increases when the number of drones or rules grows.
Analyze the time complexity of the following code snippet.
// Check if a drone operation is allowed under DGCA rules
function isOperationAllowed(drone, rules) {
for (let rule of rules) {
if (!rule.check(drone)) {
return false;
}
}
return true;
}
This code checks each DGCA rule one by one to see if the drone operation meets all requirements.
- Primary operation: Looping through all DGCA rules to check each one.
- How many times: Once for each rule in the rules list.
As the number of DGCA rules increases, the program checks more rules one after another.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 rules | 10 checks |
| 100 rules | 100 checks |
| 1000 rules | 1000 checks |
Pattern observation: The number of checks grows directly with the number of rules.
Time Complexity: O(n)
This means the time to check all rules grows in a straight line as the number of rules increases.
[X] Wrong: "The program checks all rules instantly no matter how many there are."
[OK] Correct: Each rule must be checked one by one, so more rules mean more work and more time.
Understanding how your drone program handles many rules helps you write efficient code and shows you can think about how your program grows with more data.
"What if the rules were grouped and checked in parallel? How would the time complexity change?"
Practice
Solution
Step 1: Understand DGCA registration rule
DGCA mandates that all drones must be registered before flying in India.Step 2: Check other options against DGCA rules
Flying above 400 feet or in no-fly zones is prohibited without permission, and ignoring weight limits is not allowed.Final Answer:
Registering the drone before flight -> Option CQuick Check:
Registration is mandatory = C [OK]
- Assuming flying above 400 feet is allowed
- Ignoring no-fly zone restrictions
- Thinking weight limits don't matter
Solution
Step 1: Understand altitude limit condition
DGCA allows flying up to 400 feet inclusive, so altitude <= 400 is correct.Step 2: Analyze each condition
if altitude <= 400: print('Safe to fly') uses <= 400, which includes 400 feet. if altitude < 400: print('Safe to fly') excludes 400 feet, the other options allow unsafe altitudes.Final Answer:
if altitude <= 400:\n print('Safe to fly') -> Option AQuick Check:
Altitude must be at most 400 = B [OK]
- Using < 400 excludes exactly 400 feet
- Using >= or > allows unsafe altitudes
- Confusing comparison operators
weight = 2.5 # in kg
if weight <= 2:
print('Light drone')
elif weight <= 25:
print('Medium drone')
else:
print('Heavy drone')Solution
Step 1: Check weight against conditions
Weight is 2.5 kg, which is not <= 2 but is <= 25.Step 2: Determine which print executes
Since 2.5 <= 25, the 'Medium drone' print statement runs.Final Answer:
Medium drone -> Option BQuick Check:
2.5 kg fits medium drone category = A [OK]
- Assuming 2.5 kg is light drone
- Ignoring elif condition
- Thinking else runs for 2.5 kg
no_fly_zones = ['airport', 'military_base']
drone_location = 'airport'
if drone_location = no_fly_zones:
print('Drone in no-fly zone!')Solution
Step 1: Check the if condition syntax
The code uses '=' which is assignment, not comparison. It should be '==' or 'in'.Step 2: Understand correct membership check
To check if drone_location is in no_fly_zones, use 'if drone_location in no_fly_zones:'. Using '=' causes syntax error.Final Answer:
Using '=' instead of '==' in the if condition -> Option AQuick Check:
Use '==' or 'in' for comparison, not '=' [OK]
- Using '=' instead of '==' or 'in'
- Confusing assignment with comparison
- Not checking membership properly
Solution
Step 1: Analyze legal conditions
Drone must be registered, altitude <= 400, and location not in no-fly zones.Step 2: Check each option's logic
def is_legal(registered, altitude, location): if registered and altitude <= 400 and location not in ['airport', 'military_base']: return True return False uses 'and' for all conditions correctly. Others use 'or' or wrong comparisons allowing illegal flights.Final Answer:
def is_legal(registered, altitude, location):\n if registered and altitude <= 400 and location not in ['airport', 'military_base']:\n return True\n return False -> Option DQuick Check:
All conditions must be true = A [OK]
- Using 'or' instead of 'and' allowing illegal flights
- Wrong altitude comparison signs
- Incorrect no-fly zone membership check
Ready to prove it?
Pass the test and this pattern moves unknown
