Skip to main content
Teacher Portal

Teacher Toolbox icon Teacher Toolbox - Introducing Code Efficiency

Now that students have had practice writing code sequences to accomplish a specific task, they will be asked to apply those skills to reading code sequences and evaluating them. In this activity, students will be given a map similar to the one in the Play section, and asked to look at 3 code sequences to choose the preferred solution. For each sequence students will answer 3 questions:

  • Does this code accomplish the task?

  • If it works, what are the advantages of this code over the others?

  • What are the disadvantages of this code over the others?

Then, looking at all of the sequences, the students will be introduced to the idea of code efficiency and asked what their preferred solution is—based on efficiency and their own preferences—and to explain why. This can be a springboard for a whole class discussion about efficiency and accuracy in coding.

Reading Code Sequences to Choose a Preferred Solution

As your class worked on the Play section, you probably noticed that there were many different solutions to the same problem that was presented. That is something that happens often in the world of programming. While there can be different ways to do something, everyone will have a preferred method or solution, and that could be based on a number of factors. In this activity, your group will look at 3 possible code block solutions to a problem, figure out if they work in the intended fashion, then choose a preferred solution from the group and explain why you chose it.

The problem: Create a sequence that, when the robot begins at the Start, will travel into and out of all 3 classrooms (in any order) and return to the End point. The robot must navigate around the stairs, and can go through the doorways marked by the small rectangles on the map image.

  • For each solution below, answer these 3 questions in your engineering notebook:

    • Does this code accomplish the task? Why or why not?

    • If it does work, what are the advantages of this code over the others?

    • What are the disadvantages of this code over the others?

  • Most of the time, programming is evaluated on its efficiency, and the preferred solution is one that accomplishes the goal in the most efficient way possible.

Click on the solutions below to see a larger image.

Solution A (inches)
Solution A (inches)

Solution B (inches)
Solution B (inches)
Solution C (inches)
Solution C (inches)
Solution A (metric)
Solution A (metric)
Solution A (metric)
Solution B (metric)
Solution C (metric)
Solution C (metric)

What is Code Efficiency?

If you needed to get 3 things from your kitchen, you would probably go get all 3 things in one trip, instead of making 3 separate trips. Why? Because it would be more efficient. Efficient means “achieving maximum productivity with minimum wasted effort or expense.” So how does that connect to programming?

Code efficiency means that a program is written to work well and quickly, using the least amount of work, or steps, properly, while still doing its job. It is important because it reduces the risk of a program not functioning well, and in turn, causing problems for other parts of a program that are running around it. The efficiency of a code can be a measure of quality, and when we write projects in VEXcode IQ block, we are often looking for the most “efficient” project as the preferred solution.

Basically, code efficiency is a principle that means you want to write a code that accomplishes your goal using the fewest commands, or blocks, possible.

In your Engineering Notebook, answer the following questions:

  • With code efficiency in mind, which is your preferred solution and why?

  • Do you think that is the best solution, why or why not?

Teacher Toolbox icon Teacher Toolbox - Answers

Answers may vary since the no specific dimensions were given above for creating a sequence to navigate around three rooms.
Click here for a possible example solution.

Motivate Discussion icon Motivate Discussion

While efficiency is useful, we often have other considerations about how or why we do things a certain way. Have students share their answers in their Engineering Notebook, and/or use this question to frame a discussion about the balance of efficiency and actions.
Q: In programming, efficiency is usually the preferred methodology; can you think of a reason why this is the case?
A: Answers will vary, but some include:

  • Editing projects so that they are more efficient helps those in the future that could be possibly working with the same project. For example, if you work on a project and then a few days later, ask your friend to update the project and add a few more items to increase the functionality, it will be easier for your friend to read and work with if the project is written efficiently.

  • Projects are always susceptible to errors. The more efficient a project is written, the less likely of an error to be made.

  • Individuals who use programming to maneuver industrial robots rely on those projects being efficient in order to save the company time, energy, and resources.