This page contains practice problems with detailed solutions to help you improve your understanding of various subjects. Each problem includes a clear solution with step-by-step explanations.
To solve the quadratic equation 2x - 5x + 3 = 0, we can use the quadratic formula:
x = (-b (b - 4ac)) / 2a
Where in our equation: a = 2, b = -5, and c = 3
Substituting these values:
x = (-(-5) ((-5) - 4(2)(3))) / 2(2)
x = (5 (25 - 24)) / 4
x = (5 1) / 4
So we have two solutions:
x = (5 + 1) / 4 = 6/4 = 3/2
x = (5 - 1) / 4 = 4/4 = 1
Therefore, the solutions are x = 3/2 and x = 1.
We can verify our answers by substitution:
For x = 3/2: 2(3/2) - 5(3/2) + 3 = 0 2(9/4) - 15/2 + 3 = 0 9/2 - 15/2 + 6/2 = 0 0/2 = 0
For x = 1: 2(1) - 5(1) + 3 = 0 2 - 5 + 3 = 0 0 = 0
Here's a Python solution to find the second largest number in an array:
def find_second_largest(arr): # Check if array has fewer than 2 elements if len(arr) < 2: return -1 # Initialize largest and second largest largest = second_largest = float('-inf') # Iterate through the array for num in arr: if num > largest: second_largest = largest largest = num elif num > second_largest and num != largest: second_largest = num # If second largest remains negative infinity, it means all elements are equal if second_largest == float('-inf'): return -1 return second_largest largest and second_largest, to negative infinity.print(find_second_largest([5, 2, 9, 7, 3, 6])) # Output: 7print(find_second_largest([1, 2])) # Output: 1print(find_second_largest([5])) # Output: -1print(find_second_largest([8, 8, 8, 8])) # Output: -1 The algorithm runs in O(n) time, where n is the number of elements in the array, as we only need to iterate through the array once.
The algorithm uses O(1) additional space, as we only use a constant amount of extra memory.
First, let's break down the initial velocity into horizontal and vertical components:
Horizontal component: v = v cos() = 20 cos(30) = 20 0.866 = 17.32 m/s
Vertical component: v = v sin() = 20 sin(30) = 20 0.5 = 10 m/s
At the maximum height, the vertical velocity becomes zero. Using the equation:
v = v - gt
Setting v = 0:
0 = 10 - 9.8t
t = 10/9.8 = 1.02 seconds
Using the equation for displacement in the vertical direction:
y = vt - 0.5gt
y = 10 1.02 - 0.5 9.8 (1.02)
y = 10.2 - 5.1 1.0404
y = 10.2 - 5.306
y = 4.894 4.89 meters
First, we need to find the total time of flight. The time to go up is equal to the time to come down, so the total time is 2 1.02 = 2.04 seconds
The horizontal distance is:
x = v total time
x = 17.32 2.04 = 35.33 meters
Answers:
Here's a solution in Python that checks if a string is a palindrome:
def is_palindrome(s): # Convert the string to lowercase and remove non-alphanumeric characters cleaned = ''.join(char.lower() for char in s if char.isalnum()) # Check if the cleaned string equals its reverse return cleaned == cleaned[::-1] [::-1] is a slicing technique that reverses a string.True if the string is a palindrome and False otherwise.def is_palindrome_two_pointer(s): # Convert the string to lowercase and remove non-alphanumeric characters cleaned = ''.join(char.lower() for char in s if char.isalnum()) # Initialize two pointers left = 0 right = len(cleaned) - 1 # Move pointers toward each other while left < right: if cleaned[left] != cleaned[right]: return False left += 1 right -= 1 return True print(is_palindrome("racecar")) # Output: Trueprint(is_palindrome("A man, a plan, a canal: Panama")) # Output: Trueprint(is_palindrome("hello")) # Output: Falseprint(is_palindrome("Was it a car or a cat I saw")) # Output: True Both implementations run in O(n) time, where n is the length of the input string. The two-pointer approach might have a slight advantage in practice as it doesn't need to create a reversed string.
Both implementations use O(n) space to store the cleaned string. This could be optimized to O(1) by processing the original string directly, but would make the code more complex.
Here's the truth table for (p q) (q r):
| p | q | r | p q | q | q r | (p q) (q r) |
|---|---|---|---|---|---|---|
| T | T | T | T | F | F | T |
| T | T | F | T | F | F | T |
| T | F | T | F | T | T | T |
| T | F | F | F | T | F | F |
| F | T | T | F | F | F | F |
| F | T | F | F | F | F | F |
| F | F | T | F | T | T | T |
| F | F | F | F | T | F | F |
The expression (p q) (q r) evaluates to true in the following cases:
We can simplify the expression by noticing a pattern:
This shows that the expression is equivalent to (q p) (q r), which is a form of a conditional statement.
