0% found this document useful (0 votes)
6 views

Week 2 Lecture 4-5 (1)

The document discusses problem solving in programming, outlining steps such as identifying and analyzing the problem, generating solutions, and implementing them. It emphasizes the importance of algorithms and pseudocode in structuring solutions and provides examples of common programming languages. Additionally, it highlights the characteristics of algorithms and pseudocode, illustrating their roles in developing effective programs.

Uploaded by

Hina Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Week 2 Lecture 4-5 (1)

The document discusses problem solving in programming, outlining steps such as identifying and analyzing the problem, generating solutions, and implementing them. It emphasizes the importance of algorithms and pseudocode in structuring solutions and provides examples of common programming languages. Additionally, it highlights the characteristics of algorithms and pseudocode, illustrating their roles in developing effective programs.

Uploaded by

Hina Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Week 2 Lecture 4-

5
Problem Solving, Problem Solving with
perspective of programming, Algorithm, Pseudo
code
Problem Solving
• Problem solving is the process of identifying a challenge
or issue and finding a solution to it. It typically involves
several steps:
1.Identifying the Problem: Recognizing and clearly
defining the issue.
2.Analyzing the Problem: Understanding the factors
contributing to the problem and gathering relevant
information.
3.Generating Solutions: Brainstorming potential solutions
or approaches to address the problem.
Problem Solving
• Evaluating Options: Assessing the pros and cons of each
solution to determine the best course of action.
• Implementing a Solution: Putting the chosen solution
into action.
• Reviewing and Reflecting: Evaluating the effectiveness
of the solution and making adjustments if necessary.
Problem Solving in
Programming
• Programming:
• Programming is the process of creating a set of
instructions that a computer can understand and execute
to perform specific tasks.
• These instructions are written in a programming
language, which provides the syntax and structure needed
to communicate with the computer.
Problem Solving in
Programming
• For Example you are writing a recipie
1.Ingredients List: Like a recipe starts with ingredients, programming starts
with data (e.g., numbers or text).
2.Instructions: A recipe provides step-by-step instructions; programming
does the same with code.
3.Following Steps: Just as you follow each cooking step to make a dish, a
computer executes the code in order.
4.Final Product: If done correctly, you end up with a delicious meal (or a
functioning app)!
• In short, programming is like writing a recipe for a computer to follow
Problem Solving in
Programming
• In programming, problem solving involves applying logical thinking
and technical skills to devise solutions for specific challenges or
tasks. Here’s a breakdown of how problem solving manifests in
programming:
• Understanding the Problem: Clearly define the problem you're
trying to solve. This could involve analyzing requirements,
constraints, and desired outcomes.
• Breaking Down the Problem: Decompose the problem into smaller,
more manageable parts or sub-problems. This makes it easier to
tackle complex issues step by step.
Problem Solving in
Programming
• Choosing an Approach: Select an appropriate algorithm or
data structure to address the problem. This involves considering
factors like efficiency, readability, and scalability.
• Writing the Code: Translate the chosen approach into code
using a programming language. This requires familiarity with
syntax, libraries, and best practices.
• Testing and Debugging: Verify that the solution works as
intended by running tests. Debug any issues that arise, which
may involve revisiting your logic and making adjustments.
Problem Solving in
Programming
• Refactoring: Once the solution is functional, consider
improving the code by making it more efficient, readable,
or maintainable without altering its functionality.
• Documenting: Write comments and documentation to
explain your solution, making it easier for others (and
yourself) to understand in the future.
• Iterating: If necessary, revisit and revise the solution
based on feedback, new requirements, or identified
inefficiencies.
Programming Languages
• A programming language is a formal set of rules and
syntax used to write instructions that a computer can
understand and execute.
• It allows developers to create software, applications,
websites, and more by providing a way to communicate
with computers.
Key Features of programming
language
• Syntax: Each programming language has its own rules for how code should be
written, similar to grammar in human languages.
• Semantics: This refers to the meaning behind the code—what each instruction
does.
• Data Types: Programming languages have different data types (like integers,
strings, and booleans) that define what kind of data can be used and how.
• Control Structures: These allow programmers to control the flow of the
program, such as loops (repeating actions) and conditionals (making decisions).
• Libraries and Frameworks: Many languages come with pre-written code
(libraries) and tools (frameworks) to make development easier
Common Programming
Languages
• Python: Known for its readability and simplicity, often
used for web development, data analysis, and AI.
• JavaScript: Primarily used for web development to create
interactive websites.
• Java: A versatile language often used for enterprise
applications and Android development.
• C++: An extension of C, used for system/software
development and game programming.
Algorithm
• An algorithm is a step-by-step set of instructions or rules
designed to solve a specific problem or perform a task.
• It provides a clear procedure that can be followed to
achieve a desired outcome.
• Algorithms can be expressed in various forms, including
natural language, pseudocode, or programming
languages.
Characteristics of Algorithm
• Clear and Unambiguous: Each step must be clearly defined so that
there’s no confusion about what to do.
• Well-Defined Inputs: An algorithm may take one or more inputs, which
are the data it processes.
• Produces an Output: After processing the inputs, an algorithm
produces an output or result.
• Finite Steps: It should have a finite number of steps, meaning it
eventually terminates.
• Effectiveness: Each step must be simple enough to be carried out,
ideally in a reasonable amount of time.
Simple Example of an Algorithm
• Consider a recipe for making a cup of tea:
1.Boil Water.
2.Add Tea Bag to Cup.
3.Pour Boiling Water into Cup.
4.Steep for 3-5 Minutes.
5.Remove Tea Bag.
6.Add Milk or Sugar (if desired).
7.Stir and Enjoy.
Task for you
• Scenario: You are hosting a birthday party and want to
prepare a fruit salad for your guests. You have apples,
bananas, oranges, and grapes available.
• Question: Write an algorithm to prepare the fruit salad.
What steps would you take from gathering the ingredients
to serving the salad? Be clear and specific in your
instructions.
Expected Solution
1. Gather the following ingredients: apples, bananas, oranges, and grapes.
2. Wash all the fruits under running water.
3. Cut the apples and bananas into bite-sized pieces.
4. Peel the oranges and separate them into segments.
5. Wash the grapes and remove any stems.
6. Combine all the prepared fruits in a large bowl.
7. Mix the fruits gently with a spoon.
8. Serve the fruit salad in individual bowls.
Pseudo code
• Pseudocode is a simplified, informal way of describing an
algorithm using a mixture of natural language and
programming constructs.
• It helps programmers plan and visualize the logic of a
program without worrying about specific syntax of a
programming language.
• Pseudocode focuses on the logic and flow of the algorithm,
making it easier to understand and communicate ideas.
Key Features of Pseudocode
• Readability: It is written in a way that is easy to read and
understand, using plain language and straightforward
expressions.
• No Strict Syntax: There are no strict rules, so you can
use whatever notation makes sense, as long as it conveys
the intended logic.
• Structure: Pseudocode often includes common
programming structures like loops, conditionals, and
function calls.
Example of Pseudocode:
• START
• GATHER apples, bananas, oranges, grapes
• WASH all fruits
• CUT apples and bananas into pieces
• PEEL oranges and separate into segments
• WASH grapes and remove stems
• COMBINE all fruits in a bowl
• MIX gently
• SERVE in individual bowls
• END
Task For you
• Scenario: You need to create a program that performs basic arithmetic
operations on two numbers: addition, subtraction, multiplication, and
division.
• Question: Write the pseudocode to describe the steps needed to:
1.Gather two numbers from the user.
2.Calculate the sum, difference, product, and quotient of the two numbers.
3.Display the results of each operation.
• Make sure to include clear steps for each operation in your pseudocode!
• START
• PRINT "Enter the first number:"INPUT number1
• PRINT "Enter the second number:“
• INPUT number2
• SET sum = number1 + number2
• SET difference = number1 - number2
• SET product = number1 * number2
• SET quotient = number1 / number2 (if number2 ≠ 0)
• PRINT "Sum is:", sum
• PRINT "Difference is:", difference
• PRINT "Product is:", product
• PRINT "Quotient is:", quotient (if number2 ≠ 0)
• END

You might also like