33.6k views
3 votes
Imagine we have a list of instances of OnlineOrder, called orders. There are various functions and algorithms we could run on it.

Here's one such algorithm. This algorithm retrieves the total cost of the first order in the list. Note that if relevant, you may assume that all orde in orders have around the same number of items.
1 det et first order total orders
What is the running time of this algorithm in terms of Big O notation?
O(1) constant order O(n)
linear order (nº)
quadratic order (12)
polynomial (cubic, specifically) order
O(2) exponential order O(log(n))
logarithmic order
Imagine we have a list of instances of OnlineOrder, called orders. There are various functions and algorithms we could run on it.
Here's one such algorithm. This algorithm finds the total cost of orders in the list. Note that if relevant, you may assume that all or have around the same number of items.
1 def get all order totals(orders):
2 total = 0.0
3 for order in orders:
4 total + order.get order total) Si
5 return total
What is the running time of this algorithm in terms of Big O notation?
O(1), constant order (n)
linear order (n2)
quadratic order (nº)
polynomial (cubic, specifically) order 0
O(2), exponential order (log (n))
logarithmic order 0.0/1.0 point
Imagine we have a list of instances of OnlineOrder, called orders. There are various functions and algorithms we could run on it.
Here's one such algorithm. This algorithm searches for an order with a giverr order number, and returns the index of where it is found. If it is found, it returns - 1. This is implemented with binary search, and we assume that orders is sorted from lowest order number to highest. Note if relevant, you may assume that all orders in orders have around the same number of items.
1) def search orders (orders, search number);
2) win = 0
3) nas n lentorders) 1
4) while in <-
5) current_middle (winna) // 2
6) If orders (current middlel on search numbers
7) return current middle
8) elif search number orders current siddle.order Numbers -
9) Max current siddle 1
10) else:
11) min = current middle an
12) return -1
What is the running time of this algorithm in terms of Big O notation?
O(1), constant order O(n)
linear order O(nº)
quadratic order On
polynomial (cubic, specifically) order 0
O(2), exponential order (log(n))
logarithmic order

User Sschuberth
by
4.2k points

1 Answer

3 votes

Answer:

The answer to this question can be defined as follows:

In question 1, the answer is "O(1), constant order ".

In question 2, the answer is "O(n), linear order".

In question 3, the answer is "O(log(n)), logarithmic order".

Step-by-step explanation:

  • In question 1, There are no constant or low-order words for big-O notation. It's attributable to the fact and, where N is big sufficient, the terms static and low average differ the algorithm with succession planning is quicker than a linear method and it is slower than that of an algorithm with quadratic times.
  • In question 2, The complete sequence is also called a linear order, and also a sequence is named, or even a set with such a real line. To demonstrate so a not (simply) total request always alludes to it as a weighted sum, several authors utilize a to claim a||b to demonstrate either that a≤b or b≤a holds.
  • In question 3, the Log-linear running time (O(log n)) implies that only the total speed rises proportionally to the output-group number system.
User Shnd
by
4.5k points