0
0
Drone Programmingprogramming~5 mins

Indian drone regulations (DGCA rules) in Drone Programming - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Indian drone regulations (DGCA rules)
O(n)
Understanding Time 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.

Scenario Under Consideration

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.

Identify Repeating Operations
  • Primary operation: Looping through all DGCA rules to check each one.
  • How many times: Once for each rule in the rules list.
How Execution Grows With Input

As the number of DGCA rules increases, the program checks more rules one after another.

Input Size (n)Approx. Operations
10 rules10 checks
100 rules100 checks
1000 rules1000 checks

Pattern observation: The number of checks grows directly with the number of rules.

Final Time Complexity

Time Complexity: O(n)

This means the time to check all rules grows in a straight line as the number of rules increases.

Common Mistake

[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.

Interview Connect

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.

Self-Check

"What if the rules were grouped and checked in parallel? How would the time complexity change?"