This session teaches two methods for effective problem-solving.
Size: 7.28 MB
Language: en
Added: May 11, 2024
Slides: 14 pages
Slide Content
Code Lab Module 1: Introduction to Problem Solving Opeoluwa Daniel Oyedeji GDSC Lead, E.U. Elizade University
What is problem solving?
Problem-solving refers to a systematic approach to analyzing the problem, developing a solution (algorithm), and implementing that solution in code .
Divide and Conquer
Problem-Solving Approaches When tackling coding problems, there are two main approaches you can take to break them down and develop a solution. Top-Down Approach Bottom-Up Approach
Top-Down Approach This approach starts with the big picture and works its way down. Understand the overall problem and break it down into smaller subproblems. Solve each subproblem independently, and then combine the solutions to form the final solution to the larger problem.
Top-Down Approach: Calculating Area Identify the whole shape. Divide it into simpler shapes. Calculate the area of each simple shape. Combine the areas to find the total area.
Top-Down Approach: Calculating Area Identify the whole shape. Divide it into simpler shapes. Calculate the area of each simple shape. Combine the areas to find the total area.
Semicircle Area Rectangle Area Triangle Area Total Area C hart 1
Bottom-Up Approach This approach starts with the building blocks and works its way up. Start with the most basic operations needed to solve the problem. Combine these operations into larger functions to create the overall solution.
Bottom-Up Approach : Counting Vowels Implement a function to i dentify vowels. Implement a function to iterate through the list. Vowels : (a, e, i, o, u) List: (b, d, c, a, z, x, i, l, f)
I dentify vowels // Basic Operation private static boolean isVowel ( char x ) { char [] vowels = { 'a' , 'e' , 'i' , 'o' , 'u' }; for ( int i = ; i < vowels.length; i ++ ) if (vowels[i] == x) return true ; return false ; }
Iterate through list // Larger Function private static int countVowels ( char [] arr ) { int count = ; for ( int i = ; i < arr.length; i ++ ) if ( isVowel (arr[i])) count ++ ; return count; }