Q1. A train traveling at a speed of 60 km/hr takes 30 seconds to cross a bridge that is 400 meters long. What is the length of the train?
Q2. If it takes 6 workers 8 days to build a wall, how many days would it take for 9 workers to build the same wall?
Q3. If the ratio of the circumference of two circles is 3:4, what is the ratio of their areas?
Q4. Explain how generators work in Python and give an example of how you would use them to iterate over a large dataset efficiently.
Q5. How do you optimize the performance of MySQL queries and what tools or techniques do you use?
Answers

Let’s first convert the train’s speed to meters per second: 60 km/hr = (60*1000)/3600 = 16.67 m/s. The time taken to cross the bridge is 30 seconds. Therefore, distance traveled by train during this time is 400 meters + length of the train. We can write the equation as 16.67 * 30 = 400 + length of train. Solving for length of the train, we get length of train = 150 meters.

The number of workers and the time they take to complete a task are inversely proportional. We can use the formula: (number of workers) * (time taken) = constant. Let’s call this constant K. So we have, 6 * 8 = K. Therefore, K = 48. To find the time taken by 9 workers, we can write: 9 * T = K, where T is the time taken. Solving for T, we get T = 48/9 = 5.33 days (rounded off to 2 decimal places).

Let the circumference of the first circle be 3x and that of the second circle be 4x. The radius of the first circle will be 3x/(2pi) and that of the second circle will be 4x/(2pi). Therefore, the area of the first circle will be (3x/(2pi))^2pi = (9/4)x^2pi and that of the second circle will be (4x/(2pi))^2pi = 4x^2pi. Therefore, the ratio of their areas will be (9/4)x^2pi : 4x^2pi, which simplifies to 9:16.

In Python, a generator is a type of iterator that allows you to iterate over a large dataset efficiently without having to load the entire dataset into memory at once. A generator produces a sequence of values onthefly, as you iterate over it, using the
yield
keyword instead of thereturn
keyword.
To create a generator in Python, you can define a function that uses the yield
keyword instead of return
to produce a sequence of values. When the function is called, it returns a generator object that you can iterate over using a for
loop or the next()
function.
Example:
def read_large_file(file_path):
with open(file_path) as f:
for line in f:
yield line
for line in read_large_file(‘large_file.txt’):
print(line)
 To optimize the performance of MySQL queries, some tools and techniques that can be used include:
 Indexing: Creating indexes on the columns that are frequently used in queries can speed up data retrieval.
 Query optimization: Rewriting queries to use more efficient algorithms or optimizing the structure of the queries can improve performance.
 Caching: Caching the results of frequently used queries can reduce the amount of time spent retrieving data from the database.
 Load balancing: Distributing the workload across multiple servers can help to handle high traffic loads and improve performance.
 Profiling: Using profiling tools to identify performance bottlenecks and optimize queries accordingly.