Data Structures & AlgorithmsยทPractice drills 7

Drill 16: Inputs and outputs โ€” Complexity and Big O

Identify the inputs and outputs of the example.

Intermediate 5 min read Lesson 166 of 300 Challenge included
What you will be able to do
  • Identify the inputs and outputs of the example.

Practice task

Identify the inputs and outputs of the example.

complexity.jsJavaScript
// O(n): one pass
function total(values) {
  let sum = 0
  for (const value of values) sum += value
  return sum
}

// O(n^2): compare every pair
function hasDuplicate(values) {
  for (let i = 0; i < values.length; i++)
    for (let j = i + 1; j < values.length; j++)
      if (values[i] === values[j]) return true
  return false
}
Your turn

Write your answer

Easy

Identify the inputs and outputs of the example.

TEXT ยท starter
Your answerโ€ฆ
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 166 of 300 ยท 0% of course