How did the Knights of Labor and the American Federation of Labor try to solve the problems of workers or farmers? I mean what was the problem that each organization tried to solve and how did they solve it?
Both the Knights of Labor and the AFL had essentially the same goal and wanted to solve the same immediate problem. The differences between them had to do with how they wanted to solve the problem.
The immediate problem for workers during this time was the fact that they were often treated poorly by their employers. Workers often had to work long hours in dangerous conditions for low pay. The unions wanted to solve these problems, giving workers a better life.
The two unions that you mention went about trying to solve this problem very differently. The Knights of Labor were a relatively radical union. They felt that it was necessary to change the entire American economic system in order to gain better lives for workers. They wanted to create a more socialist system in which the workers owned and operated the factories and other places of business where they worked. The Knights wanted to include all workers (including blacks, women, immigrants, and unskilled workers) in their union. This was all very different from what the AFL wanted. The AFL was much more conservative. It did not want to change the American economic system. Instead, it just wanted that system to treat its members better. It did not seek radical social change and asked only for better working conditions and wages. It did not accept blacks or women and it tried to organize only the top stratum of workers—those who had the greatest skills and could not be easily replaced by their bosses.
Thus, while both of these unions wanted better lives and working conditions for their members, they tried to achieve this in very different ways.