SlideShare uma empresa Scribd logo
1 de 30
Lecture 24: Problem Solving and
Thinking Like a Programmer
How to Think Like a Programmer…
10 Steps
Step 1: Read the problem at least three times
• You can’t solve a problem you don’t understand.
• There is a difference between the problem AND the problem you think
you are solving.
• It’s easy to start reading the first few lines in a problem and assume the
rest of it because it’s similar to something you’ve seen in the past.
• EX: If you are making even a popular game like Hangman, be sure to read
through any rules even if you’ve played it before.
• I once was asked to make a game like Hangman that I realized was “Evil
Hangman” only after I read through the instructions (it was a trick!).
• Sometimes I’ll even try explaining the problem to a friend and see if
his/her understanding of my explanation matches the problem I am
tasked with.
• You don’t want to find out halfway through that you misunderstood
the problem.
• Taking extra time in the beginning is worth it. The better you understand the
problem, the easier it will be to solve it.
Step 2: Work through the problem manually with
at least three sets of sample data
• Take out a piece of paper and work through the problem manually.
• Think of at least three sets of sample data you can use.
• Consider corner and edge cases as well.
• Corner case: a problem or situation that occurs outside of normal
operating parameters.
• Edge case: problem or situation that occurs only at an extreme
(maximum or minimum) operating parameter
Step 3: Simplify and optimize your steps
• Look for patterns and see if there’s anything you can generalize.
• See if you can reduce any steps or if you are repeating any steps.
Step 4: Write Pseudocode
• Even after you’ve worked out general steps, writing out pseudocode
that you can translate into code will help with defining the structure
of your code and make coding a lot easier.
• Write pseudocode line by line.
• You can do this either on paper or as comments in your code editor.
• Don’t get caught up with the syntax. Focus on the logic
and steps.
Step 5:Translate pseudocode into code
and debug
• When you have your pseudocode ready, translate each line into real code
in the language you are working on.
• Then I call the function and give it some sample sets of data we used
earlier.
• I use them to see if my code returns the results I want.
• You can also write tests to check if the actual output is equal to the expected output.
• Sometimes new developers will get hung up with the syntax that it
becomes difficult to move forward.
• Remember that syntax will come more naturally over time and there is no
shame in referencing material for the correct syntax later on when coding.
Step 6: Simplify and optimize your code
• You’ve probably noticed by now that simplifying and optimizing are
recurring themes.
Questions to keep in mind when optimizing
• What are your goals for simplifying and optimizing?
• How else can you make the code more readable?
• Are there any more extra steps you can take out?
• Are there any variables or functions you ended up not even needing or using?
• Are you repeating some steps a lot? See if you can define in another method.
• Are there better ways to handle edge cases?
Step 7: Debug
• This step really should be throughout the process.
• Debugging throughout will help you catch any syntax errors or gaps
in logic sooner rather than later.
• Take advantage of your Integrated Development Environment
(IDE) and debugger.
• When I encounter bugs, I trace the code line-by-line to see if there was
anything that did not go as expected.
Here are some techniques I use to debug:
• Check the console to see what the error message says.
• Sometimes it’ll point out a line number I need to check.
• This gives me a rough idea of where to start, although the issue sometimes may not be at this
line at all.
• Comment out chunks or lines of code and output what I have so far to quickly see if
the code is behaving how I expected. I can always uncomment the code as needed.
• Use other sample data if there are scenarios I did not think of and see if the code will
still work.
• Save different versions of my file if I am trying out a completely different approach. I
don’t want to lose any of my work if I end up wanting to revert back to it!
Step 8: Write Useful Comments
• You may not always remember what every single line meant a month later.
• Someone else working on your code may not know either.
• That’s why it’s important to write useful comments to avoid problems and save time later on if
you need to come back to it.
• I try to write brief, high-level comments that help me understand what’s
going on if it is not obvious.
• This comes in handy when I am working on more complex problems. It helps understand what a
particular function is doing and why.
• Through the use of clear variable names, function names, and comments, you (and
others) should be able to understand:
• What is this code for?
• What is it doing?
Step 9: Get Feedback
• Get feedback from your teammates, professors, and other
developers.
• Check out Stack Overflow. See how others tackled the problem and
learn from them.
• There are sometimes several ways to approach a problem.
• Find out what they are and you’ll get better and quicker at coming up with
them yourself.
Step 10: Practice, Practice, Practice
• Even experienced developers are always practicing and learning.
• If you get helpful feedback, implement it.
• Redo a problem or do similar problems.
• Keep pushing yourself.
• With each problem you solve, the better a developer you become.
• Celebrate each success and be sure to remember how far you’ve come.
• Remember that programming, like with anything, comes easier and more
naturally with time.
10
Minute
Break
21
ATTENDANCE
will be taken
now…
Lecture 25: Binary Search, BubbleSort, Big-O
Notation
Search Algorithms...What Are They?
• Searching Algorithms are designed to check for an element or retrieve an
element from any data structure where it is stored.
• There are many different types of searches
• Linear Search
• Binary Search
• Jump Search
• Interpolation Search
• Exponential Search
• …and the list goes on
Binary
Search
• Search a sorted array by
repeatedly dividing the search
interval in half. Begin with an
interval covering the whole
array. If the value of the search
key is less than the item in the
middle of the interval, narrow
the interval to the lower half.
Otherwise narrow it to the
upper half. Repeatedly check
until the value is found or the
interval is empty.
Linear
Search
• A simple approach is to
do linear search
• Start from the leftmost
element of arr[] and one
by one compare x with
each element of arr[]
• If x matches with an
element, return the index
• If x doesn’t match with
any of elements, return -1
BubbleSort
Big O Notation
• Big O notation is used to communicate how fast an algorithm is
• Also known as run time
• Big O establishes a worst-case run time
• Algorithm speed isn’t measured in seconds, but in growth of the
number of operations.
• Instead, we talk about how quickly the run time of an algorithm
increases as the size of the input increases.
Binary Search O(1) O(log (n)) O(1)
Linear Search O(n) O(n) O(n)
for Loop
for (int i = 0; i < 10; i++) {
Console.WriteLine(“Hello”);
int x += nums[2];
for (int j = 0; j < 5; j++) {
Console.WriteLine(“This is the second loop”);
}
}
Run Time = O(n^2) Remove the constants!

Mais conteúdo relacionado

Mais procurados

Programming is Easy Once You Master....
Programming is Easy Once You Master....Programming is Easy Once You Master....
Programming is Easy Once You Master....Tonya Mork
 
Extreme Programming Deployed
Extreme Programming DeployedExtreme Programming Deployed
Extreme Programming DeployedSteve Loughran
 
Coding Introductory Lesson Upper Elementary
Coding Introductory Lesson Upper ElementaryCoding Introductory Lesson Upper Elementary
Coding Introductory Lesson Upper ElementaryBrittany Pike
 
Review June2015 Dec2015
Review June2015 Dec2015Review June2015 Dec2015
Review June2015 Dec2015Ikuru Kanuma
 
AP Computer Science Exam Information - 2018
AP Computer Science Exam Information - 2018AP Computer Science Exam Information - 2018
AP Computer Science Exam Information - 2018dmidgette
 
ICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionSyed Zaid Irshad
 
Pj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsPj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsSasidharaRaoMarrapu
 
Agile Software Development
Agile Software DevelopmentAgile Software Development
Agile Software DevelopmentAhmet Bulut
 
Simulating systems: Delivering digital difference
Simulating systems: Delivering digital differenceSimulating systems: Delivering digital difference
Simulating systems: Delivering digital differenceBrightwave Group
 
Code smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software OdorsCode smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software OdorsClint Edmonson
 
Sharpest tool in the box: Choosoing the best authoring tool for your learning...
Sharpest tool in the box: Choosoing the best authoring tool for your learning...Sharpest tool in the box: Choosoing the best authoring tool for your learning...
Sharpest tool in the box: Choosoing the best authoring tool for your learning...Brightwave Group
 
Planning Your Code
Planning Your CodePlanning Your Code
Planning Your Codelistergc
 
Seattle Girls' School Presentation
Seattle Girls' School PresentationSeattle Girls' School Presentation
Seattle Girls' School PresentationLiquidPlanner
 
8th grade tech test1
8th grade tech test18th grade tech test1
8th grade tech test1ChuckWalker
 
Real World Application of Development
Real World Application of DevelopmentReal World Application of Development
Real World Application of Developmentdjones101
 

Mais procurados (20)

Programming is Easy Once You Master....
Programming is Easy Once You Master....Programming is Easy Once You Master....
Programming is Easy Once You Master....
 
Code design
Code designCode design
Code design
 
Extreme Programming Deployed
Extreme Programming DeployedExtreme Programming Deployed
Extreme Programming Deployed
 
Coding Introductory Lesson Upper Elementary
Coding Introductory Lesson Upper ElementaryCoding Introductory Lesson Upper Elementary
Coding Introductory Lesson Upper Elementary
 
Review June2015 Dec2015
Review June2015 Dec2015Review June2015 Dec2015
Review June2015 Dec2015
 
AP Computer Science Exam Information - 2018
AP Computer Science Exam Information - 2018AP Computer Science Exam Information - 2018
AP Computer Science Exam Information - 2018
 
ICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionICS 2nd Year Book Introduction
ICS 2nd Year Book Introduction
 
Pj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsPj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentals
 
Agile Software Development
Agile Software DevelopmentAgile Software Development
Agile Software Development
 
Simulating systems: Delivering digital difference
Simulating systems: Delivering digital differenceSimulating systems: Delivering digital difference
Simulating systems: Delivering digital difference
 
Workshop 1 october 25
Workshop 1 october 25Workshop 1 october 25
Workshop 1 october 25
 
Code smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software OdorsCode smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software Odors
 
Bug Hunting Safari
Bug Hunting SafariBug Hunting Safari
Bug Hunting Safari
 
Sharpest tool in the box: Choosoing the best authoring tool for your learning...
Sharpest tool in the box: Choosoing the best authoring tool for your learning...Sharpest tool in the box: Choosoing the best authoring tool for your learning...
Sharpest tool in the box: Choosoing the best authoring tool for your learning...
 
Planning Your Code
Planning Your CodePlanning Your Code
Planning Your Code
 
Seattle Girls' School Presentation
Seattle Girls' School PresentationSeattle Girls' School Presentation
Seattle Girls' School Presentation
 
Pair Programming and XP Values
Pair Programming and XP ValuesPair Programming and XP Values
Pair Programming and XP Values
 
8th grade tech test1
8th grade tech test18th grade tech test1
8th grade tech test1
 
Soft Eng 1st PPT
Soft Eng 1st PPTSoft Eng 1st PPT
Soft Eng 1st PPT
 
Real World Application of Development
Real World Application of DevelopmentReal World Application of Development
Real World Application of Development
 

Semelhante a Lecture 24

Computational thinking
Computational thinkingComputational thinking
Computational thinkingr123457
 
Evolutionary Design - Refactoring Heuristics
Evolutionary Design - Refactoring HeuristicsEvolutionary Design - Refactoring Heuristics
Evolutionary Design - Refactoring HeuristicsAdi Bolboaca
 
11 rules for programmer should live by
11 rules for programmer should live by11 rules for programmer should live by
11 rules for programmer should live byYe Win
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipCamille Bell
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development Amir Assad
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tipsBill Buchan
 
CPP16 - Object Design
CPP16 - Object DesignCPP16 - Object Design
CPP16 - Object DesignMichael Heron
 
CSCI 180 Project Grading  Your project is graded based .docx
CSCI 180 Project Grading   Your project is graded based .docxCSCI 180 Project Grading   Your project is graded based .docx
CSCI 180 Project Grading  Your project is graded based .docxfaithxdunce63732
 
"How do you think when you're coding?", Jon Skeet
"How do you think when you're coding?",  Jon Skeet"How do you think when you're coding?",  Jon Skeet
"How do you think when you're coding?", Jon SkeetFwdays
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplaceDonny Wals
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplaceDonny Wals
 
Lecture 7 program development issues (supplementary)
Lecture 7  program development issues (supplementary)Lecture 7  program development issues (supplementary)
Lecture 7 program development issues (supplementary)alvin567
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš Maconko
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 

Semelhante a Lecture 24 (20)

Computational thinking
Computational thinkingComputational thinking
Computational thinking
 
Evolutionary Design - Refactoring Heuristics
Evolutionary Design - Refactoring HeuristicsEvolutionary Design - Refactoring Heuristics
Evolutionary Design - Refactoring Heuristics
 
11 rules for programmer should live by
11 rules for programmer should live by11 rules for programmer should live by
11 rules for programmer should live by
 
Intro to TDD
Intro to TDDIntro to TDD
Intro to TDD
 
Problem solving
Problem solvingProblem solving
Problem solving
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW Craftsmanship
 
Git Makes Me Angry Inside
Git Makes Me Angry InsideGit Makes Me Angry Inside
Git Makes Me Angry Inside
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
CPP16 - Object Design
CPP16 - Object DesignCPP16 - Object Design
CPP16 - Object Design
 
CSCI 180 Project Grading  Your project is graded based .docx
CSCI 180 Project Grading   Your project is graded based .docxCSCI 180 Project Grading   Your project is graded based .docx
CSCI 180 Project Grading  Your project is graded based .docx
 
"How do you think when you're coding?", Jon Skeet
"How do you think when you're coding?",  Jon Skeet"How do you think when you're coding?",  Jon Skeet
"How do you think when you're coding?", Jon Skeet
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
 
Lecture 7 program development issues (supplementary)
Lecture 7  program development issues (supplementary)Lecture 7  program development issues (supplementary)
Lecture 7 program development issues (supplementary)
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
Debugging
DebuggingDebugging
Debugging
 
Clean code
Clean codeClean code
Clean code
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 

Mais de Skillspire LLC (20)

Logistics
LogisticsLogistics
Logistics
 
Introduction to analytics
Introduction to analyticsIntroduction to analytics
Introduction to analytics
 
Lecture 29
Lecture 29Lecture 29
Lecture 29
 
Review
ReviewReview
Review
 
Review version 4
Review version 4Review version 4
Review version 4
 
Review version 3
Review version 3Review version 3
Review version 3
 
Review version 2
Review version 2Review version 2
Review version 2
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
Lecture 17
Lecture 17Lecture 17
Lecture 17
 
Lecture 16
Lecture 16Lecture 16
Lecture 16
 
Lecture 15
Lecture 15Lecture 15
Lecture 15
 
Lecture 14
Lecture 14Lecture 14
Lecture 14
 
Lecture 14
Lecture 14Lecture 14
Lecture 14
 
Lecture 13
Lecture 13Lecture 13
Lecture 13
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 

Último

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 

Último (20)

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 

Lecture 24

  • 1. Lecture 24: Problem Solving and Thinking Like a Programmer
  • 2. How to Think Like a Programmer… 10 Steps
  • 3. Step 1: Read the problem at least three times • You can’t solve a problem you don’t understand. • There is a difference between the problem AND the problem you think you are solving. • It’s easy to start reading the first few lines in a problem and assume the rest of it because it’s similar to something you’ve seen in the past. • EX: If you are making even a popular game like Hangman, be sure to read through any rules even if you’ve played it before. • I once was asked to make a game like Hangman that I realized was “Evil Hangman” only after I read through the instructions (it was a trick!).
  • 4. • Sometimes I’ll even try explaining the problem to a friend and see if his/her understanding of my explanation matches the problem I am tasked with. • You don’t want to find out halfway through that you misunderstood the problem. • Taking extra time in the beginning is worth it. The better you understand the problem, the easier it will be to solve it.
  • 5.
  • 6. Step 2: Work through the problem manually with at least three sets of sample data • Take out a piece of paper and work through the problem manually. • Think of at least three sets of sample data you can use. • Consider corner and edge cases as well. • Corner case: a problem or situation that occurs outside of normal operating parameters. • Edge case: problem or situation that occurs only at an extreme (maximum or minimum) operating parameter
  • 7. Step 3: Simplify and optimize your steps • Look for patterns and see if there’s anything you can generalize. • See if you can reduce any steps or if you are repeating any steps.
  • 8.
  • 9. Step 4: Write Pseudocode • Even after you’ve worked out general steps, writing out pseudocode that you can translate into code will help with defining the structure of your code and make coding a lot easier. • Write pseudocode line by line. • You can do this either on paper or as comments in your code editor. • Don’t get caught up with the syntax. Focus on the logic and steps.
  • 10.
  • 11. Step 5:Translate pseudocode into code and debug • When you have your pseudocode ready, translate each line into real code in the language you are working on. • Then I call the function and give it some sample sets of data we used earlier. • I use them to see if my code returns the results I want. • You can also write tests to check if the actual output is equal to the expected output. • Sometimes new developers will get hung up with the syntax that it becomes difficult to move forward. • Remember that syntax will come more naturally over time and there is no shame in referencing material for the correct syntax later on when coding.
  • 12. Step 6: Simplify and optimize your code • You’ve probably noticed by now that simplifying and optimizing are recurring themes.
  • 13. Questions to keep in mind when optimizing • What are your goals for simplifying and optimizing? • How else can you make the code more readable? • Are there any more extra steps you can take out? • Are there any variables or functions you ended up not even needing or using? • Are you repeating some steps a lot? See if you can define in another method. • Are there better ways to handle edge cases?
  • 14. Step 7: Debug • This step really should be throughout the process. • Debugging throughout will help you catch any syntax errors or gaps in logic sooner rather than later. • Take advantage of your Integrated Development Environment (IDE) and debugger. • When I encounter bugs, I trace the code line-by-line to see if there was anything that did not go as expected.
  • 15. Here are some techniques I use to debug: • Check the console to see what the error message says. • Sometimes it’ll point out a line number I need to check. • This gives me a rough idea of where to start, although the issue sometimes may not be at this line at all. • Comment out chunks or lines of code and output what I have so far to quickly see if the code is behaving how I expected. I can always uncomment the code as needed. • Use other sample data if there are scenarios I did not think of and see if the code will still work. • Save different versions of my file if I am trying out a completely different approach. I don’t want to lose any of my work if I end up wanting to revert back to it!
  • 16. Step 8: Write Useful Comments • You may not always remember what every single line meant a month later. • Someone else working on your code may not know either. • That’s why it’s important to write useful comments to avoid problems and save time later on if you need to come back to it. • I try to write brief, high-level comments that help me understand what’s going on if it is not obvious. • This comes in handy when I am working on more complex problems. It helps understand what a particular function is doing and why. • Through the use of clear variable names, function names, and comments, you (and others) should be able to understand: • What is this code for? • What is it doing?
  • 17.
  • 18. Step 9: Get Feedback • Get feedback from your teammates, professors, and other developers. • Check out Stack Overflow. See how others tackled the problem and learn from them. • There are sometimes several ways to approach a problem. • Find out what they are and you’ll get better and quicker at coming up with them yourself.
  • 19.
  • 20. Step 10: Practice, Practice, Practice • Even experienced developers are always practicing and learning. • If you get helpful feedback, implement it. • Redo a problem or do similar problems. • Keep pushing yourself. • With each problem you solve, the better a developer you become. • Celebrate each success and be sure to remember how far you’ve come. • Remember that programming, like with anything, comes easier and more naturally with time.
  • 22. Lecture 25: Binary Search, BubbleSort, Big-O Notation
  • 23. Search Algorithms...What Are They? • Searching Algorithms are designed to check for an element or retrieve an element from any data structure where it is stored. • There are many different types of searches • Linear Search • Binary Search • Jump Search • Interpolation Search • Exponential Search • …and the list goes on
  • 24. Binary Search • Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.
  • 25. Linear Search • A simple approach is to do linear search • Start from the leftmost element of arr[] and one by one compare x with each element of arr[] • If x matches with an element, return the index • If x doesn’t match with any of elements, return -1
  • 27. Big O Notation • Big O notation is used to communicate how fast an algorithm is • Also known as run time • Big O establishes a worst-case run time • Algorithm speed isn’t measured in seconds, but in growth of the number of operations. • Instead, we talk about how quickly the run time of an algorithm increases as the size of the input increases.
  • 28.
  • 29. Binary Search O(1) O(log (n)) O(1) Linear Search O(n) O(n) O(n)
  • 30. for Loop for (int i = 0; i < 10; i++) { Console.WriteLine(“Hello”); int x += nums[2]; for (int j = 0; j < 5; j++) { Console.WriteLine(“This is the second loop”); } } Run Time = O(n^2) Remove the constants!