Big O Notation

¡Supera tus tareas y exámenes ahora con Quizwiz!

What are the three cases that Big O can be used for with an algorithm?

1. Best Case: Telephone book search, the best case is that we find the name in one comparison O(1) CONSTANT COMPLEXITY 2. Expected Case: O(log n) 3. Worst Case: also O(log n)

What is the Big O of inserting an item to the end of an array? What is the Big O of inserting an item into the middle of an array?

1. O(1) - discounting the case where you'd have to resize the array if its its full 2. O(n)

By what percent is the input size decreased in binary search on each iteration through the alg?

50%

Say you are given a phonebook and you are given a phone number and asked to find the name associated with it? What is the time complexity?

Best Case: O(1) Expected Case: O(n) Worst Case: O(n)

What is the name of O(1)

Constant complexity : 1 item : 1 second 1000000 items : 1 second

What is O(1)?

Describes an algorithm that will always execute in the same time regardless of the size of the input data set. Constant complexity.

Who invented the Big O Notation?

Edmund Landau

What is a classic example of O(2^N) run time?

Fibonacci.

What are trees good for?

Finding ranges of values.

Is insertion sort or bubble sort on average more efficient? Is selection sort or bubble sort on average more efficient? What are each respective time complexities?

Insertion sort Selection sort O(n^2)

Define Big-O notation. Define relative within the definition.

It is a relative representation of the complexity of an algorithm. It helps us better understand how well an algorithm will scale as the input size increases. Relative: You can only compare apples to apples. You can't compare an algorithm that sorts a list of integers to an algorithm that performs some arithmetic multiplication. BUT a comparison to an algorithm that performs some arithmetic multiplication to an algorithm that performs some arithmetic addition will tell you something meaningful Representation: Reduces the comparison between algorithms to a single variable (i.e. O(n) O(log n), etc.). Based on assumptions and usually on worst case scenario. Complexity: Relative measure to something else. Ex: If it takes one second to sort 10,000 elements. How long will it take me to sort one million?

What are linked lists good for?

Linked lists preserve order of insertion.

What is the name of O(log n)

Logarithmic complexity: 1 item : 1 second 10 items: 2 seconds 100 items: 3 seconds

Why is the letter O used?

O is used because the rate of growth of a function is also called its order.

What is the big O of the internet's transfer speed? And explain what it means.

O(N). Describes an algorithm whose performance grows linearly and in direct proportion to the size of the input data set.

What is the Big O of Bubble Sort?

O(N^2)

Does O(n^c) or O(c^n) grow faster?

O(c^n)

What is the big O of binary search?

O(log n). AKA logarithmic complexity

What is the Big O of merging k sorted arrays? What is the term to implement this?

O(n log n). a heap.

What is the big O of finding an item in a linked list

O(n) the time complexity is directly related to number of items in linked list.

What is the Big O of insertion sort?

O(n^2)

What is the name of O(n^c)

Polynomial complexity

What are hashmaps good for?

Quick lookup.

What is O(2^N)?

Represents an algorithm whose growth doubles with each addition to the input data set. It is an exponential function.

Explain O(N^2)

Represents an algorithm whose performance is directly proportional to the square of the size of the input data set.

What are two of the most important things you have to consider when weighing the Big O of an algorithm?

Saving time and saving space

Name an example of binary search with its complexity being O(log n)?

Say you have a phonebook with 1000000 pages of contacts. How would you find 'John Smith'. 1. Find the 500,000 page 2. If 'John Smith' comes before or after the name on that page, divide everything before or after 3. Keep sub dividing until you land on his name At most this will take 20 times to find.

What is the only difference between O(log(n)) and O(log(n))^c)?

The only difference is the constants, and the big O notation ignores constants.

Name a real life example of O(N^2)

The time it takes to paint a square wall of length N. (N is the length of the wall). Say the length is 4... Math.pow(4, 2) = 16 Say you increase the length to 8... Math.pow(8, 2) = 64 Increases exponentially. It now takes 4x as long.

What is the traveling salesman problem? And what is it's Big O Notation? At how many towns does the complexity get so great that no amount of computers can solve it?

There are N towns. Each town is linked to one or more other towns. The traveling salesman is tasked with finding the shortest route while visiting every town. 3 towns --> 3 possibilities 4 towns --> 12 possibilities 5 towns --> 60 possibilities 6 towns --> 360 possibilities You take factorial of towns and divide by 2. The complexity is O(n!) 200 towns

What is the Big O of inserting an item into an array?

Worst case: O(n) linear complexity. If you insert a value at the beginning, all numbers must be moved one to the right.

Are the following complexities equal? O(log(n)) === O(log(n))^c) Name each one.

Yes they are equal O(log(n)) === logarithmic O(log(n))^c) === polylogarithmic

Define Memoization.

a programming technique which attempts to increase a function's performance by caching tis previously computed results (usually in a hash table)

Is binary search or indexOf better for large data sets and why?

binary search b/c it is O(log n) and indexOf is O(n)

What is the big O of finding an item in a hash table? Why is it this?

constant Looking up a value in a hash table does not depend on the number of items

Name the common performance classes of Big O Notation

constant time, linear time, exponential, logarithmic, polynomial, factorial

What is the big o of a nested for loop? for (....) for (....)

each is for loop is considered O(n). Therefore, a nested for loop is O(n^2)

What is the name for O(n)

linear complexity. If the problem size doubles, the number of operations doubles 1 item : 1 second 10 items : 10 seconds 100 items : 100 seconds

What is the big O of finding an item in a balanced tree

log n

What is the name for O(n^2)

quadratic complexity. 1 item : 1 second 10 item : 100 seconds 100 item : 10000 seconds

What do you a call function that grows slower than an exponential function of the form O(c^n)?

subexponential

What do you call a function that grows faster than any exponential function of the form O(c^n)?

superpolynomial


Conjuntos de estudio relacionados

Teaching and Learning/Patient Education

View Set

CULTURAL COMPETENCY FOR ALL CLASSES

View Set

Male reproductive disorders from PrepU

View Set

Ch 7 and 8 - Data Warehouse and Big DataAssignment

View Set

Chapter 3. Fitness, Wellness, and Stress Management

View Set

FOUNDATIONS OF PROGRAMMING : INTRODUCTION TO PROGRAMMING : 01.05 STRING INPUT

View Set

Academic Team Full Practice Set 9

View Set