- Trending Now
- Foundational Courses
- Data Science
- Practice Problem
- Machine Learning
- System Design
- DevOps Tutorial
CBSE Class 11 | Problem Solving Methodologies
Problem solving process.
The process of problem-solving is an activity which has its ingredients as the specification of the program and the served dish is a correct program. This activity comprises of four steps : 1. Understanding the problem: To solve any problem it is very crucial to understand the problem first. What is the desired output of the code and how that output can be generated? The obvious and essential need to generate the output is an input. The input may be singular or it may be a set of inputs. A proper relationship between the input and output must be drawn in order to solve the problem efficiently. The input set should be complete and sufficient enough to draw the output. It means all the necessary inputs required to compute the output should be present at the time of computation. However, it should be kept in mind that the programmer should ensure that the minimum number of inputs should be there. Any irrelevant input only increases the size of and memory overhead of the program. Thus Identifying the minimum number of inputs required for output is a crucial element for understanding the problem.
2. Devising the plan: Once a problem has been understood, a proper action plan has to be devised to solve it. This is called devising the plan. This step usually involves computing the result from the given set of inputs. It uses the relationship drawn between inputs and outputs in the previous step. The complexity of this step depends upon the complexity of the problem at hand.
3. Executing the plan: Once the plan has been defined, it should follow the trajectory of action while ensuring the plan’s integrity at various checkpoints. If any inconsistency is found in between, the plan needs to be revised.
4. Evaluation: The final result so obtained must be evaluated and verified to see if the problem has been solved satisfactorily.
Problem Solving Methodology(The solution for the problem)
The methodology to solve a problem is defined as the most efficient solution to the problem. Although, there can be multiple ways to crack a nut, but a methodology is one where the nut is cracked in the shortest time and with minimum effort. Clearly, a sledgehammer can never be used to crack a nut. Under problem-solving methodology, we will see a step by step solution for a problem. These steps closely resemble the software life cycle . A software life cycle involves several stages in a program’s life cycle. These steps can be used by any tyro programmer to solve a problem in the most efficient way ever. The several steps of this cycle are as follows :
Step by step solution for a problem (Software Life Cycle) 1. Problem Definition/Specification: A computer program is basically a machine language solution to a real-life problem. Because programs are generally made to solve the pragmatic problems of the outside world. In order to solve the problem, it is very necessary to define the problem to get its proper understanding. For example, suppose we are asked to write a code for “ Compute the average of three numbers”. In this case, a proper definition of the problem will include questions like : “What exactly does average mean?” “How to calculate the average?”
Once, questions like these are raised, it helps to formulate the solution of the problem in a better way. Once a problem has been defined, the program’s specifications are then listed. Problem specifications describe what the program for the problem must do. It should definitely include :
what is the input set of the program
What is the desired output of the program and in what form the output is desired?
2. Problem Analysis (Breaking down the solution into simple steps): This step of solving the problem follows a modular approach to crack the nut. The problem is divided into subproblems so that designing a solution to these subproblems gets easier. The solutions to all these individual parts are then merged to get the final solution of the original problem. It is like divide and merge approach.
Modular Approach for Programming :
The process of breaking a large problem into subproblems and then treating these individual parts as different functions is called modular programming. Each function behaves independent of another and there is minimal inter-functional communication. There are two methods to implement modular programming :
- Top Down Design : In this method, the original problem is divided into subparts. These subparts are further divided. The chain continues till we get the very fundamental subpart of the problem which can’t be further divided. Then we draw a solution for each of these fundamental parts.
- Bottom Up Design : In this style of programming, an application is written by using the pre-existing primitives of programming language. These primitives are then amalgamated with more complicated features, till the application is written. This style is just the reverse of the top-down design style.
3. Problem Designing: The design of a problem can be represented in either of the two forms :
The ways to execute any program are of three categories:
- Sequence Statements Here, all the instructions are executed in a sequence, that is, one after the another, till the program is executed.
- Selection Statements As it is self-clear from the name, in these type of statements the whole set of instructions is not executed. A selection has to be made. A selected number of instructions are executed based on some condition. If the condition holds true then some part of the instruction set is executed, otherwise, another part of the set is executed. Since this selection out of the instruction set has to be made, thus these type of instructions are called Selection Statements.
Identification of arithmetic and logical operations required for the solution : While writing the algorithm for a problem, the arithmetic and logical operations required for the solution are also usually identified. They help to write the code in an easier manner because the proper ordering of the arithmetic and logical symbols is necessary to determine the correct output. And when all this has been done in the algorithm writing step, it just makes the coding task a smoother one.
- Flow Chart : Flow charts are diagrammatic representation of the algorithm. It uses some symbols to illustrate the starting and ending of a program along with the flow of instructions involved in the program.
4. Coding: Once an algorithm is formed, it can’t be executed on the computer. Thus in this step, this algorithm has to be translated into the syntax of a particular programming language. This process is often termed as ‘coding’. Coding is one of the most important steps of the software life cycle. It is not only challenging to find a solution to a problem but to write optimized code for a solution is far more challenging.
Writing code for optimizing execution time and memory storage : A programmer writes code on his local computer. Now, suppose he writes a code which takes 5 hours to get executed. Now, this 5 hours of time is actually the idle time for the programmer. Not only it takes longer time, but it also uses the resources during that time. One of the most precious computing resources is memory. A large program is expected to utilize more memory. However, memory utilization is not a fault, but if a program is utilizing unnecessary time or memory, then it is a fault of coding. The optimized code can save both time and memory. For example, as has been discussed earlier, by using the minimum number of inputs to compute the output , one can save unnecessary memory utilization. All such techniques are very necessary to be deployed to write optimized code. The pragmatic world gives reverence not only to the solution of the problem but to the optimized solution. This art of writing the optimized code also called ‘competitive programming’.
5. Program Testing and Debugging: Program testing involves running each and every instruction of the code and check the validity of the output by a sample input. By testing a program one can also check if there’s an error in the program. If an error is detected, then program debugging is done. It is a process to locate the instruction which is causing an error in the program and then rectifying it. There are different types of error in a program : (i) Syntax Error Every programming language has its own set of rules and constructs which need to be followed to form a valid program in that particular language. If at any place in the entire code, this set of rule is violated, it results in a syntax error. Take an example in C Language
In the above program, the syntax error is in the first printf statement since the printf statement doesn’t end with a ‘;’. Now, until and unless this error is not rectified, the program will not get executed.
Once the error is rectified, one gets the desired output. Suppose the input is ‘good’ then the output is : Output:
(ii) Logical Error An error caused due to the implementation of a wrong logic in the program is called logical error. They are usually detected during the runtime. Take an example in C Language:
In the above code, the ‘for’ loop won’t get executed since n has been initialized with the value of 11 while ‘for’ loop can only print values smaller than or equal to 10. Such a code will result in incorrect output and thus errors like these are called logical errors. Once the error is rectified, one gets the desired output. Suppose n is initialised with the value ‘5’ then the output is : Output:
(iii) Runtime Error Any error which causes the unusual termination of the program is called runtime error. They are detected at the run time. Some common examples of runtime errors are : Example 1 :
If during the runtime, the user gives the input value for B as 0 then the program terminates abruptly resulting in a runtime error. The output thus appears is : Output:
Example 2 : If while executing a program, one attempts for opening an unexisting file, that is, a file which is not present in the hard disk, it also results in a runtime error.
6. Documentation : The program documentation involves :
- Problem Definition
- Problem Design
- Documentation of test perform
- History of program development
7. Program Maintenance: Once a program has been formed, to ensure its longevity, maintenance is a must. The maintenance of a program has its own costs associated with it, which may also exceed the development cost of the program in some cases. The maintenance of a program involves the following :
- Detection and Elimination of undetected errors in the existing program.
- Modification of current program to enhance its performance and adaptability.
- Enhancement of user interface
- Enriching the program with new capabilities.
- Updation of the documentation.
Control Structure- Conditional control and looping (finite and infinite)
There are codes which usually involve looping statements. Looping statements are statements in which instruction or a set of instructions is executed multiple times until a particular condition is satisfied. The while loop, for loop, do while loop, etc. form the basis of such looping structure. These statements are also called control structure because they determine or control the flow of instructions in a program. These looping structures are of two kinds :
In the above program, the ‘for’ loop gets executed only until the value of i is less than or equal to 10. As soon as the value of i becomes greater than 10, the while loop is terminated. Output:
In the above code, one can easily see that the value of n is not getting incremented. In such a case, the value of n will always remain 1 and hence the while loop will never get executed. Such loop is called an infinite loop. Output:
Similar Reads
- CBSE Class 11 | Problem Solving Methodologies Problem Solving Process The process of problem-solving is an activity which has its ingredients as the specification of the program and the served dish is a correct program. This activity comprises of four steps : 1. Understanding the problem: To solve any problem it is very crucial to understand th 13 min read
- Critical Thinking Math Problems Ability to make decisions by the application of logical, sceptic, and objective analyses and evaluations of data, arguments, and other evidence is known as critical thinking. Regarding mathematics, critical thinking is not only about making calculations but also involves logical reasoning, pattern r 10 min read
- Class 11 NCERT Solutions - Chapter 1 Sets - Exercise 1.6 Chapter 1 of Class 11 NCERT Mathematics focuses on "Sets" a fundamental concept in mathematics that provides the basis for the various mathematical structures and operations. Understanding sets is crucial for grasping more advanced topics in algebra, calculus, and discrete mathematics. Exercise 1.6 8 min read
- NCERT Solutions for Class 9 English Moments Chapter 1 The Lost Child We have tried to provide NCERT Solutions for Supplementary English Class 9 Chapter 1 The Lost Child covering each & every question of Supplementary English. Students will improve their answer writing skills by referring to the following NCERT Solutions for Class 9 Supplementary English Moments. 6 min read
- NCERT Solutions for Class 9 English Beehive Chapter 3 The Little Girl We have tried to provide NCERT Solutions for Class 9 English- Chapter 3 The Little Girl covering each and every question of the textbook Beehive. Students will improve their answer writing skills by referring to the following NCERT Solutions for Class 9 English Beehive. The following NCERT Solutions 13 min read
- NCERT Solutions for Class 9 English Beehive Chapter 1 The Fun They Had We have tried to provide NCERT Solutions for Class 9 English Chapter 1 The Fun They Had covering each and every question of the textbook Beehive. Students will improve their answer writing skills by referring to the following NCERT Solutions for Class 9 English Beehive. The following NCERT Solutions 14 min read
- CBSE 10th Board Exam Experience For every Indian student, the Central Board of Secondary Education (CBSE) 10th board exams mark a significant milestone in their academic journey. These exams are not just assessments of academic prowess; they are rites of passage, symbolizing the transition from secondary to higher secondary educat 4 min read
- How to read Competitive Programming Questions? Competitive Programming is considered as a sport in the field of computer science. The culture of this sport is growing day by day and a lot of people are also considering this as a career choice. So, to help the participants with improving their efficiency in this sport, in this post, we have tried 5 min read
- Non Verbal Reasoning : Paper Cutting Non-verbal reasoning is integral to the Staff Selection Commission (SSC) Combined Graduate Level (CGL) examination, which no student should avoid. You can take a good lead in this section with practice. One common and very important topic of Non-Verbal reasoning is paper cutting, which involves anal 6 min read
- Non-Verbal Reasoning : Dot Situation SSC CGL examination has one of the most important sections i.e. Non-Verbal Reasoning section. It includes many important topics and out of which Dot Situation-related questions are frequently asked. Sometimes, Dot situation-based questions can be tricky and confusing, but with continuous practice an 4 min read
- Accolite Interview Experience | Set 4 (On-Campus) Round 1 (Written) Around 140 students appeared for the offline test. There were 20 MCQs that to be done in (30 minutes), questions were from OS,DBMS,Datastructures. After that coding round was there (paper coding) in which 3 questions were given and we have to attempt any 2 (1 hour) 1. Write your ow 8 min read
- Points to focus on while doing Competitive Programming Competitive Programming is vital for one’s development in the coding field. This article is going to discuss some basics points one should keep in mind while competing. Make a list of functions to perform tasks that are encountered frequently in questions and add them to your code in the form of a t 5 min read
- OLA Interview Experience | Set 11 ( For Internship) Round 1 (Online Test): Four Programming Questions- a) Given a string find number of different substrings that are palindromes. b) In a matrix we can destruct it's one column by vanishing any of the element in column . We have to destruct the matrix completely so that sum of the elements destucted by 2 min read
- Final Exam | Google Kickstart 2021 Round D It's time for the final exam in algorithms and data structures! Edsger prepared N sets of problems. Each set consists of problems in an increasing difficulty sequence; the i-th set can be described by two integers Ai and Bi (Ai≤Bi), which denotes that this set contains problems with difficulties Ai, 12 min read
- Cisco Interview Experience | Set 9 (For Experienced) Written Test: 1) 15 Aptitude Questions 2) 25 CS Fundamentals & Couple of output questions. 3) Coding Question: A thief trying to escape from a jail has to cross 'N' walls each with varying heights. He climbs 'X' feet every time. But, due to the slippery nature of those walls, every times he slip 2 min read
- Amazon Interview | Set 55 (On-Campus) Online Test on InterviewStreet: 18 MCQs (Normal C loop questions, networking, dbms, os, analytical) 2 Coding questions 1. Check if an undirected graph is a tree or not. 2. Given an array of integers, print the 2 elements with least absolute difference. Interview Rounds:- Round 1: Tell me about yours 4 min read
- MakeMyTrip Interview Experience | Set 6 (Online Coding) Round-1: Online test There were 2 sections – Aptitude and Coding Section A- 20 MCQ's on General Aptitude. Section B- There were 3 coding questions. 1) Given an array and 2 numbers l,r find the number of elements in the array in between l and r; 2) Calculate a power b (b -> [1,1000000000] (required a 3 min read
- Microsoft Interview experience | Set 98 (On Campus for IDC) Round 1 : (1hr 15 min) Online test on CoCubes contains 3 Coding Questions Calculate difficulty of a given sentence. Where difficulty of a word is: Word is hard if it has 4 consecutive consonants or number of consonants are more than number of vowels else word is easy. Difficulty of sentence is defin 3 min read
- MakeMyTrip Interview Experience | Set 8 (On-Campus) MakeMyTrip recently visited our campus. There were 4 rounds. Online Round ( 1 Hour ) This round consisted of 20 aptitude questions and 3 coding Questions. Coding Questions: 1. Find ‘x’ in the equation. The input is in the form of a string. Equation consisted of addition operator only and 2 integers 3 min read
- School Programming
Improve your Coding Skills with Practice
What kind of Experience do you want to share?
How to think like a programmer — lessons in problem solving
By Richard Reis
If you’re interested in programming, you may well have seen this quote before:
“Everyone in this country should learn to program a computer, because it teaches you to think.” — Steve Jobs
You probably also wondered what does it mean, exactly, to think like a programmer? And how do you do it??
Essentially, it’s all about a more effective way for problem solving .
In this post, my goal is to teach you that way.
By the end of it, you’ll know exactly what steps to take to be a better problem-solver.
Why is this important?
Problem solving is the meta-skill.
We all have problems. Big and small. How we deal with them is sometimes, well…pretty random.
Unless you have a system, this is probably how you “solve” problems (which is what I did when I started coding):
- Try a solution.
- If that doesn’t work, try another one.
- If that doesn’t work, repeat step 2 until you luck out.
Look, sometimes you luck out. But that is the worst way to solve problems! And it’s a huge, huge waste of time.
The best way involves a) having a framework and b) practicing it.
“Almost all employers prioritize problem-solving skills first. Problem-solving skills are almost unanimously the most important qualification that employers look for….more than programming languages proficiency, debugging, and system design. Demonstrating computational thinking or the ability to break down large, complex problems is just as valuable (if not more so) than the baseline technical skills required for a job.” — Hacker Rank ( 2018 Developer Skills Report )
Have a framework
To find the right framework, I followed the advice in Tim Ferriss’ book on learning, “ The 4-Hour Chef ”.
It led me to interview two really impressive people: C. Jordan Ball (ranked 1st or 2nd out of 65,000+ users on Coderbyte ), and V. Anton Spraul (author of the book “ Think Like a Programmer: An Introduction to Creative Problem Solving ”).
I asked them the same questions, and guess what? Their answers were pretty similar!
Soon, you too will know them.
Sidenote: this doesn’t mean they did everything the same way. Everyone is different. You’ll be different. But if you start with principles we all agree are good, you’ll get a lot further a lot quicker.
“The biggest mistake I see new programmers make is focusing on learning syntax instead of learning how to solve problems.” — V. Anton Spraul
So, what should you do when you encounter a new problem?
Here are the steps:
1. Understand
Know exactly what is being asked. Most hard problems are hard because you don’t understand them (hence why this is the first step).
How to know when you understand a problem? When you can explain it in plain English.
Do you remember being stuck on a problem, you start explaining it, and you instantly see holes in the logic you didn’t see before?
Most programmers know this feeling.
This is why you should write down your problem, doodle a diagram, or tell someone else about it (or thing… some people use a rubber duck ).
“If you can’t explain something in simple terms, you don’t understand it.” — Richard Feynman
Don’t dive right into solving without a plan (and somehow hope you can muddle your way through). Plan your solution!
Nothing can help you if you can’t write down the exact steps.
In programming, this means don’t start hacking straight away. Give your brain time to analyze the problem and process the information.
To get a good plan, answer this question:
“Given input X, what are the steps necessary to return output Y?”
Sidenote: Programmers have a great tool to help them with this… Comments!
Pay attention. This is the most important step of all.
Do not try to solve one big problem. You will cry.
Instead, break it into sub-problems. These sub-problems are much easier to solve.
Then, solve each sub-problem one by one. Begin with the simplest. Simplest means you know the answer (or are closer to that answer).
After that, simplest means this sub-problem being solved doesn’t depend on others being solved.
Once you solved every sub-problem, connect the dots.
Connecting all your “sub-solutions” will give you the solution to the original problem. Congratulations!
This technique is a cornerstone of problem-solving. Remember it (read this step again, if you must).
“If I could teach every beginning programmer one problem-solving skill, it would be the ‘reduce the problem technique.’ For example, suppose you’re a new programmer and you’re asked to write a program that reads ten numbers and figures out which number is the third highest. For a brand-new programmer, that can be a tough assignment, even though it only requires basic programming syntax. If you’re stuck, you should reduce the problem to something simpler. Instead of the third-highest number, what about finding the highest overall? Still too tough? What about finding the largest of just three numbers? Or the larger of two? Reduce the problem to the point where you know how to solve it and write the solution. Then expand the problem slightly and rewrite the solution to match, and keep going until you are back where you started.” — V. Anton Spraul
By now, you’re probably sitting there thinking “Hey Richard... That’s cool and all, but what if I’m stuck and can’t even solve a sub-problem??”
First off, take a deep breath. Second, that’s fair.
Don’t worry though, friend. This happens to everyone!
The difference is the best programmers/problem-solvers are more curious about bugs/errors than irritated.
In fact, here are three things to try when facing a whammy:
- Debug: Go step by step through your solution trying to find where you went wrong. Programmers call this debugging (in fact, this is all a debugger does).
“The art of debugging is figuring out what you really told your program to do rather than what you thought you told it to do.”” — Andrew Singer
- Reassess: Take a step back. Look at the problem from another perspective. Is there anything that can be abstracted to a more general approach?
“Sometimes we get so lost in the details of a problem that we overlook general principles that would solve the problem at a more general level. […] The classic example of this, of course, is the summation of a long list of consecutive integers, 1 + 2 + 3 + … + n, which a very young Gauss quickly recognized was simply n(n+1)/2, thus avoiding the effort of having to do the addition.” — C. Jordan Ball
Sidenote: Another way of reassessing is starting anew. Delete everything and begin again with fresh eyes. I’m serious. You’ll be dumbfounded at how effective this is.
- Research: Ahh, good ol’ Google. You read that right. No matter what problem you have, someone has probably solved it. Find that person/ solution. In fact, do this even if you solved the problem! (You can learn a lot from other people’s solutions).
Caveat: Don’t look for a solution to the big problem. Only look for solutions to sub-problems. Why? Because unless you struggle (even a little bit), you won’t learn anything. If you don’t learn anything, you wasted your time.
Don’t expect to be great after just one week. If you want to be a good problem-solver, solve a lot of problems!
Practice. Practice. Practice. It’ll only be a matter of time before you recognize that “this problem could easily be solved with .”
How to practice? There are options out the wazoo!
Chess puzzles, math problems, Sudoku, Go, Monopoly, video-games, cryptokitties, bla… bla… bla….
In fact, a common pattern amongst successful people is their habit of practicing “micro problem-solving.” For example, Peter Thiel plays chess, and Elon Musk plays video-games.
“Byron Reeves said ‘If you want to see what business leadership may look like in three to five years, look at what’s happening in online games.’ Fast-forward to today. Elon [Musk], Reid [Hoffman], Mark Zuckerberg and many others say that games have been foundational to their success in building their companies.” — Mary Meeker ( 2017 internet trends report )
Does this mean you should just play video-games? Not at all.
But what are video-games all about? That’s right, problem-solving!
So, what you should do is find an outlet to practice. Something that allows you to solve many micro-problems (ideally, something you enjoy).
For example, I enjoy coding challenges. Every day, I try to solve at least one challenge (usually on Coderbyte ).
Like I said, all problems share similar patterns.
That’s all folks!
Now, you know better what it means to “think like a programmer.”
You also know that problem-solving is an incredible skill to cultivate (the meta-skill).
As if that wasn’t enough, notice how you also know what to do to practice your problem-solving skills!
Phew… Pretty cool right?
Finally, I wish you encounter many problems.
You read that right. At least now you know how to solve them! (also, you’ll learn that with every solution, you improve).
“Just when you think you’ve successfully navigated one obstacle, another emerges. But that’s what keeps life interesting.[…] Life is a process of breaking through these impediments — a series of fortified lines that we must break through. Each time, you’ll learn something. Each time, you’ll develop strength, wisdom, and perspective. Each time, a little more of the competition falls away. Until all that is left is you: the best version of you.” — Ryan Holiday ( The Obstacle is the Way )
Now, go solve some problems!
And best of luck ?
Special thanks to C. Jordan Ball and V. Anton Spraul . All the good advice here came from them.
Thanks for reading! If you enjoyed it, test how many times can you hit in 5 seconds. It’s great cardio for your fingers AND will help other people see the story.
If you read this far, thank the author to show them you care. Say Thanks
Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started
COMMENTS
Let’s walk through solving a simple coding problem using the four-step problem-solving method. This allows us to see the method in action as we learn it. We'll use JavaScript as our language of choice. Here’s the problem: Create a function that adds together two numbers and returns that value. There are four steps to the problem-solving method:
Computer programming is not just programming language syntax and using a development environment. At its core, computer programming is solving problems. We will now turn our attention to a structured methodology you can use to construct solutions for a given problem.
In this article, we will explore a variety of basic programming problems that are essential for every aspiring coder to understand. By delving into these foundational challenges, you will gain valuable insights into problem-solving techniques and build a strong foundation for your programming journey.
These steps can be used by any tyro programmer to solve a problem in the most efficient way ever. The several steps of this cycle are as follows : 1. Problem Definition/Specification: A computer program is basically a machine language solution to a real-life problem.
Essentially, it’s all about a more effective way for problem solving. In this post, my goal is to teach you that way. By the end of it, you’ll know exactly what steps to take to be a better problem-solver. Why is this important? Problem solving is the meta-skill. We all have problems. Big and small.
In the world of programming, problem-solving is the cornerstone of success. Whether you're a seasoned coder or just starting your journey, the ability to tackle challenges effectively is a skill that will set you apart; finding solutions to issues that arise in the development process.