SlideShare a Scribd company logo
1 of 28
Knowledge Institute of Technology, Salem-637504
(Affiliated to Anna University, Chennai)
(Accredited by NAAC)
Department of Computer Science and Engineering
(Accredited by NBA)
Course
Code
GE8151 Course Name
PROBLEM SOLVING AND
PYTHON PROGRAMMING
Year I SEM I CLASS CSE
Name of
the Faculty
Mrs.R.Sathya Priya, Assistant Professor Dept. CSE
PSPP U-I
UNIT-I ALGORITHMIC PROBLEM
SOLVING Algorithms, Building Blocks of
algorithms (statements, state, control flow,
functions), Notation (pseudo code, flow chart,
programming language), Algorithmic problem
solving, Simple strategies for developing
algorithms (iteration, recursion).
Illustrative problems: find minimum in a list,
insert a card in a list of sorted cards, Guess an
SYLLABUS
2
3
 Illustrative problems:
 Find minimum in a list.
 Insert a card in a list of sorted cards.
 Guess an integer number in a range.
 Towers of Hanoi.
Find minimum in a list
4
List
5
 List is a collection of elements stored under a
common name.
 List is commonly represented by using [ ].
 Example:
 b[ ] = {10, 20, 30, 40, 50}
b [0] b [1] b [2] b[3] b[4]
10 20 30 40 50
Finding Minimum in a list
6
 Given a list of numbers from which you are
supposed to find the minimum value.
 An algorithm is required for entering the numbers
in the list and then calculate the minimum value.
 How it works?
 Take the first number in the list and call it
minimum.
 Compare the minimum’s value with all other
values in the list one by one.
 The moment you find a smaller element than the
7
Example
Initial List 8 6 9 10 5 7 3 21
Let Min = 8, Compare MIN with every element in the list one by one.
8 6 9 10 5 7 3 21
Step 1: 6<Min, So set Min=6
8 6 9 10 5 7 3 21
Step 2: 9 > Min , So no change
8 6 9 10 5 7 3 21
Step 3: 10 > Min , So no change
8 6 9 10 5 7 3 21
Step 4: 5 < Min, So Set Min =5
8 6 9 10 5 7 3 21
Step 5: 7 > Min, So No Change.
8 6 9 10 5 7 3 21
Step 6: 3 < Min, So Set Min=3
8 6 9 10 5 7 3 21
Step 7: 21 > Min , So No change
So the minimum value in the given list is 3.
8
Algorithm:
Step 1: Start the program.
Step 2: Read the number of elements in list n.
Step 3: Initialize i=0 as the starting index
Step Repeat steps 4.1 and 4.2 until the while
condition is true (i<n ) , otherwise continue with
step5 .
Step 4.1: Read the element a[i]
Step 4.2: i=i+1
Step 5: initialize k=1, Min=a[0]
Step 6: Repeat step 6.1 and 6.2 until the while
condition is true (k<n), otherwise continue with
step7.
Step 6.1: If a[k]<Min then set Min=a[k]
Step 6.2: k=k+1
9
Pseudo code:
READ N
INITIALIZE i=0,
WHILE i<n
READ a[i]
SET i=i+1
ENDWHILE
INITIALIZE Min=a[0], k=1
WHILE k<n
IF a[k] < Min THEN
Min=a[k]
k=k+1
ENDWHILE
PRINT Min
10
Flow chart
Inserting a Card into a list of sorted
Cards
11
Inserting a Card into a list of sorted
Cards
12
 Inserting a card in a list of sorted cards is same as
inserting an element into a sorted list of numbers.
 For this, start from the end of the list and compare
the new element with the elements of the list to
find a suitable position at which the new element
has to be inserted.
 While comparing, also shift the elements one step
ahead to create a vacancy for the new element.
13
Example : Insert the element 23 into the given sorted list
Position 0 1 2 3 4 5 6
Original list 10 15 20 25 30 35
Step 1: 23>35 ? No so move 35 to position 6
10 15 20 25 30 35
Step 2: 23>30 ? No so move 30 to position 5
10 15 20 25 30 35
Step 3: 23>25 ? No so move 25 to position 4
10 15 20 25 30 35
Step 4: 23>20 ? Yes insert 23 at position 3
10 15 20 23 25 30 35
14
Algorithm:
Step 1: Start the program.
Step 2: Read the number of elements in list n.
Step 3: Initialize i=0
Step 4: Repeat steps 4.1 and 4.2 until the while condition is true
(i<n ) , otherwise continue with step5 .
Step 4.1: Read the element a[i] –in sorted order
Step 4.2: i=i+1
Step 5: Read the element to be inserted X
Step 6: Set j=n-1
Step 7: Repeat steps 7.1 and 7.2 until the while condition is true
( (j>=0) && (X<a[j])) otherwise continue with step8 .
Step 7.1: a[j+1]=a[j]
Step 7.2: Set j=j-1
Step 8: a[j+1] = X
Step 9: Stop the Program.
15
Pseudo code:
READ n
SET i=0
WHILE i<n
READ a[i]
i=i+1
ENDWHILE
READ X
SET j=n-1
WHILE j>=0 && a[j]>X
a[j+1]=a[j]
j=j-1
ENDWHILE
a[j+1]=X
16
Flow chart
Guess an integer number in a range.
17
Guess an integer number in a
range
18
 It is a game.
 The user selects a range.
 Let’s say User selected a range, i.e., from A to B,
where A and B belong to Integer.
 Some random integer will be selected by the system and
the user has to guess that integer in the minimum number
of guesses.
 There is no limit on number of guesses.
Example:
 If the User inputs range, let’s say from 1 to 100. And System
randomly selected 42 as the integer.
 Now the guessing game started, if the user entered 50 as
his/her first guess. The compiler shows “Try Again! You
guessed too high”.
 Now the second guess started.
19
Algorithm:
Step 1: Start the program.
Step 2: Read the range of integers Start, End.
Step 3: Set num = random number from Start to End.
Step 4: Set =1
Step 5: Read the Guess number as G
Step 6: If G=num then print ‘you win in the ith guess’
Step 7: Else If G>num the print ‘your guess is too high’ go to step
5.
Step 8: Else print ‘your guess is too low’ go to step 5.
Step 9: Stop the program.
20
Pseudo code:
READ Start, End
SET num=Random(Start, End)
SET i =1
LOOP:
READ G
IF G=num THEN
PRINT ‘You win in ith turn’
EXIT
ELSEIF G>num THEN
PRINT ‘Too High’
ELSE
PRINT ‘Too Low’
i=i+1
ENDLOOP
21
Flowchar
t
Tower of Hanoi
22
Tower of Hanoi
23
 Tower of Hanoi is a mathematical puzzle where we
have three poles (namely A, B, C) and n disks.
 The objective of the puzzle is to move the disks from
pole A to Pole C using the Pole B.
 simple rules:
1) Only one disk can be moved at a time.
2) Each move consists of taking the upper disk from
one of the poles and placing it on top of another pole
i.e. a disk can only be moved if it is the uppermost
disk on a pole.
3) No disk may be placed on top of a smaller disk.
Ex: with two disks
24
Ex: with Three disks
25
26
Algorithm:
Step 1: Start
Step 2: Read the number of disc n
Step 3: Call the function TOH(n, A, B, C)
Step 4: Stop
 Algorithm for Function Definition TOH
Step 1: if n==1 then Move disc from A to C and
go to step 5 else continue with step 2
Step 2: Call the function TOH(n-1,A,C,B)
Step 3: Move disc n from A to C
Step 4: Call the function TOH(n-1,B,A,C)
Step 5: Return
27
Pseudo code:
READ n
CALL TOH(n,A,B,C)
Function Definition TOH(n, A, B, C)
IF n==1
Move disc from A to C
return
ELSE
CALL TOH(n-1,A,C,B)
Move disc n from A to C
CALL TOH(n-1,B,A,C)
Return
28
Flowcha
rt

More Related Content

Similar to UNIT I_PSPP - Illustrative Problems (1).pptx

25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manualkamesh dagia
 
Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureNurjahan Nipa
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applicationsyazad dumasia
 
14-sorting (3).ppt
14-sorting (3).ppt14-sorting (3).ppt
14-sorting (3).pptyasser3omr
 
Decision Science.pdf
Decision Science.pdfDecision Science.pdf
Decision Science.pdfpandeyaman577
 
CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfsaneshgamerz
 
Insersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmInsersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmEhsan Ehrari
 
Updated Lab3.docx
Updated Lab3.docxUpdated Lab3.docx
Updated Lab3.docxAleezaAnjum
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithmDHANIK VIKRANT
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0BG Java EE Course
 
Array data structure
Array data structureArray data structure
Array data structureharsh112327
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Pramit Kumar
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithmspppepito86
 

Similar to UNIT I_PSPP - Illustrative Problems (1).pptx (20)

25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual
 
Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structure
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applications
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
 
14-sorting (3).ppt
14-sorting (3).ppt14-sorting (3).ppt
14-sorting (3).ppt
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
 
Decision Science.pdf
Decision Science.pdfDecision Science.pdf
Decision Science.pdf
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Sorting2
Sorting2Sorting2
Sorting2
 
CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
 
Insersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmInsersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in Algoritm
 
Updated Lab3.docx
Updated Lab3.docxUpdated Lab3.docx
Updated Lab3.docx
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
 
Array data structure
Array data structureArray data structure
Array data structure
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Ada notes
Ada notesAda notes
Ada notes
 

More from RSathyaPriyaCSEKIOT

More from RSathyaPriyaCSEKIOT (9)

c programming session 1.pptx
c programming session 1.pptxc programming session 1.pptx
c programming session 1.pptx
 
UNIT-4
UNIT-4UNIT-4
UNIT-4
 
unit-2 mc.pdf
unit-2 mc.pdfunit-2 mc.pdf
unit-2 mc.pdf
 
unit-5
unit-5unit-5
unit-5
 
unit-1 notes
unit-1 notesunit-1 notes
unit-1 notes
 
unit-4
unit-4 unit-4
unit-4
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
pattern-printing-in-c.pdf
pattern-printing-in-c.pdfpattern-printing-in-c.pdf
pattern-printing-in-c.pdf
 
C program full materials.pdf
C program  full materials.pdfC program  full materials.pdf
C program full materials.pdf
 

Recently uploaded

Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 

Recently uploaded (20)

Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 

UNIT I_PSPP - Illustrative Problems (1).pptx

  • 1. Knowledge Institute of Technology, Salem-637504 (Affiliated to Anna University, Chennai) (Accredited by NAAC) Department of Computer Science and Engineering (Accredited by NBA) Course Code GE8151 Course Name PROBLEM SOLVING AND PYTHON PROGRAMMING Year I SEM I CLASS CSE Name of the Faculty Mrs.R.Sathya Priya, Assistant Professor Dept. CSE PSPP U-I
  • 2. UNIT-I ALGORITHMIC PROBLEM SOLVING Algorithms, Building Blocks of algorithms (statements, state, control flow, functions), Notation (pseudo code, flow chart, programming language), Algorithmic problem solving, Simple strategies for developing algorithms (iteration, recursion). Illustrative problems: find minimum in a list, insert a card in a list of sorted cards, Guess an SYLLABUS 2
  • 3. 3  Illustrative problems:  Find minimum in a list.  Insert a card in a list of sorted cards.  Guess an integer number in a range.  Towers of Hanoi.
  • 4. Find minimum in a list 4
  • 5. List 5  List is a collection of elements stored under a common name.  List is commonly represented by using [ ].  Example:  b[ ] = {10, 20, 30, 40, 50} b [0] b [1] b [2] b[3] b[4] 10 20 30 40 50
  • 6. Finding Minimum in a list 6  Given a list of numbers from which you are supposed to find the minimum value.  An algorithm is required for entering the numbers in the list and then calculate the minimum value.  How it works?  Take the first number in the list and call it minimum.  Compare the minimum’s value with all other values in the list one by one.  The moment you find a smaller element than the
  • 7. 7 Example Initial List 8 6 9 10 5 7 3 21 Let Min = 8, Compare MIN with every element in the list one by one. 8 6 9 10 5 7 3 21 Step 1: 6<Min, So set Min=6 8 6 9 10 5 7 3 21 Step 2: 9 > Min , So no change 8 6 9 10 5 7 3 21 Step 3: 10 > Min , So no change 8 6 9 10 5 7 3 21 Step 4: 5 < Min, So Set Min =5 8 6 9 10 5 7 3 21 Step 5: 7 > Min, So No Change. 8 6 9 10 5 7 3 21 Step 6: 3 < Min, So Set Min=3 8 6 9 10 5 7 3 21 Step 7: 21 > Min , So No change So the minimum value in the given list is 3.
  • 8. 8 Algorithm: Step 1: Start the program. Step 2: Read the number of elements in list n. Step 3: Initialize i=0 as the starting index Step Repeat steps 4.1 and 4.2 until the while condition is true (i<n ) , otherwise continue with step5 . Step 4.1: Read the element a[i] Step 4.2: i=i+1 Step 5: initialize k=1, Min=a[0] Step 6: Repeat step 6.1 and 6.2 until the while condition is true (k<n), otherwise continue with step7. Step 6.1: If a[k]<Min then set Min=a[k] Step 6.2: k=k+1
  • 9. 9 Pseudo code: READ N INITIALIZE i=0, WHILE i<n READ a[i] SET i=i+1 ENDWHILE INITIALIZE Min=a[0], k=1 WHILE k<n IF a[k] < Min THEN Min=a[k] k=k+1 ENDWHILE PRINT Min
  • 11. Inserting a Card into a list of sorted Cards 11
  • 12. Inserting a Card into a list of sorted Cards 12  Inserting a card in a list of sorted cards is same as inserting an element into a sorted list of numbers.  For this, start from the end of the list and compare the new element with the elements of the list to find a suitable position at which the new element has to be inserted.  While comparing, also shift the elements one step ahead to create a vacancy for the new element.
  • 13. 13 Example : Insert the element 23 into the given sorted list Position 0 1 2 3 4 5 6 Original list 10 15 20 25 30 35 Step 1: 23>35 ? No so move 35 to position 6 10 15 20 25 30 35 Step 2: 23>30 ? No so move 30 to position 5 10 15 20 25 30 35 Step 3: 23>25 ? No so move 25 to position 4 10 15 20 25 30 35 Step 4: 23>20 ? Yes insert 23 at position 3 10 15 20 23 25 30 35
  • 14. 14 Algorithm: Step 1: Start the program. Step 2: Read the number of elements in list n. Step 3: Initialize i=0 Step 4: Repeat steps 4.1 and 4.2 until the while condition is true (i<n ) , otherwise continue with step5 . Step 4.1: Read the element a[i] –in sorted order Step 4.2: i=i+1 Step 5: Read the element to be inserted X Step 6: Set j=n-1 Step 7: Repeat steps 7.1 and 7.2 until the while condition is true ( (j>=0) && (X<a[j])) otherwise continue with step8 . Step 7.1: a[j+1]=a[j] Step 7.2: Set j=j-1 Step 8: a[j+1] = X Step 9: Stop the Program.
  • 15. 15 Pseudo code: READ n SET i=0 WHILE i<n READ a[i] i=i+1 ENDWHILE READ X SET j=n-1 WHILE j>=0 && a[j]>X a[j+1]=a[j] j=j-1 ENDWHILE a[j+1]=X
  • 17. Guess an integer number in a range. 17
  • 18. Guess an integer number in a range 18  It is a game.  The user selects a range.  Let’s say User selected a range, i.e., from A to B, where A and B belong to Integer.  Some random integer will be selected by the system and the user has to guess that integer in the minimum number of guesses.  There is no limit on number of guesses. Example:  If the User inputs range, let’s say from 1 to 100. And System randomly selected 42 as the integer.  Now the guessing game started, if the user entered 50 as his/her first guess. The compiler shows “Try Again! You guessed too high”.  Now the second guess started.
  • 19. 19 Algorithm: Step 1: Start the program. Step 2: Read the range of integers Start, End. Step 3: Set num = random number from Start to End. Step 4: Set =1 Step 5: Read the Guess number as G Step 6: If G=num then print ‘you win in the ith guess’ Step 7: Else If G>num the print ‘your guess is too high’ go to step 5. Step 8: Else print ‘your guess is too low’ go to step 5. Step 9: Stop the program.
  • 20. 20 Pseudo code: READ Start, End SET num=Random(Start, End) SET i =1 LOOP: READ G IF G=num THEN PRINT ‘You win in ith turn’ EXIT ELSEIF G>num THEN PRINT ‘Too High’ ELSE PRINT ‘Too Low’ i=i+1 ENDLOOP
  • 23. Tower of Hanoi 23  Tower of Hanoi is a mathematical puzzle where we have three poles (namely A, B, C) and n disks.  The objective of the puzzle is to move the disks from pole A to Pole C using the Pole B.  simple rules: 1) Only one disk can be moved at a time. 2) Each move consists of taking the upper disk from one of the poles and placing it on top of another pole i.e. a disk can only be moved if it is the uppermost disk on a pole. 3) No disk may be placed on top of a smaller disk.
  • 24. Ex: with two disks 24
  • 25. Ex: with Three disks 25
  • 26. 26 Algorithm: Step 1: Start Step 2: Read the number of disc n Step 3: Call the function TOH(n, A, B, C) Step 4: Stop  Algorithm for Function Definition TOH Step 1: if n==1 then Move disc from A to C and go to step 5 else continue with step 2 Step 2: Call the function TOH(n-1,A,C,B) Step 3: Move disc n from A to C Step 4: Call the function TOH(n-1,B,A,C) Step 5: Return
  • 27. 27 Pseudo code: READ n CALL TOH(n,A,B,C) Function Definition TOH(n, A, B, C) IF n==1 Move disc from A to C return ELSE CALL TOH(n-1,A,C,B) Move disc n from A to C CALL TOH(n-1,B,A,C) Return