Unit 3 Sections 17-18 Hacks
Home | API | Notes |
Notes (From the lesson + extra research)
- The Collatz Conjecture is an unsolved problem in mathematics that involves repeating two simple arithmetic operations on any given positive integer. This will eventually produce a sequence of numbers known as Hailstone Numbers,
Example: If the input is 7, the Hailstone Numbers would be 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1. Iteration is the action or process of repeating a sequence of operations until the desired result is achieved. Undecidable problems are those which should give a yes or no answer, yet no algorithm exists that can answer correctly on all inputs.
Algorithm efficiency in computer science refers to how efficient an algorithm is at solving a given problem.
Efficiency is typically measured in terms of time and/or space complexity, meaning how much time and/or memory is needed to complete the algorithm. Algorithm efficiency is an important factor in determining which algorithm should be used to solve a particular problem.
Time Complexity: This measures the amount of time required to execute an algorithm. Time complexity is usually expressed as a function of the input size, and can be calculated using Big-O notation. Generally, algorithms with a lower time complexity are considered more efficient than those with a higher time complexity.
Space Complexity: This measures the amount of memory required to execute an algorithm. Space complexity is also expressed as a function of the input size, and can also be calculated using Big-O notation. Generally, algorithms with a lower space complexity are considered more efficient than those with a higher space complexity.
Optimization Techniques: Optimization techniques can be used to improve the efficiency of an algorithm. These techniques can involve modifying the algorithm itself, or using data structures and algorithms that are better suited to the problem.
Parallelism: Parallelism is a technique that allows multiple parts of an algorithm to be executed simultaneously. This can significantly reduce the amount of time required to complete the algorithm, but can also increase the complexity of the algorithm.
In conclusion, algorithm efficiency is an important factor in determining which algorithm should be used to solve a particular problem. Factors such as time complexity, space complexity, optimization techniques, and parallelism should all be taken into consideration when assessing the efficiency of an algorithm.
i = int(input("Please input a number: "))
list = []
def collatz_seq(n):
list = []
while n != 1:
if (n % 2):
n = 3*n + 1
else:
n = n/2
list.append(n)
return list
result = collatz_seq(i)
print("Input:" , i)
print(result)
print("Iteration count:", len(result))
car = []
car.append({
"Make": "BMW",
"Model": "M4 CSL",
"Year": "2023",
})
def loop():
for data in car:
print(data)
loop()
car = "Make: BMW", "Model: M4 CSL", "Year: 2023"
print(car)
Algorithm 1 properly displays efficiency, as it appends the list and utilizes a for loop in order to display the data of the given car in an orderly manner. Algorithm 2 is inefficient because the data is only displayed in the order that it is typed in.
- Explain algorithm efficiency in your own words (.25)
Algorithm efficiency in computer science is the measure of how well a particular algorithm performs when compared to other algorithms. It is typically calculated by measuring the amount of time and space it takes to complete a task. The most efficient algorithms are those that take the least amount of time to complete a task while consuming the smallest amount of resources. In other words, the most efficient algorithms are those that are able to accomplish a task in the shortest amount of time with the least amount of memory and CPU cycles.
- Code an efficient program that shows your daily tasks or schedule. (We have an example shown in our lesson) (.25)
tasks = ["wake up", "get ready", "head to school", "finish homework/study", "go to bed"]
def daily_routine(tasks):
for task in tasks:
if task == "wake up":
print("Waking up!")
elif task == "get ready":
print("Getting ready!")
elif task == "head to school":
print("Heading to school!")
elif task == "finish homework/study":
print("Working hard!")
elif task == "going to bed":
print("Time for bed!")
daily_routine(tasks)
from getpass import getpass