SlideShare a Scribd company logo
How to Solve Problems
Problem Solving
Software University
https://softuni.bg
SoftUni Team
Technical Trainers
sli.do
#fund-common
Questions?
2
Table of Content
1. What Is a Problem?
2. Stages of Problem Solving
3. Complexity of a Problem
4. Example Problems
5. From Chaotic to Methodological Approach
3
What Is a Problem?
Current and Desired State Diff
 Definition - a doubtful or difficult matter,
requiring a solution
 Goals - anything you wish to achieve,
anywhere you want to be
 Barriers - obstacles that prevent the
achievement of goals
What Is a Problem?
5
Without goals and barriers
there is no problem
Stages
Stages of Solving a Problem
 Define the problem
 Analyse the problem
 Identify potential solutions
 Evaluate and choose the best solution
 Plan action
 Implement and review results
Solving a Problem
 What are the steps to cross the street successfully ?
Problem Street Crossing
8
 Recognizing that there is a problem, identifying the nature
of the problem, defining the problem
Problem Identification
9
Ascertain
the
objective
of the
decision
maker
Understand
the
background
of the
problem
Isolate
and
identify
the
problem
Determine
the unit of
analysis
and the
relevant
variables
State and
research
the
objective
 Observation
 Inspection
 Fact-finding
 Developing a clear picture
of the problem
Structure of the Problem
10
 Generating a range of possible courses of action and trying to
evaluate them
 Analyzing the different possible solutions and choosing the
best one
Solutions and Decisions
11
 Connect all the nine dots,
using only 4 lines
Nine Dots Problem
12
 Let's think outside the box!
 What has changed?
 Our point of view
Nine Dots Problem
13
Examples
Solving Problems
The Missing Piece
15
 You are mixing cement and the recipe calls for five gallons of water
 You have a garden hose giving you all the water you need
 The problem is that you only have a four-gallon bucket and
a seven-gallon bucket and neither has graduation marks
 Find a method to measure five gallons
Five Gallons
16
4 gal 7 gal
 You have 10 stacks of 10 gold coins
 All the coins in one of these stacks are counterfeit,
all the other coins are not
 A real coin weighs 10 grams
 A counterfeit coin weighs 11 grams
 You can use an extremely
accurate digital weighing machine only once
 How do you determine which set of
10 coins is faulty?
10 Piles of 10 Coins One of Which Is Fake
17
Solutions
The Missing Piece
19
The Missing Piece
20
 The gradient of the teal hypotenuse is different than the
gradient of the red hypotenuse
 Fill the 4-gallon bucket
 Empty the 4-gallon bucket into the 7-gallon bucket
 Fill the 4-gallon bucket
 Pour the 3 gallons from the 4-gallon bucket
into the 7-gallon bucket
 Empty the 7-gallon bucket
 Pour the 1 gallon from the 4-gallon bucket into the 7-gallon bucket
 Fill the 4-gallon bucket
 Empty the 4-gallon bucket into the 7-gallon bucket
 We have solved the problem
Five Gallons
21
0 gal
0 gal
4 gal 4 gal
1 gal
7 gal1 gal
5 gal
 We take one coin from pile #1, two coins from pile #2, three coins
from pile #3 and so on until we have 10 coins from pile #10
 This gives us 55 coins which if they were all pure would give us 550g
10 Piles of 10 Coins One of Which Is Fake (1)
22
10 Piles of 10 Coins One of Which Is Fake (2)
23
 However, some of them will be fake
 Let's say we place them all on the scale, for our one and only
weighing, and it reads 553g
 The only possible way this could have happened is if we placed
3 counterfeit coins on the balance, and that means that
pile #3 is counterfeit
Solving
From Chaotic to Methodological Approach
Read and Analyze the Problems
25
 Consider you are at a computer programming exam or contest
 You have 5 problems to solve in 6 hours
 First read carefully all problems and try to estimate how
complex each of them is
 Read the requirements, don't invent them!
 Start solving the easiest / fastest to solve problem first!
 Leave the most complex / slow to solve problem last!
 Approach the next problem when the previous is well tested
Use a Sheet of Paper and a Pen
26
 Never start solving a problem without a sheet of paper + a pen
 You need to sketch your ideas
 Paper and pen is the best visualization tool
 Allows your brain to think efficiently
 Paper works faster than keyboard / screen
 Other visualization tools could also work well
Prefer Squared Paper
27
 Squared paper works best for
algorithmic problems
 Easy to draw a table
 Easy to draw a coordinate
system with objects at it
 Easy to calculate distances
 Easy to sketch a problem and
solution idea
Paper and Pen
28
 Consider a "Cards Shuffle" problem
 We can sketch it to start thinking
 Some ideas immediately come, e.g.
 Split the deck into two parts and swap them multiple times
 Swap 2 random cards a random number of times
 Swap each card with a random card
Invent Ideas
Think-up, Invent Ideas and Check Them
Think Up, Invent and Try Ideas
30
 First take an example of the problem
 Sketch it on the sheet of paper
 Next try to invent some idea that works for your example
 Check if your idea will work for other examples
 Try to find a case that breaks your idea
 Try challenging examples and unusual cases
 If you find your idea incorrect, try to fix it
 Or just invent a new idea
Think Up, Invent and Try Ideas
31
 Idea #1: random number of times split the deck into left and
right part and swap them
 How to represent the cards?
 How to choose a random split point?
 How to perform the exchange?
 Idea #2: swap each card with a random card
 How many times to repeat this?
 Is this fast enough?
Think Up, Invent and Try Ideas
32
 Idea #3: swap 2 random cards a random number of times
 How to choose two random cards?
 How many times to repeat this?
 Idea #4: choose a random card and insert it in front of the deck
 How to choose random card?
 How many times to repeat this?
 Idea #5: do you have another idea?
Divide and Conquer
Decompose Problems into Manageable Pieces
Decompose the Problem
34
 Work decomposition is natural in engineering
 It happens every day in the industry
 Projects are decomposed into subprojects
 Complex problems could be decomposed into several smaller
sub-problems
 Technique known as "Divide and Conquer"
 Small problems could easily be solved
 Smaller sub-problems could be further decomposed as well
Divide and Conquer – Example
35
 Let's try idea #1:
 Split the deck into left and right part and swap them
(many times)
 Divide and conquer
 Sub-problem #1 (single exchange) – split the deck into two
random parts and exchange them
 Sub-problem #2 – choosing a random split point
 Sub-problem #3 – combining single exchanges
 How many times to perform "single exchange"?
Sub-Problem #1 (Single Exchange)
36
 Split the deck into two parts at random split point
 And exchange these 2 parts
 We visualize this by paper and pen:
Sub-Problem #2 (Single Exchange)
37
 Choosing a random split point
 Need to understand the concept of pseudo-random numbers
and how to use it
 In Internet lots of examples are available, some of them incorrect
 The class System.Random can do the job
 Important detail is that the Random class should be
instantiated only once
 Not at each random number generation
Sub-Problem #3 (Single Exchange)
38
 Combining a sequence of single exchanges to solve
the initial problem
 How many times to perform single exchanges to reliably
randomize the deck?
 N times (where N is the number of the cards) seems enough
 We have an algorithm:
 N times split at random position and exchange the left and right
parts of the deck
Check-Up Your Ideas
Don't Go Ahead Before Checking Your Ideas
Check-Up Your Ideas
40
 Check-up your ideas with examples
 It is better to find a problem before the idea is implemented
 When the code is written, changing your ideas radically costs a
lot of time and effort
 Carefully select examples for check-up
 Examples should be simple enough to be checked
by hand in a minute
 Examples should be complex enough to cover the most general
case, not just an isolated case
Check-Up Your Ideas – Example
41
 Let's check the idea:
 After 3 random splits and swaps we obtain the start position
 Seems like a serious problem!
Invent New Idea If Needed
42
 What to do when you find your idea is not working in all cases?
 Try to fix your idea
 Sometimes a small change could fix the problem
 Invent new idea and carefully check it
 Iterate
 Usually your first idea is not the best
 Invent ideas, check them, try various cases, find problems,
fix them, invent better ideas, etc.
Invent New Ideas – Example
43
 Invent a few new ideas:
 New idea #1 – multiple times select 2 random cards and
exchange them
 New idea #2 – multiple times select a random card and
exchange it with the first card
 New idea #3 – multiple times select a random card and move it
to an external list
 Let's check the new idea #2
 Is it correct?
Check-Up the New Idea – Example
44
Implementation
Coding and Testing Step-By-Step
Start Coding: Checklist
46
 Never start coding before you find a correct idea that will meet
the requirements
 What shall you write before you have a correct idea?
 Checklist to follow before start of coding:
 Ensure you understand the requirements well
 Ensure you have come up a good idea
 Ensure your idea is correct
 Ensure you know what data structures to use
 Ensure the performance will be sufficient
Implement Your Algorithm Step-By-Step
47
 "Step-by-step" approach is always better than
"build all, then test"
 Implement a piece of your program and test it
 Then implement another piece of the program and test it
 Finally put together all pieces and test it
 Small increments (steps) reveal errors early
 "Big bang" integration takes more time
Testing the Code
Thoroughly Test Your Solution
Thoroughly Test Your Solution
49
 Always test thoroughly your solution
 Invest in testing!
 One 90-100% solved problem could be better than 2 or 3
partially solved
 Testing an existing problem takes less time than solving another
problem from scratch
How to Test?
50
 Testing could not certify absence of defects
 It just reduces the defects’ rates
 Well tested solutions are more likely to be correct
 Start testing with a good representative of the general case
 Not a small isolated case, but a typical one
 Large enough test case, but small enough to be easily checkable
Read the Problem Statement
51
 Read carefully the problem statement
 Does your solution print exactly what is expected?
 Does your output follow the requested format?
 Did you remove your debug printouts?
 Be sure to solve the requested problem, not the problem
you think is requested!
 Example: "Write a program to print the number of
permutations of n elements" means to print a single number,
not a set of permutations!
 …
 …
 …
Summary
52
 Problem solving needs methodology:
 Understanding and analyzing problems
 Using a sheet of paper and a pen for sketching
 Thinking up, inventing and trying ideas
 Decomposing problems into sub-problems
 Selecting appropriate data structures
 Thinking about the efficiency and performance
 Implementing step-by-step
 Testing the nominal case, border cases and efficiency
 https://softuni.bg/courses/programming-fundamentals
SoftUni Diamond Partners
SoftUni Organizational Partners
 Software University – High-Quality Education and
Employment Opportunities
 softuni.bg
 Software University Foundation
 http://softuni.foundation/
 Software University @ Facebook
 facebook.com/SoftwareUniversity
 Software University Forums
 forum.softuni.bg
Trainings @ Software University (SoftUni)
 This course (slides, examples, demos, videos, homework, etc.)
is licensed under the "Creative Commons Attribution-NonCom
mercial-ShareAlike 4.0 International" license
License
57

More Related Content

Similar to Java Problem solving

Creative Problem Solving Skills For Staff
Creative Problem Solving Skills For StaffCreative Problem Solving Skills For Staff
Creative Problem Solving Skills For Staff
Paul Nguyen
 
Analytical thinking team
Analytical thinking teamAnalytical thinking team
Analytical thinking teamShrikant Tyagi
 
Introducing the maths toolbox to students
Introducing the maths toolbox to studentsIntroducing the maths toolbox to students
Introducing the maths toolbox to students
Kevin Cummins
 
Creativity Workshop
Creativity WorkshopCreativity Workshop
Creativity Workshop
Carole Derks
 
Problem Solving
Problem SolvingProblem Solving
Problem Solving
Shagufta Naz
 
Creative Problem Solving
Creative Problem SolvingCreative Problem Solving
Creative Problem SolvingZahyd Shuja
 
Mental Models2
Mental Models2Mental Models2
Mental Models2
Katrin Becker
 
Order of operations ppt lesson
Order of operations ppt lessonOrder of operations ppt lesson
Order of operations ppt lessonbundelk12
 
NC-NETS Employability Skills: Problem Solving
NC-NETS Employability Skills: Problem SolvingNC-NETS Employability Skills: Problem Solving
NC-NETS Employability Skills: Problem Solving
WakeTechCC
 
20190413 zen and the art of programming
20190413 zen and the art of programming20190413 zen and the art of programming
20190413 zen and the art of programming
David Horvath
 
Creativity techniques for computer scientists
Creativity techniques for computer scientistsCreativity techniques for computer scientists
Creativity techniques for computer scientists
Marco Cattani
 
Design Thinking & The Hackathon
Design Thinking & The HackathonDesign Thinking & The Hackathon
Design Thinking & The Hackathon
The Pilot Project
 
Creative and innovative thinking skills
Creative and innovative thinking skillsCreative and innovative thinking skills
Creative and innovative thinking skillsZaini Ithnin
 
Research methodology
Research methodologyResearch methodology
Research methodology
Dr. Dipti Patil
 
Creative problem solving revised
Creative problem solving revisedCreative problem solving revised
Creative problem solving revised
Vasudevan BK
 
Creativity 100910074135-phpapp02[1]
Creativity 100910074135-phpapp02[1]Creativity 100910074135-phpapp02[1]
Creativity 100910074135-phpapp02[1]Mary Bolton
 
Creativity
CreativityCreativity
Creativity
summersolero
 
ProblemSolving for engineering presentation.ppt
ProblemSolving for engineering presentation.pptProblemSolving for engineering presentation.ppt
ProblemSolving for engineering presentation.ppt
KRkumar12
 
20180324 zen and the art of programming
20180324 zen and the art of programming20180324 zen and the art of programming
20180324 zen and the art of programming
David Horvath
 

Similar to Java Problem solving (20)

Creative Problem Solving Skills For Staff
Creative Problem Solving Skills For StaffCreative Problem Solving Skills For Staff
Creative Problem Solving Skills For Staff
 
Analytical thinking team
Analytical thinking teamAnalytical thinking team
Analytical thinking team
 
Introducing the maths toolbox to students
Introducing the maths toolbox to studentsIntroducing the maths toolbox to students
Introducing the maths toolbox to students
 
Creativity Workshop
Creativity WorkshopCreativity Workshop
Creativity Workshop
 
Problem Solving
Problem SolvingProblem Solving
Problem Solving
 
Creative Problem Solving
Creative Problem SolvingCreative Problem Solving
Creative Problem Solving
 
Mental Models2
Mental Models2Mental Models2
Mental Models2
 
BOOI_Innovations_match_sticks_v03
BOOI_Innovations_match_sticks_v03BOOI_Innovations_match_sticks_v03
BOOI_Innovations_match_sticks_v03
 
Order of operations ppt lesson
Order of operations ppt lessonOrder of operations ppt lesson
Order of operations ppt lesson
 
NC-NETS Employability Skills: Problem Solving
NC-NETS Employability Skills: Problem SolvingNC-NETS Employability Skills: Problem Solving
NC-NETS Employability Skills: Problem Solving
 
20190413 zen and the art of programming
20190413 zen and the art of programming20190413 zen and the art of programming
20190413 zen and the art of programming
 
Creativity techniques for computer scientists
Creativity techniques for computer scientistsCreativity techniques for computer scientists
Creativity techniques for computer scientists
 
Design Thinking & The Hackathon
Design Thinking & The HackathonDesign Thinking & The Hackathon
Design Thinking & The Hackathon
 
Creative and innovative thinking skills
Creative and innovative thinking skillsCreative and innovative thinking skills
Creative and innovative thinking skills
 
Research methodology
Research methodologyResearch methodology
Research methodology
 
Creative problem solving revised
Creative problem solving revisedCreative problem solving revised
Creative problem solving revised
 
Creativity 100910074135-phpapp02[1]
Creativity 100910074135-phpapp02[1]Creativity 100910074135-phpapp02[1]
Creativity 100910074135-phpapp02[1]
 
Creativity
CreativityCreativity
Creativity
 
ProblemSolving for engineering presentation.ppt
ProblemSolving for engineering presentation.pptProblemSolving for engineering presentation.ppt
ProblemSolving for engineering presentation.ppt
 
20180324 zen and the art of programming
20180324 zen and the art of programming20180324 zen and the art of programming
20180324 zen and the art of programming
 

More from Intro C# Book

17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
Intro C# Book
 
21. Java High Quality Programming Code
21. Java High Quality Programming Code21. Java High Quality Programming Code
21. Java High Quality Programming Code
Intro C# Book
 
20.5 Java polymorphism
20.5 Java polymorphism 20.5 Java polymorphism
20.5 Java polymorphism
Intro C# Book
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
Intro C# Book
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
Intro C# Book
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
Intro C# Book
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
Intro C# Book
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity
Intro C# Book
 
18. Java associative arrays
18. Java associative arrays18. Java associative arrays
18. Java associative arrays
Intro C# Book
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
Intro C# Book
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
Intro C# Book
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
Intro C# Book
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
Intro C# Book
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
Intro C# Book
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
Intro C# Book
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
Intro C# Book
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
Intro C# Book
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
Intro C# Book
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variables
Intro C# Book
 
01. Introduction to programming with java
01. Introduction to programming with java01. Introduction to programming with java
01. Introduction to programming with java
Intro C# Book
 

More from Intro C# Book (20)

17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
 
21. Java High Quality Programming Code
21. Java High Quality Programming Code21. Java High Quality Programming Code
21. Java High Quality Programming Code
 
20.5 Java polymorphism
20.5 Java polymorphism 20.5 Java polymorphism
20.5 Java polymorphism
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity
 
18. Java associative arrays
18. Java associative arrays18. Java associative arrays
18. Java associative arrays
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variables
 
01. Introduction to programming with java
01. Introduction to programming with java01. Introduction to programming with java
01. Introduction to programming with java
 

Recently uploaded

一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
GTProductions1
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
JeyaPerumal1
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
VivekSinghShekhawat2
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 

Recently uploaded (20)

一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 

Java Problem solving

  • 1. How to Solve Problems Problem Solving Software University https://softuni.bg SoftUni Team Technical Trainers
  • 3. Table of Content 1. What Is a Problem? 2. Stages of Problem Solving 3. Complexity of a Problem 4. Example Problems 5. From Chaotic to Methodological Approach 3
  • 4. What Is a Problem? Current and Desired State Diff
  • 5.  Definition - a doubtful or difficult matter, requiring a solution  Goals - anything you wish to achieve, anywhere you want to be  Barriers - obstacles that prevent the achievement of goals What Is a Problem? 5 Without goals and barriers there is no problem
  • 7.  Define the problem  Analyse the problem  Identify potential solutions  Evaluate and choose the best solution  Plan action  Implement and review results Solving a Problem
  • 8.  What are the steps to cross the street successfully ? Problem Street Crossing 8
  • 9.  Recognizing that there is a problem, identifying the nature of the problem, defining the problem Problem Identification 9 Ascertain the objective of the decision maker Understand the background of the problem Isolate and identify the problem Determine the unit of analysis and the relevant variables State and research the objective
  • 10.  Observation  Inspection  Fact-finding  Developing a clear picture of the problem Structure of the Problem 10
  • 11.  Generating a range of possible courses of action and trying to evaluate them  Analyzing the different possible solutions and choosing the best one Solutions and Decisions 11
  • 12.  Connect all the nine dots, using only 4 lines Nine Dots Problem 12
  • 13.  Let's think outside the box!  What has changed?  Our point of view Nine Dots Problem 13
  • 16.  You are mixing cement and the recipe calls for five gallons of water  You have a garden hose giving you all the water you need  The problem is that you only have a four-gallon bucket and a seven-gallon bucket and neither has graduation marks  Find a method to measure five gallons Five Gallons 16 4 gal 7 gal
  • 17.  You have 10 stacks of 10 gold coins  All the coins in one of these stacks are counterfeit, all the other coins are not  A real coin weighs 10 grams  A counterfeit coin weighs 11 grams  You can use an extremely accurate digital weighing machine only once  How do you determine which set of 10 coins is faulty? 10 Piles of 10 Coins One of Which Is Fake 17
  • 20. The Missing Piece 20  The gradient of the teal hypotenuse is different than the gradient of the red hypotenuse
  • 21.  Fill the 4-gallon bucket  Empty the 4-gallon bucket into the 7-gallon bucket  Fill the 4-gallon bucket  Pour the 3 gallons from the 4-gallon bucket into the 7-gallon bucket  Empty the 7-gallon bucket  Pour the 1 gallon from the 4-gallon bucket into the 7-gallon bucket  Fill the 4-gallon bucket  Empty the 4-gallon bucket into the 7-gallon bucket  We have solved the problem Five Gallons 21 0 gal 0 gal 4 gal 4 gal 1 gal 7 gal1 gal 5 gal
  • 22.  We take one coin from pile #1, two coins from pile #2, three coins from pile #3 and so on until we have 10 coins from pile #10  This gives us 55 coins which if they were all pure would give us 550g 10 Piles of 10 Coins One of Which Is Fake (1) 22
  • 23. 10 Piles of 10 Coins One of Which Is Fake (2) 23  However, some of them will be fake  Let's say we place them all on the scale, for our one and only weighing, and it reads 553g  The only possible way this could have happened is if we placed 3 counterfeit coins on the balance, and that means that pile #3 is counterfeit
  • 24. Solving From Chaotic to Methodological Approach
  • 25. Read and Analyze the Problems 25  Consider you are at a computer programming exam or contest  You have 5 problems to solve in 6 hours  First read carefully all problems and try to estimate how complex each of them is  Read the requirements, don't invent them!  Start solving the easiest / fastest to solve problem first!  Leave the most complex / slow to solve problem last!  Approach the next problem when the previous is well tested
  • 26. Use a Sheet of Paper and a Pen 26  Never start solving a problem without a sheet of paper + a pen  You need to sketch your ideas  Paper and pen is the best visualization tool  Allows your brain to think efficiently  Paper works faster than keyboard / screen  Other visualization tools could also work well
  • 27. Prefer Squared Paper 27  Squared paper works best for algorithmic problems  Easy to draw a table  Easy to draw a coordinate system with objects at it  Easy to calculate distances  Easy to sketch a problem and solution idea
  • 28. Paper and Pen 28  Consider a "Cards Shuffle" problem  We can sketch it to start thinking  Some ideas immediately come, e.g.  Split the deck into two parts and swap them multiple times  Swap 2 random cards a random number of times  Swap each card with a random card
  • 29. Invent Ideas Think-up, Invent Ideas and Check Them
  • 30. Think Up, Invent and Try Ideas 30  First take an example of the problem  Sketch it on the sheet of paper  Next try to invent some idea that works for your example  Check if your idea will work for other examples  Try to find a case that breaks your idea  Try challenging examples and unusual cases  If you find your idea incorrect, try to fix it  Or just invent a new idea
  • 31. Think Up, Invent and Try Ideas 31  Idea #1: random number of times split the deck into left and right part and swap them  How to represent the cards?  How to choose a random split point?  How to perform the exchange?  Idea #2: swap each card with a random card  How many times to repeat this?  Is this fast enough?
  • 32. Think Up, Invent and Try Ideas 32  Idea #3: swap 2 random cards a random number of times  How to choose two random cards?  How many times to repeat this?  Idea #4: choose a random card and insert it in front of the deck  How to choose random card?  How many times to repeat this?  Idea #5: do you have another idea?
  • 33. Divide and Conquer Decompose Problems into Manageable Pieces
  • 34. Decompose the Problem 34  Work decomposition is natural in engineering  It happens every day in the industry  Projects are decomposed into subprojects  Complex problems could be decomposed into several smaller sub-problems  Technique known as "Divide and Conquer"  Small problems could easily be solved  Smaller sub-problems could be further decomposed as well
  • 35. Divide and Conquer – Example 35  Let's try idea #1:  Split the deck into left and right part and swap them (many times)  Divide and conquer  Sub-problem #1 (single exchange) – split the deck into two random parts and exchange them  Sub-problem #2 – choosing a random split point  Sub-problem #3 – combining single exchanges  How many times to perform "single exchange"?
  • 36. Sub-Problem #1 (Single Exchange) 36  Split the deck into two parts at random split point  And exchange these 2 parts  We visualize this by paper and pen:
  • 37. Sub-Problem #2 (Single Exchange) 37  Choosing a random split point  Need to understand the concept of pseudo-random numbers and how to use it  In Internet lots of examples are available, some of them incorrect  The class System.Random can do the job  Important detail is that the Random class should be instantiated only once  Not at each random number generation
  • 38. Sub-Problem #3 (Single Exchange) 38  Combining a sequence of single exchanges to solve the initial problem  How many times to perform single exchanges to reliably randomize the deck?  N times (where N is the number of the cards) seems enough  We have an algorithm:  N times split at random position and exchange the left and right parts of the deck
  • 39. Check-Up Your Ideas Don't Go Ahead Before Checking Your Ideas
  • 40. Check-Up Your Ideas 40  Check-up your ideas with examples  It is better to find a problem before the idea is implemented  When the code is written, changing your ideas radically costs a lot of time and effort  Carefully select examples for check-up  Examples should be simple enough to be checked by hand in a minute  Examples should be complex enough to cover the most general case, not just an isolated case
  • 41. Check-Up Your Ideas – Example 41  Let's check the idea:  After 3 random splits and swaps we obtain the start position  Seems like a serious problem!
  • 42. Invent New Idea If Needed 42  What to do when you find your idea is not working in all cases?  Try to fix your idea  Sometimes a small change could fix the problem  Invent new idea and carefully check it  Iterate  Usually your first idea is not the best  Invent ideas, check them, try various cases, find problems, fix them, invent better ideas, etc.
  • 43. Invent New Ideas – Example 43  Invent a few new ideas:  New idea #1 – multiple times select 2 random cards and exchange them  New idea #2 – multiple times select a random card and exchange it with the first card  New idea #3 – multiple times select a random card and move it to an external list  Let's check the new idea #2  Is it correct?
  • 44. Check-Up the New Idea – Example 44
  • 46. Start Coding: Checklist 46  Never start coding before you find a correct idea that will meet the requirements  What shall you write before you have a correct idea?  Checklist to follow before start of coding:  Ensure you understand the requirements well  Ensure you have come up a good idea  Ensure your idea is correct  Ensure you know what data structures to use  Ensure the performance will be sufficient
  • 47. Implement Your Algorithm Step-By-Step 47  "Step-by-step" approach is always better than "build all, then test"  Implement a piece of your program and test it  Then implement another piece of the program and test it  Finally put together all pieces and test it  Small increments (steps) reveal errors early  "Big bang" integration takes more time
  • 48. Testing the Code Thoroughly Test Your Solution
  • 49. Thoroughly Test Your Solution 49  Always test thoroughly your solution  Invest in testing!  One 90-100% solved problem could be better than 2 or 3 partially solved  Testing an existing problem takes less time than solving another problem from scratch
  • 50. How to Test? 50  Testing could not certify absence of defects  It just reduces the defects’ rates  Well tested solutions are more likely to be correct  Start testing with a good representative of the general case  Not a small isolated case, but a typical one  Large enough test case, but small enough to be easily checkable
  • 51. Read the Problem Statement 51  Read carefully the problem statement  Does your solution print exactly what is expected?  Does your output follow the requested format?  Did you remove your debug printouts?  Be sure to solve the requested problem, not the problem you think is requested!  Example: "Write a program to print the number of permutations of n elements" means to print a single number, not a set of permutations!
  • 52.  …  …  … Summary 52  Problem solving needs methodology:  Understanding and analyzing problems  Using a sheet of paper and a pen for sketching  Thinking up, inventing and trying ideas  Decomposing problems into sub-problems  Selecting appropriate data structures  Thinking about the efficiency and performance  Implementing step-by-step  Testing the nominal case, border cases and efficiency
  • 56.  Software University – High-Quality Education and Employment Opportunities  softuni.bg  Software University Foundation  http://softuni.foundation/  Software University @ Facebook  facebook.com/SoftwareUniversity  Software University Forums  forum.softuni.bg Trainings @ Software University (SoftUni)
  • 57.  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution-NonCom mercial-ShareAlike 4.0 International" license License 57