SCC.121 Algorithms and Complexity - Introduction to Operation Counting

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

flashcard set

Earn XP

Description and Tags

Flashcards covering key concepts from the lecture on operation counting in algorithms, including running time, cost of operations, and best vs. worst case scenarios.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards

What factors determine the running time of an algorithm?

The size of the input and the organization of the input.

2
New cards

Why do we generally seek upper bounds (worst case) on the running time of an algorithm?

To understand the maximum time the algorithm could take, providing a guarantee on performance.

3
New cards

What is a limitation of using an experimental approach to determine the efficiency of an algorithm?

It requires implementing the algorithm, results may not be indicative of other inputs, and requires the same hardware and software for comparison.

4
New cards

What is the advantage of using Operation Counting?

Operation counting allows us to estimate actual runtime and come up with classes of runtimes based on input size, which means to analyze algorithms and this can be done without implementing the algorithms.

5
New cards

What counts as one operation when determining how long an algorithm takes to run?

An elementary operation that takes a fixed time to execute, independent of the choice of language or compiler.

6
New cards

Why do we ignore minor details between programming languages when counting operations?

To analyze the algorithm itself, independent of the specific language used to execute it.

7
New cards

Given an array of integers arr of size n, what is the first step when counting how many operations the 'find max element' code executes?

Count the operations in the initialization step: int maxel = arr[0];

8
New cards

In the 'find max element' algorithm, how many operations are associated with the for loop initialization?

Two operations: assignment ('i = 0') and comparison ('i < n').

9
New cards

In the 'find max element' algorithm, what operations occur after each for loop iteration?

Increment of 'i' (i++) and comparison ('i < n').

10
New cards

Why can't we always easily define the number of operations T(n) for an algorithm?

Because the number of operations may depend not only on the size of the input 'n' but also on the organization of the input.

11
New cards

What are the different scenarios considered when analyzing the number of operations an algorithm needs?

Worst-case scenario, best-case scenario, and average-case scenario.

12
New cards

What is the worst-case scenario when finding the max element in an array?

When each element in the array is greater than the previous max, meaning 'maxel' needs to be replaced every single time.

13
New cards

What is the best-case scenario when finding the max element in an array?

When the first element is the largest, so 'maxel' never needs to be replaced.

14
New cards

What is the equation to determine the total number of operations T(k) when counting the operations for 'sum += a[i]'?

T(k) = 3k + 3 where k is the length of the Input array a.

15
New cards

What are the considerations when defining T(n) that we learned about in this lecture?

Best case, Worst Case and Average case.