All of the above
---------------------------------
Linear search
You implement this algorithm by iterating over each item, and checking if the item matches what you are searching for.
It is linear because it takes a linear amount of time to search for an item.
Answer:
- common = []
- num1 = 8
- num2 = 24
- for i in range(1, num1 + 1):
- if(num1 % i == 0 and num2 % i == 0):
- common.append(i)
- print(common)
Explanation:
The solution is written in Python 3.
Firstly create a common list to hold a list of the common factor between 8 and 24 (Line 1).
Create two variables num1, and num2 and set 8 and 24 as their values, respectively (Line 3 - 4).
Create a for loop to traverse through the number from 1 to 8 and use modulus operator to check if num1 and num2 are divisible by current i value. If so the remainder of both num1%i and num2%i will be zero and the if block will run to append the current i value to common list (Line 6-8).
After the loop, print the common list and we shall get [1, 2, 4, 8]
Answer:
Answer explained
Explanation:
From the previous question we know that while searching for n^(1/r) we don't have to look for guesses less than 0 and greater than n. Because for less than 0 it will be an imaginary number and for rth root of a non negative number can never be greater than itself. Hence lowEnough = 0 and tooHigh = n.
we need to find 5th root of 47226. The computation of root is costlier than computing power of a number. Therefore, we will look for a number whose 5th power is 47226. lowEnough = 0 and tooHigh = 47226 + 1. Question that should be asked on each step would be "Is 5th power of number < 47227?" we will stop when we find a number whose 5th power is 47226.
Answer:
The resultant value is 0
Explanation:
Solution
Given that:
Now
The +5 representation in signed 2's complement integer: 00000101
Thus
When we right shift then, 4 rightmost bit (0101) will be dropped.
The number after 4-bit right shift: 00000000
Therefore the resultant value after 4-bit right shift is "0" in decimal.