I'm not able to write even small logics for programs. How can I improve my logical thinking and problem solving?

First things first, read the question properly.

Write down the data given.

Read the question again, this is to make sure you aren't missing anything.

There is a fair chance you might miss something and get them in the second reading.

At this stage, you have the correct data.

Now think of what you can do about solving the question.

If you've got no idea what to do and you've already spent a lot of time trying to figure out something, DO NOT CHECK THE ANSWER,leave it.

Your sub consious will take care of it.

It's been a day and you still didn't figure it out? This probably might be the best time you chec

First things first, read the question properly.

Write down the data given.

Read the question again, this is to make sure you aren't missing anything.

There is a fair chance you might miss something and get them in the second reading.

At this stage, you have the correct data.

Now think of what you can do about solving the question.

If you've got no idea what to do and you've already spent a lot of time trying to figure out something, DO NOT CHECK THE ANSWER,leave it.

Your sub consious will take care of it.

It's been a day and you still didn't figure it out? This probably might be the best time you checked the solution.

Reason to leave it to the subconscious:

1.It provides you an answer

It's all good in this case,you got it.

2.It doesn't.

It's all good in this case too :), guess why?

Since you've thought of solving it in all possibleways you can , you never fail to the same or related questions in future.

There might be a lot of students around you who are brilliant in figuring out the logic, they might be that way from the start..DO NOT GET DISHEARTENED, feel happy for them.

Practice never fails and you don't need to be brilliant to practice.

Practice a lot, push your limits, Give it time and no doubt you'll be on par with the best.

Cheers, All the best :D

Practice !!! Yes. Only practice can help you improve your logical thinking.

Logical thinking and problem solving are not only limited to Programming, indeed, you will need them in every phase of life.

Now coming to your question, To write a logic for a program, first of all, get hold on the question or as they say, “READ BETWEEN LINES”.

Then, try to break your problems into smaller pieces as this brings a larger problem to a smaller scope. Then, try to solve every piece individually keeping one concept in mind ‘DRY’ i.e Don’t repeat yourself.

Then, last but not the least, connect those pieces with

Practice !!! Yes. Only practice can help you improve your logical thinking.

Logical thinking and problem solving are not only limited to Programming, indeed, you will need them in every phase of life.

Now coming to your question, To write a logic for a program, first of all, get hold on the question or as they say, “READ BETWEEN LINES”.

Then, try to break your problems into smaller pieces as this brings a larger problem to a smaller scope. Then, try to solve every piece individually keeping one concept in mind ‘DRY’ i.e Don’t repeat yourself.

Then, last but not the least, connect those pieces with each other and try to understand the role of each piece on a larger scale.

With this approach, Just practice and practice and practice !!!!!

I hope this will be helpful.

Cheers!!

Obvious answer: Practice

Next question “How to practice?”

Keep the solution away from you. Relax. Do not put yourself under any constraints such as time.

Understand the problem. Try to break it into small pieces if you can. Don’t worry if you are not able to understand the complete problem. If you understand a part of problem, work with that.

Take a piece of paper and start developing logic on that paper. Make use of small diagrams to develop your logic. Diagrams such as boxes for arrays, arrows for control flow etc. You don’t have to think about syntax or even programming language in which you wa

Obvious answer: Practice

Next question “How to practice?”

Keep the solution away from you. Relax. Do not put yourself under any constraints such as time.

Understand the problem. Try to break it into small pieces if you can. Don’t worry if you are not able to understand the complete problem. If you understand a part of problem, work with that.

Take a piece of paper and start developing logic on that paper. Make use of small diagrams to develop your logic. Diagrams such as boxes for arrays, arrows for control flow etc. You don’t have to think about syntax or even programming language in which you want to write the code in.

If you have fully understood a part of problem and have developed logic for it, you can go ahead and code that. Or you can spend time solving other parts. It’s your choice how you want to do it.

Stay relaxed the whole time. There is no hurry. Take your time.

Keep practicing this way and gradually your problem solving will improve.

Last thing: If you have found your answer, ask next question.

First read the question carefully. After that thnk what can you do in the question write what you think about question.

Then think about what are the accpect you need to solve that question like variable character etc. After that try to use that thing into a mathematical form to solve the problem .

After all that you will take about 1 week to increase your logical thinking power than the main accpect you need is a large amount of practice. Try to think the solution of a problem if you are playing, moving with friends etc. That how your logical thinking power increase.

I also faced this same problem in the beginning.The only way to improve your coding skill, that is logical thinking skills in programming,is only through practice.You got to practice many problems from the various websites like

1.hackerrank

2.codechef

3.guvi(for beginners guvi is good).

If you are not able to solve don't get tensed, because I felt so.Just refer the submitted solutions of that program..Then analyse it why he did so..Then save programs that you felt good in GitHub or in your local system as notepad or word..refer it whenever you get time..after a 4 or 6 months,you will get somewhat

I also faced this same problem in the beginning.The only way to improve your coding skill, that is logical thinking skills in programming,is only through practice.You got to practice many problems from the various websites like

1.hackerrank

2.codechef

3.guvi(for beginners guvi is good).

If you are not able to solve don't get tensed, because I felt so.Just refer the submitted solutions of that program..Then analyse it why he did so..Then save programs that you felt good in GitHub or in your local system as notepad or word..refer it whenever you get time..after a 4 or 6 months,you will get somewhat expert..you will be cracking the logic as soon as you read the program.

I hope this helps you..All the best..Try..

I can only tell what has worked for me:

  1. Knowing a source of truth, experience? intuition? For me it is the former
  2. Given that you know where you can get your truths from you can start reasoning. Two fundamental things are needed for reasoning axioms, and rules of inference, you get both from experience
  3. Mindfulness meditation (focus on your breath), I do about 1/2 hr a day. I have written a whole blog about this
  4. Getting good sleep
  5. Practice and focus on domain

A2A

Let me try to explain with simple example— Task is to find student whose rank is first and last in class. Before you write code, follow these steps. These will help you in resolving your problem.

  • Understand what you want to do carefully and define correct problem definition.

we can define our problem as “Find Max and Min Marks from list”

  • Break down main task into smaller tasks

Task looks easier when you devide it into smaller tasks. Here, You can break down it as--

  1. Read all student’s names and marks.
  2. Sort Students by marks in descending order
  3. Print name of student with first rank as first record f

A2A

Let me try to explain with simple example— Task is to find student whose rank is first and last in class. Before you write code, follow these steps. These will help you in resolving your problem.

  • Understand what you want to do carefully and define correct problem definition.

we can define our problem as “Find Max and Min Marks from list”

  • Break down main task into smaller tasks

Task looks easier when you devide it into smaller tasks. Here, You can break down it as--

  1. Read all student’s names and marks.
  2. Sort Students by marks in descending order
  3. Print name of student with first rank as first record from list
  4. Print name of student with last rank as last record from list

Go further and break down these task again into smaller tasks.

For Ex: Read all student’s names and marks can be break down as follow:

  1. Define data-structure or variables to hold all student’s names and marks.
  2. Define input method for reading data.
  3. Get input and validate.
  4. Add input to defined database (variable or database)
  • Always look for alternative.

There is always another way to do it. Before you proceed, check if there is any alternative way of solving problem and select simplest and easiest alternative.

For example in our case, we can solve it other way as follow :

1) Read student’s name and marks

2) Save it into database.

3) Fetch student with Max value of mark from database using database query, print as first rank

4)Fetch student with min value of mark from database using database query, print as last rank

  • Analyze

re-think on what you have decided and consider all possibilities to ensure 100% correctness.

Now, as you have list of small task, star coding. Start with simplest task.

Apply above for any programm you want write. If you still find it difficult, For few days, forget about programming and start solving logical puzzles. once you feel you are comfortable with it, come back to programming.

Luminous Learning

Starter Puzzles

Once you feel more than comfortable with solving these puzzles, come back to programming and try to follow these instructions.

Above All-- as mentioned in every answer to this question- Practice!! Any technique will not work without practice.

First of all “it’s not hard”.

Think “it’s easy and I can do it” , half of the work is done.

  1. Visualize the program output screen . Think about the number of inputs , outputs and printed statements.
  2. Think about each input and output from start of the program. Understand why you need the inputs and what operation should be done on each of them.
  3. Then write down the operation code for given inputs / the program ( part by part ). Write down the code for the program by breaking down the whole program into several parts. Write them in a sheet of paper ( do not code directly ).
  4. Arrange all the parts in orde

First of all “it’s not hard”.

Think “it’s easy and I can do it” , half of the work is done.

  1. Visualize the program output screen . Think about the number of inputs , outputs and printed statements.
  2. Think about each input and output from start of the program. Understand why you need the inputs and what operation should be done on each of them.
  3. Then write down the operation code for given inputs / the program ( part by part ). Write down the code for the program by breaking down the whole program into several parts. Write them in a sheet of paper ( do not code directly ).
  4. Arrange all the parts in order . Go through it .Check the logic ( will be correct if you follow the above given points) . Even if it wrong it will be easier to correct on a sheet of paper rather that finding it out from source code on the screen.

That’s it . You got it !

ENJOY CODING ..

You should practice. The more you think, the better you will be able to solve. You should have a decent knowlege of mathematics and also the programming constructs like loops and conditional statements. Also, the understanding of simple data structures can be helpful.

For building your logic and enhancing the problem solving ability, you can refer the following books:

How to Solve It by George Polya and Problem Solving and OOP by Maureen Sprankle.

Good luck writing Algorithms…!!! :)

Don’t start solving something head on. Break it into parts, adopt a modular approach. Do one tiny part at time. This may not sound terribly important, but it helps for sure.

__Suyash

I sat in my introduction to programming course, listening around the room as the teacher reported the results of our first project. This class was part of a EE program, many were not there to learn to code, but the program reasonably expected that the EE students at least have a passing knowledge of programming concepts. Sinking deeper and deeper into my chair, as I realized that amongst this crowd (300+ students) of would be Electrical Engineers, capable of advanced calculus and understanding the complex concepts of physics, I was exceptional. My score was among those that set the curve, and

I sat in my introduction to programming course, listening around the room as the teacher reported the results of our first project. This class was part of a EE program, many were not there to learn to code, but the program reasonably expected that the EE students at least have a passing knowledge of programming concepts. Sinking deeper and deeper into my chair, as I realized that amongst this crowd (300+ students) of would be Electrical Engineers, capable of advanced calculus and understanding the complex concepts of physics, I was exceptional. My score was among those that set the curve, and the average was far away.

TL;DR

If you are doing this for the money do yourself a favor and stop now. If you succeed in learning, you will not enjoy it and it is unlikely that you will be very good at it. It is still work, and at times very emotionally and mentally draining. If your primary driver is the money, do yourself and the industry a favor, look elsewhere, you will find money quicker somewhere else. If money is your motivation you will not likely succeed in finding it as a programmer.

Having now worked multiple decades in the industry, I have found that there are those who can and there are those that cannot. The concepts elude them but for whatever reason, there are many, they just cannot code effectively.

I have many nephews, and to some extent or another, most have approached me at one time or another about learning to be a programmer. I am eager to teach anyone willing to learn. I love to code, and want to share that love. Considering two of my nephews who were more interested than the others, the story is telling. With both, I made the same offer. I opened my library to them, I offered my time to tutor and provided lists of other resources. However, I did not bring the books too them, I did not schedule the time for them, nor did I force them to look at those resources. Recently, now a decade later, one approached me about learning to program again. Desperate to change his life circumstances. Again I made the same offers. The other recently submitted his resume to me, for consideration of a job that I need to fill. I was skeptical, but upon review, his resume provided the qualifications needed to approach this advanced position. He had made it.

Time and again as I am approached, it has been clear to me that there are many who want to code, not because they think they have the aptitude, or inclination. Not because they have a love for the machines we work with. Rather so often because they are unhappy with their life circumstances and see programming as an easy way out. After all it was for me right? I don’t even have a college degree but am very successful.

What they didn’t see was the many late nights, starting from the age of 12 digesting every piece of information that I could lay my hands on about computers, there was no Internet. They didn’t see me enrolling in after school programs so that I could become more knowledgeable about the machines I was programming. I have an insatiable thirst for this knowledge, then and now. It consumes my life well beyond my job. Frankly, I am always baffled by those who have a healthier work-life balance, and often their code reflects it (not in a good way). Those that I have worked with over this time that are the best talent share many of the same characteristics that I have. They live and breathe programming and spend far too much time in their caves.

Still I think anyone who can finish High School can code. Not all will be able to have successful careers programming, but they should be able to learn the concepts. And more than a lack of ability, a lack of interest will be the downfall. There are many that put all the effort in, learned to code, usually because of the love of money and not computers, but when faced with the day to day challenges, finally moved on. Real Estate or sales, some other get rich quick scheme. So while pretty much anyone could code, it is unreasonable to think that anyone can have a career as a software developer.

While I do not have a college degree, I do have a significant amount of college course work, particularly in CS. I found it very difficult to deal with college politics and the minutia of general ed credits. So I took what I could get and left.

I feel strongly that there are innate characteristics that I have that make me able to code the way I do. Some of those are the same that made it impossible to work through my General Education. I have ADHD, I have dealt with it my entire life. They almost held me back in 5th grade because they thought I had a learning disability. Until they tested me and found that I had the highest score in the grade. It wasn’t that I had a learning disability, I had a working disability and was bored. While ADHD causes me significant challenges engaging in work, and managing my schedule, it comes with a gift. The gift of hyper-focus. When I do successfully engage, the level of focus is far beyond what most experience. All else falls away, it is just me and the computer. I have been known to have conversations that I was completely unaware of. Providing adequate responses to preserve my concentration and avoid the interruption. My strength in some of the formal testing show that my strength is in 3 dimensional conceptual reasoning. This translates well into being able to visualize the virtual and reason about it. To see the data flows and process integration. To conceptualize what is happening within the hardware at a microscopic level.

While I do not think that every programmer has the same gifts, I do believe that there are innate abilities, beyond what can be learned, that are necessary to be successful in this industry. As evidence, my four brothers are all software developers, two of my uncles are mechanical engineers, they were before the time of computers. On my fathers side, a trainwreck of lives due to ADHD and chemical addiction. I was not raised by my biological father who had an advanced degree in biology and was very successful until his addictions destroyed and eventually killed him. My father who raised me was a contractor and struggles with computers, though with a family of mentors has become functional. My brothers did not learn to code together. We came at it very differently than each other. Half of them were adamant that they would never do this, but ultimately their aptitude for the skill prevailed. This was very much nature, though work and nurture was necessary to really make it happen.

Some do not have the aptitude and no level of effort will replace that.

I will never be a famous tenor, despite my secret fantasies.
I will never be a rock star
I will never be successful as a salesman
I struggle as a father, despite immense love for my children and a willingness to sacrifice all.
I could never be a psychologist, that was the easy money when I was in college. My friend who followed that course is now a programmer.

If you have given it a significant effort and it is not working, it may be time to move on. That said, you need to objectively quantify and qualify your effort. Have you sought out appropriate resources, a mentor, the best books, a boot camp or a college course? Have you really made the time investment and made learning to code a priority. I won’t belabor this much longer, many other excellent answers here, and I primarily wanted to provide the insight above.

Are you doing it for the money or because you love working with computers and creating.