Surveying and mapping with photogrammetry in Drone Programming - Time & Space Complexity
When using drones for surveying and mapping with photogrammetry, we want to know how the time to process images grows as we collect more data.
We ask: How does the work increase when we add more photos to map?
Analyze the time complexity of the following code snippet.
function processPhotos(photoList) {
let mappedPoints = []
for (let photo of photoList) {
let points = extractPoints(photo)
for (let point of points) {
mappedPoints.push(transformPoint(point))
}
}
return mappedPoints
}
This code takes a list of photos, extracts points from each photo, transforms them, and collects all mapped points.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Nested loops over photos and points inside each photo.
- How many times: Outer loop runs once per photo; inner loop runs once per point in each photo.
As the number of photos increases, and the number of points per photo stays about the same, the total work grows roughly in proportion to the number of photos times points per photo.
| Input Size (photos) | Approx. Operations |
|---|---|
| 10 | 10 x points per photo |
| 100 | 100 x points per photo |
| 1000 | 1000 x points per photo |
Pattern observation: The total operations grow linearly with the number of photos, assuming points per photo stay similar.
Time Complexity: O(n x m)
This means the time grows in proportion to the number of photos (n) times the average number of points per photo (m).
[X] Wrong: "The time only depends on the number of photos, not the points inside them."
[OK] Correct: Each photo has many points to process, so ignoring points misses the real work inside the inner loop.
Understanding how nested loops affect time helps you explain how data size impacts drone mapping tasks, a useful skill in real projects.
"What if the number of points per photo grows as we use higher resolution images? How would the time complexity change?"
Practice
Solution
Step 1: Understand photogrammetry basics
Photogrammetry uses many overlapping photos to build maps and 3D models.Step 2: Identify the main goal in drone surveying
The goal is to create accurate maps and 3D models from the photos taken by the drone.Final Answer:
To create maps and 3D models from overlapping photos -> Option AQuick Check:
Photogrammetry = maps and 3D models [OK]
- Confusing photogrammetry with drone battery management
- Thinking photogrammetry speeds up flight
- Assuming photogrammetry reduces photo count
Solution
Step 1: Identify list syntax in Python
Lists use square brackets [] with items separated by commas.Step 2: Check each option
flight_path = ["point1", "point2", "point3"] uses square brackets and quotes correctly for strings.Final Answer:
flight_path = ["point1", "point2", "point3"] -> Option CQuick Check:
List syntax = square brackets [OK]
- Using parentheses instead of square brackets for lists
- Using curly braces which create sets, not lists
- Leaving out brackets and just separating by commas
photos = ["img1.jpg", "img2.jpg", "img3.jpg"]
processed = [photo.replace('.jpg', '.tif') for photo in photos]
print(processed)Solution
Step 1: Understand list comprehension with string replace
Each photo filename has '.jpg' replaced by '.tif'.Step 2: Apply replace to each item
"img1.jpg" becomes "img1.tif", similarly for others.Final Answer:
["img1.tif", "img2.tif", "img3.tif"] -> Option AQuick Check:
Replace '.jpg' with '.tif' = changed list [OK]
- Expecting original list without changes
- Thinking replace adds text instead of replacing
- Confusing syntax causing errors
overlap = 0.7
if overlap > 1:
print("Overlap too high")
else
print("Overlap acceptable")Solution
Step 1: Check syntax of if-else statements
Python requires a colon ':' after else keyword.Step 2: Identify missing colon
Code has 'else' without a colon, causing syntax error.Final Answer:
Missing colon after else statement -> Option BQuick Check:
else: needs colon [OK]
- Forgetting colon after else
- Thinking overlap must be integer
- Misreading comparison operator
photos = ["img1.jpg", "img2.jpg", "img3.jpg"] and coords = [(34.5, -117.2), (34.6, -117.3), (34.7, -117.4)]?Solution
Step 1: Understand dictionary creation from two lists
We want keys as photo names and values as coordinates.Step 2: Check each option
photo_coords = {photos[i]: coords[i] for i in range(len(photos))} uses dictionary comprehension with matching indexes correctly.Final Answer:
photo_coords = {photos[i]: coords[i] for i in range(len(photos))} -> Option DQuick Check:
Dict keys=photos, values=coords [OK]
- Swapping keys and values in dict
- Using zip with wrong order
- Creating list instead of dict
Ready to prove it?
Pass the test and this pattern moves unknown
