You are on page 1of 98

School of

Computing

19CSE100
Problem Solving and Algorithmic
Thinking
L-T-P-C
LECTURES TUTORIALS

PRACTICALS CREDITS

2
Course Objective

▪ To provide the foundations of algorithmic thinking and


problem solving
▪ To focus on principles and methods rather than on
systems and tools thus providing transferable skills to
any other domain
▪ To provide foundations for developing computational
perspective of one’s own discipline
3
Syllabus – Unit I

Problem Solving and Algorithmic Thinking Overview –


problem definition, logical reasoning; Algorithm – What is
an algorithm, practical examples, properties,
representation, algorithms vs programs.

4
Syllabus – Unit II

▪ Algorithmic thinking – Constituents of algorithms –


Sequence, Selection and Repetition, input-output;
Computation – expressions, logic; algorithms vs
programs,
▪ Problem Understanding and Analysis – problem
definition, input-output, variables, name binding, data
organization: lists, arrays etc. algorithms to programs.
5
Syllabus – Unit III

▪ Problem solving with algorithms – Searching and


Sorting, Evaluating algorithms, modularization,
recursion.
▪ C for problem solving – Introduction, structure of C
programs, data types, data input, output statements,
control structures.

6
Text Books

7
Course Outcomes (Cos)

▪ CO1: Apply algorithmic thinking to understand, define and


solve problems
▪ CO2: Design and implement algorithm(s) for a given problem
▪ CO3: Apply the basic programming constructs for problem
solving
▪ CO4: Understand an algorithm by tracing its computational
states, identifying bugs and correcting them

8
Do we have lab for PSAT?
Yes
Tools Used: Flowgramming
Flowgorithm
Evaluation

65 marks from
Continuous Assessments

35 marks from
End Semester Examination

11
Assessment Pattern
Assessment Component Marks
Internal Assessment (50 Marks)

Continuous Assessment 3 Tutorial-Quiz


Lab Evaluation
15
(Theory) (3(2xx57.5
marks)
marks)

Lab Evaluation
Project
20
Continuous Assessment (2 x 10 marks)
(Lab) Evaluation on a Coding Platform
10
(10 marks)
Periodical 1 & 2
Periodical 20
(10 marks + 10 marks)
External Assessment (50 Marks)
Paper-pen
Lab - oriented Exam
End Semester 35
(35 marks)
Total 100
12
Problem Solving
What is Problem Solving?

▪ Problem solving is the process of identifying a


problem, developing possible solution paths,
and taking the appropriate course of action

14
Problem solving consists of
“ moving from a given initial
situation to a desired goal

What Can I do
to move from
Initial A to B? Desired
Situation (A) Goal (B)

15
Problem solving is the
“ application of idea, skills, or
factual information to achieve
the solution to a problem or to
reach a desired outcome

16
A Framework for Problem Solving

Understanding the Making a Plan of Carrying out the


Problem Solution Plan

Looking Back

17
What is Problem?

a proposition in mathematics or
a question raised for inquiry,
physics stating something to be
consideration, or solution
done

a situation, person, or task that


needs attention and needs to be
dealt with or solved

18
Types of Problems

Well-Defined Poorly-Defined
Problems Problems

19
Types of Problems

Routine Poorly-Defined
Problems Problems

20
Activity Time – Design Challenge 1
▪ Design a one button remote for television

21
Questions that come into your mind
▪ What is the purpose of the Remote?
▪ What are the basics operations to be included?
▪ Who are the users?
▪ Nature of button
▪ Functionalities of button
▪ What is the shape / Dimensions ?
▪ How it is connected to device?

22
“ Problem Statement
A problem statement is a
concise description of the
problem or issues that
someone/something seeks
to address

23
The key elements of a problem statement

Ideal Reality
Situation

Consequences Proposals

24
Problem Statement: One Button Remote

To design a one button remote to control the TV


operations.

25
Activity Time – Design Challenge 2
▪ Design an ATM interface for kids

26
Questions for Kid’s ATM

▪ Why ATM for Kids?


▪ Height of machine ?
▪ Design of the interface ?
▪ Functionalities of ATM
▪ Security aspect

27
From Kids’ Perspective - Why ATM for Kids?

▪ Why would a 5 to 12-year-old need to access the ATM?


▪ money for bus fare, school lunch, snacks, gifts, etc.
▪ deposit allowance and earned wages (from a newspaper route,
selling lemonade, etc.)

28
From Parents’ Perspective - Why ATM for Kids?

▪ Why would parents of 5 to 12-year old kids want their children to


be able to have their own account and access their own money?
▪ There are teachable moments in earning and spending one’s
own money
▪ Perhaps asking children to make these financial decisions can
teach them, at an early age, about financial liquidity

29
The necessary constraints

▪ Varying heights of children ages 5 to 12


▪ Ability or lack of ability to digest information in a somewhat
technical language (deposits, withdrawal, over draft, etc.)
▪ Ability to remember to take out a debit card after withdrawal
▪ Ability to remember a PIN
▪ …

30

The Fundamental Requirements
▪ The ATM machine needs to be adjustable
▪ If we don’t ask for debit cards, there must
be another way to identify the user
▪ The ability to deposit change
▪ A limit on the amount that can be
withdrawn
▪ A prompt to ask what the money is for
31
32

PROTOTYPING
33

PROTOTYPING
34

PROTOTYPING
35

PROTOTYPING
36

PROTOTYPING
37

PROTOTYPING
38

PROTOTYPING
39

PROTOTYPING
40

PROTOTYPING
41

PROTOTYPING
42

PROTOTYPING
Constraints not cosidered here

▪ What happens if the child is under duress?


▪ What if a school bully is making the child withdraw
money.
▪ Should there be a panic button?
▪ What does it do?
▪ How do we prevent the abuse of this panic button?

43
Constraints not cosidered here

▪ Even if there is an auditory option, how will the buttons


be communicated?
▪ Is it through voice commands instead of a visual interface?
▪ If so, would you really want others to hear the account
summary?
▪ How can you keep the transaction private without bystanders
hearing how much is in the account?

44
Activity time – Peculiar Problem 1
Car allergic to Vanilla Ice cream
▪ Strange complaint @ Pontiac Division of General Motors
▪ “My car won't start after I buy a Vanilla Ice cream” – The complaint

45
Activity time – Peculiar Problem 2
Increasing ice cream sales causes more shark attacks
▪ Do sharks like to eat people that are full of ice cream?
▪ Confounding Variable: Temperature

46
Activity time – Peculiar Problem 3
Diaper-beer Syndrome
▪ Wal-Mart, the world’s largest retailer, supposedly found out that
there are certain times at which beer and diapers sell particularly
well together
▪ Based on working men who had been asked to pick up diapers on
their way home from work

47
“ Not all correlations are
causations…!

48
Takeaway assignment - Desert Survival
Your flight crashed in a desert and the
below 10 items were saved before the
flight caught fire. Prioritize them and
explain your priority list

49
Time to recall

▪ Problem
▪ A doubtful or difficult matter requiring a solution
▪ Something hard to understand or accomplish or deal
with

50
Reflections

▪ How were you solving the problems?


▪ What do you think is the reason for different solutions?
▪ Are all solutions equally good or one or few solutions
better than others? How did you decide the goodness
of the solution?
▪ What do you think is/are needed for solving problems?

51
Reflections

When do you think a problem is solvable


(using computers)?

52
Problem Identification

▪ Problem Statement : “I need a cake for my grandmother’s


birthday party.”
▪ Questions with respect to making of the cake
▪ What kind of cake does she like?
▪ Does she have any allergies?
▪ Does she have any health issues?
▪ Any writing on the cake? Decorations? Candies?
53
Problem Identification

Do we Need to get more information?

54
Problem Idetification

▪ Are the below questions sufficient?


▪ Is the celebration with family members or you are sending
invitation outside?
▪ Where is the party - indoors or outdoors?
▪ What is the date/time for the party?

55
“ Searching for a solution
• Taste & Style?
• Allergies?


She likes chocolate and fruit.
Nuts
• None
• Health issues?
• A simple “Happy Birthday” with simple
• Presentation?
decorations, flowers and a base. No candles.
• Party context?
• Indoor - 15 members
• Budget? • $ 800

56
Problem Identification - Iteration

“I need a birthday cake for my grandmother’s birthday


party. The cake should include chocolate and fruit, and
“I need a cake for my grandmother’s birthday party”
have a simple frosting, and it should not include nuts. The
cake should include some flowers and say
Happy Birthday !”

57
Problem Understanding

Dissect problem into components


(problems and sub-problems)

Remove ambiguity and


extraneous information

Determine knowns and unknowns


Beware of your assumptions

58
4th May I NEED A CAKE FOR MY Budget: $ 800
GRANDMOTHER’S BIRTHDAY
PARTY

Cake should include The cake should


chocolate and fruit feed 15 people

Presentation: Some flowers


Build a cake base decorated
and piping, “Happy
with some photos
Birthday” and no candles

The frosting should be The cake should be


simple without nuts transported to her retirement
home on May 4th for a 4pm
indoor party
4th May I NEED A CAKE FOR MY Budget: $ 800
GRANDMOTHER’S BIRTHDAY
PARTY

Cake should include The cake should


chocolate and fruit feed 15 people

What are some algorithms for the cake


and frosting? Any patterns we can use?
The frosting should be
simple without nuts
4th May I NEED A CAKE FOR MY Budget: $ 800
GRANDMOTHER’S BIRTHDAY
PARTY

Cake should include The cake should


chocolate and fruit feed 15 people

Build a cake base decorated


The frosting should be with some photos
simple without nuts

What are some algorithms for building the


cake base? Is this now too much? Should we
remove the fancy base and focus on the
cake?
4th May I NEED A CAKE FOR MY Budget: $ 800
GRANDMOTHER’S BIRTHDAY
PARTY

The cake should


Cake should include
feed 15 people
chocolate and fruit

Presentation: Some flowers Build a cake base decorated


and piping, “Happy with some photos
Birthday” and no candles

The cake should be transported to


The frosting should be her retirement home on May 4th
simple without nuts for a 4pm indoor party

What is the algorithm for transporting the cake?


Moving to a Solution

▪ How to Solve the problem?


▪ Identifying pattern
▪ Have we solved similar kind of problem?
▪ What are different ways we can find solution?

63
Budget: $ 800

Moving to a solution
“I need a cake for my grandmother’s birthday party.”

Cake Algorithm Frosting Algorithm Presentation Algorithm Transportation Algorithm

3rd May 4th May

Now, you could think about turning these “algorithms”


into a more specific set of instructions (or programs)
for some computational agent to enact. 64
Moving to solution

Finished Cake
Cake Algorithm

Presentation Algorithm Transportation Algorithm

Frosting Algorithm 4th May

3rd May
65
Can a computer Do I need to break down
help solve my my problem into smaller

Corner Stones problem? Is this


problem suited for
pieces to help solve it?
How do the situations to
the smaller pieces fit
a computer? together to solve the main
problem?

Problem Problem
Identification Decomposition

Have I seen problem – Are the aspects of


solving approaches in your problem that
the past that can help are not necessarily
me solve one of the
needed now to solve
problems or sub - Pattern your problem?
problems that I have Recognition Abstraction
there?

66
Problem identification
▪ Topic: What is the big problem you are trying to solve? Can you
state this in a problem statement? Is the problem statement too
broad or vague?
▪ Data: What information or data do you have to contribute to a
problem solving approach? What other information or data might
you need?
▪ Feasibility: Can you solve the problem given what you know ?Is this
problem solvable with a computer?

67
Problem identification
▪ Have we identified a problem that is “solvable” with a computer?
Believe it or not, some problems can’t be necessarily solved with
computers!
▪ How can we know when a problem is a good candidate for using a
computer to generate a solution?
▪ How might we incorporate different kinds to solve this type of
problem?

68
Abstraction
▪ Can we identify non - essential aspects of our problem that we can
ignore?
▪ This involves filtering out, or ignoring aspects of the problem or
any patterns you might have identified in order to concentrate on
the necessary aspects of the problem or potential solution
▪ Think about…
▪ Asking whether some parts of the problem less relevant to a
successful outcome? Are any extraneous?

69
Decomposition
▪ You have a problem statement… Can we break our big problem
down into smaller sub - problems that are more straightforward to
solve?
▪ If the problem statement is too big, it is difficult to see how you can go
about developing a conceptual solution
▪ Solving the sub-problems can then help you arrive at a solution for
your original problem statement

70
Pattern recognition
▪ Can we see familiar patterns or characteristics that can lead us to
potential solutions?
▪ Finding the similarities or patterns among the smaller, decomposed
problems that can help us solve these problems more efficiently
▪ Think about…
▪ Have you seen solutions to similar problems previously that we can use
here?
▪ How is this problem the same or different from other problems you have
identified or addressed?
71
Activity Time – Spit-Not-Fop Game
▪ Rules
▪ Write down the words:
▪ SPIT, NOT, SO, AS, IF, IN, PAN, FAT, FOP
▪ The game is played as follows:
▪ The first player chooses a word that is on the list, crosses it out and
writes it in front of them
▪ The second player then does the same thing with a word not crossed out
▪ The players take turns to do this until one person wins
The winner is the first player to hold three words
72
containing the same letter.
Did you find any winning

“ strategy?

73
Do you know a game that resembles

“ this?

74
Appropriate problem
“ representation or transformation
to convert it to a problem whose
solutions are well known.

75
“ Locked-in Syndrome
▪ It leaves you with all your mental abilities
intact, but totally paralyzed except
perhaps for the blink of an eye

▪ Your intelligent mind is locked inside a


useless body, able to sense everything
but unable to communicate

77
Can a computer scientist help
someone who suffered a
locked-in syndrome?
Jean Dominique Bauby

79
The diving bell and the butterfly

200,000 blinks
2 months
3 hours/day
80
Designing a way of communication for Bauby

Can you devise a means for Bauby


to communicate?

81
A simple way

Count blinks and map it to the


alphabets
2 part algorithm – protocol
(one for the Bauby and one for the helper)

82
Helper can speak

Helper reads alphabets and Bauby


blinks at the right alphabet

83
Beyond alphabets

How to handle punctuations?


What if there is a mistake?

84
Helper can Think too!!!

Halfway through blinking helper


can predict the word
Predictive texting in your smartphones!

85
Helper Can Speak!!! – How fast is this?

Best/Worst/Average cases

86
Can we reduce the number of questions?

Computer Scientists can do it!

87
Let’s play a game

88
Winning at 20 questions

89
5 Questions

92
Looking for Patterns

93
Looking for Patterns

94
Searching problem

▪ The problem is a ‘search problem’: given a series of


things, find one particular thing we are looking for
▪ The solutions to this problem are called search
algorithms
▪ They are methodical ways of finding things

95
Activity Time

Write instructions that swap positions of black and white


pieces

96
Best Solution
▪ Move piece in square 2 to square 3
▪ Jump piece in square 4 to square 2
▪ Move piece in square 5 to square 4
▪ Jump piece in square 3 to square 5
▪ Jump piece in square 1 to square 3
▪ Move piece in square 0 to square 1
▪ Jump piece in square 2 to square 0
▪ Jump piece in square 4 to square 2
97
Best Solution contd.
▪ Jump piece in square 6 to square 4
▪ Move piece in square 5 to square 6
▪ Jump piece in square 3 to square 5
▪ Jump piece in square 1 to square 3
▪ Move piece in square 2 to square 1
▪ Jump piece in square 4 to square 2
▪ Move piece in square 3 to square 4

98

You might also like