SlideShare ist ein Scribd-Unternehmen logo
1 von 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!

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Kürzlich hochgeladen

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Kürzlich hochgeladen (20)

Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

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!