Notes

3.9 Video 1

  • Algorithms can be written in mulitple ways and do the same tasks
  • Yield different side effects or results
  • Conditional statements can be written as equivalent Boolean expressions
  • Boolean expressions can be written as equivalent conditional statements
  • Different algorithms can be developed or used to solve the same problem

3.9 Video 2

  • Algorithms can be created from an idea, by combining existing algorithms, or by modifying existing algorithms.
  • Iteration: Repeating steps, or instructions over and over again. ( this could be also often called a loop )
  • Selection: is a decision or question. At some point in an algorithm there may need to be a question because the algorithm has reached a step where one or more options are available.

3.9 Video 3

  • Determining the maximum or minimum value of two or more numbers. Computing the sum or average of two or more numbers. Identifying if an integer is or is not evenly divisible by another integer. Determining a robot’s path through a maze.
  • Using existing correct algorithms as building blocks for making another algorithm has benefits
  • Benefits = reducing development time, reduce testing, and simplifying the identification of errors.
  • Algorithm: A process or set of rules to be followed in calculations or other problem solving operations, especially by a computer.

3.11 Video 1

  • Determine the number of iterations required to find a value in a data set.
  • Explain the requirements necessary to complete a binary search.
  • The binary search algorithm starts at the middle of a sorted data set of numbers and eliminates half of the data; this process repeats until the desired value is found or all elements have been eliminated.
  • Data must be in sorted order to use the binary search algorithm
  • A binary search is often more efficient than sequential/linear search when applied to sorted data.
  • While using Binary Search you have to put the group of numbers from ascending or descending order
  • What the computer does it takes the lowest index and the highest index, adds them and then divides that value by 2.
  • This gets the middle value and starts the search at the middle of the group.

Hacks

Question 1

if (isCold or isRaining) {
    stayInside <- True
}
else {
    stayInside <- False
}
  Cell In[2], line 1
    if (isCold or isRaining) {
                             ^
SyntaxError: invalid syntax

Question 2

import random
random_number = []

i = 1 
while i <= 4:
    random_number.append(random.randint(1,10))
    i = i +1 
def sort(random_number):
    for index in range(1,len(random_number)):
        value = random_number[index]
        i = index - 1
        while i >= 0:
            if value < random_number[i]:
                random_number[i+1] = random_number[i] 
                random_number[i] = value 
                i = i - 1
            else:
                break
sort(random_number)
print(random_number)
print("Max Score:", random_number[len(random_number)-1])
[3, 7, 8, 10]
Max Score: 10

Question 3

if (canmoveForward)
    moveForward
else: (canmoveRight) {
    rotateRight
moveForward
}
  Cell In[16], line 1
    if (canmoveForward)
                       ^
SyntaxError: invalid syntax

Question 4

binarysearchtree

Question 5

Explain thorughly how to find the number 69 in the list above (use key words)

In order to find the number 69 in the list above, I would use the middle index, which is 4.5 and round it to 5. The fifth number in the sequence is 6, and 6 is less than 69. After finding the middle index, you have to find the first half middle index and second half middle index. The work for how I found the numbers of each index is shown in question 6. I used all the elements in the list given to find the number 69.

Question 6

equation

Question 7

Unsorted List of Strings

[“store”, ”Market”, ”Walmart”, "Target”, ”Ralphs”]

Sorted List of Strings

["Market”, ”Ralphs”, “store”, "Target”, ”Walmart”]

Question 8

Explain why Binary Search is more efficient than Sequential Search.

Binary search is more efficient than sequential search because it makes it easier to find an item in a sorted list of items. It's more efficient because it works by continuously dividing half the proportion of the list , which could contain the item until it is narrowed down to one location. It is useful and efficient especially when there is a large set of data because it sorts it and finds the user’s final goal. Sequential search Is not as efficient as binary search because it finds a value in an unsorted array. However, if an array is sorted in the order of increasing value, then binary search is the most efficient and ideal way to go when approaching searching.

Question 9

[64,36,16,11,9] Explain which number you are finding, how many check it would take, and make a binary search tree

binarytree2

I'm finding number 16 and it would take one check to find the number 16. It would take one check because the order of the numbers are ascending up, so it would give me the middle index number.