Professor, Computer Science and Engineering Department

Slides:



Advertisements
Similar presentations
Tower of Hanoi Tower of Hanoi is a mathematical puzzle invented by a French Mathematician Edouard Lucas in The game starts by having few discs stacked.
Advertisements

AE1APS Algorithmic Problem Solving John Drake
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
1 The Limits of Computation Intractable and Non-computable functions.
Chapter 2 Matrices Finite Mathematics & Its Applications, 11/e by Goldstein/Schneider/Siegel Copyright © 2014 Pearson Education, Inc.
CMPS1371 Introduction to Computing for Engineers SORTING.
Graphs Intro G.Kamberova, Algorithms Graphs Introduction Gerda Kamberova Department of Computer Science Hofstra University.
1 On a question of Leiss regarding the Towers of Hanoi problem.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
An Euler Circuit is a cycle of an undirected graph, that traverses every edge of the graph exactly once, and ends at the same node from which it began.
Linear Programming Applications
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Design and Analysis of Algorithms - Chapter 11 Algorithm An algorithm is a.
TK3043 Analysis and Design of Algorithms Introduction to Algorithms.
Introduction Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
Towers of Hanoi. Introduction This problem is discussed in many maths texts, And in computer science an AI as an illustration of recursion and problem.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions and Recursion Outline Function Templates Recursion Example Using Recursion: The Fibonacci Series.
Module 1- Getting Started Tell me what to do Using sets of instructions…
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
Mathematical Induction I Lecture 4: Sep 16. This Lecture Last time we have discussed different proof techniques. This time we will focus on probably the.
Lecture 5 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
ALGORITHMS.
Combinatorial Optimization Lecturer Kononov Alexander Veniaminovich.
Pass the Buck Every good programmer is lazy, arrogant, and impatient. In the game “Pass the Buck” you try to do as little work as possible, by making your.
Quiz highlights 1.Probability of the song coming up after one press: 1/N. Two times? Gets difficult. The first or second? Or both? USE THE MAIN HEURISTICS:
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
 Tower of Hanoi – Link 1 Tower of Hanoi – Link 1  Tower of Hanoi – Link 2 Tower of Hanoi – Link 2.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Divide and Conquer Prudence Wong
CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 9: The Tower of Hanoi.
Dr. Naveed Riaz Design and Analysis of Algorithms 1 1 Formal Methods in Software Engineering Lecture # 27.
1 Recursion Recursive function: a function that calls itself (directly or indirectly). Recursion is often a good alternative to iteration (loops). Its.
(CSC 102) Lecture 30 Discrete Structures. Graphs.
Hubert Chan (Chapters 1.6, 1.7, 4.1)
An Introduction to Graph Theory
CSE15 Discrete Mathematics 03/06/17
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
Limitation of Computation Power – P, NP, and NP-complete
The Acceptance Problem for TMs
Applied Discrete Mathematics Week 2: Functions and Sequences
TK3043 Analysis and Design of Algorithms
COMP108 Algorithmic Foundations Divide and Conquer
COMP108 Algorithmic Foundations Divide and Conquer
Computer Science Programming Chapter 1, Sections
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
Hubert Chan (Chapters 1.6, 1.7, 4.1)
Topics Introduction to Repetition Structures
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Data Structures Recursion CIS265/506: Chapter 06 - Recursion.
Enough Mathematical Appetizers!
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
Dynamic Programming Characterize the structure (problem state) of optimal solution Recursively define the value of optimal solution Compute the value of.
Data Structures Review Session
The Wolf, the Goat, and the Cabbage
Applied Discrete Mathematics Week 6: Computation
Introduction to Algorithms and Programming
Dynamic Programming Characterize the structure (problem state) of optimal solution Recursively define the value of optimal solution Compute the value of.
4. Computational Problem Solving
Sorting "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
Haskell Tips You can turn any function that takes two inputs into an infix operator: mod 7 3 is the same as 7 `mod` 3 takeWhile returns all initial.
October 6, 2011 Dr. Itamar Arel College of Engineering
Topics Introduction to Repetition Structures
Discrete Mathematics and Its Applications
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Solving Problems by Searching
Algorithms Tutorial 27th Sept, 2019.
Presentation transcript:

Professor, Computer Science and Engineering Department ALGORITHMIC THINKING G.H.Joshi Professor, Computer Science and Engineering Department BVB College of Engineering and Technology Vidyanagar, Hubli. E_mail : ghjoshi@bvb.edu

Problem 1 A peasant finds himself on a riverbank with a wolf, a goat, and a head of cabbage. He needs to transport all three to the other side of the river in his boat. However, the boat has room for only the peasant himself and one other item (either the wolf, the goat, or the cabbage). In his absence, the wolf would eat the goat, and the goat would eat the cabbage. Solve this problem for the peasant or prove it has no solution. (Note: The peasant is a vegetarian but does not like cabbage and hence can eat neither the goat nor the cabbage to help him solve the problem. And it goes without saying that the wolf is a protected species.)

Solution Let P, w, g, and c stand for the peasant, wolf, goat, and cabbage head, respectively. The following is principal sequences that solve the problem: Intial Final BANK B P G G P W G W P W C W C PWGC R I V E R P W C C P G C P G BANK A 1 2 3 7 4 6 5

Solution Initially P,W,G and C are on BANK A Person P moves from BANK A to BANK B with Goat G . Person P moves from BANK B to BANK A. Person P moves from BANK A to BANK B with Wolf W. Person P moves from BANK B to BANK A with Goat G . Person P moves from BANK A to BANK B with Cabbage C . Person P moves from BANK B to BANK A skip to

Problem 2 There are four people who want to cross a bridge; they all begin on the same side. You have 17 minutes to get them all across to the other side. It is night, and they have one flashlight. A maximum of two people can cross the bridge at one time. Any party that crosses, either one or two people, must have the flashlight with them. The flashlight must be walked back and forth; it cannot be thrown, for example. Person 1 takes 1 minute to cross the bridge, person 2 takes 2 minutes, person 3 takes 5 minutes, and person 4 takes 10 minutes. A pair must walk together at the rate of the slower person’s pace. For example, if person 1 and person 4 walk across first, 10 minutes have elapsed when they get to the other side of the bridge. If person 4 returns the flashlight, a total of 20 minutes have passed and you have failed the mission. (Note: According to a rumor on the Internet, interviewers at a well-known software company located near Seattle have given this problem to interviewees.)

Solution Let 1, 2, 5, 10 be labels representing the persons of the problem, f represent the flashlight’s location, and the number in the parenthesis be the total amount of time elapsed. The following sequence of moves solves the problem: BANK B f,1,2 2 f,2,5,10 5,10 f,1,2,5,10 R I I V E R f,1,5,10 1 BANK A (0) (2) (3) (13) (15) (17) Time in minutes

Solution 1. Initially all the persons 1,2,5,10 and flashlight are on BANK A. 2. Persons 1,2 move with flashlight from BANK A to BANK B. 3. Person 1 moves with flashlight from BANK B to BANK A. 4. Persons 5,10 moves with flashlight from BANK A to BANK B. 5. Person 2 moves with flashlight from BANK B to BANK A. 6. . Persons 1,2 moves with flashlight from BANK A to BANK B. skip to

Algorithm Definition 1: An algorithm is a precise, step-by-step set of instructions for solving a task. Definition 2: An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time. An algorithm does not solve a task; it gives you a series of steps that, if executed correctly, will result in a solution to a task.

Characteristics of an algorithm Finiteness terminates after a finite number of steps Definiteness rigorously and unambiguously specified Input valid inputs are clearly specified Output can be proved to produce the correct output given a valid input Effectiveness steps are sufficiently simple and basic Eg1. Eg2.

Algorithmic Thinking It is the ability to understand, execute, evaluate and create algorithms. To be an algorithmic thinker you need the ability to understand and execute algorithms. Some people find it easy to follow a series of precise instructions while other people find it very challenging. Some people seem to lack the patience and diligence required to follow a step-by-step plan. However, it is a valuable skill that all people should master. Algorithmic thinking requires patience because each instruction must be executed in its correct sequence without skipping ahead or "glossing over" some of the instructions. In addition, algorithmic thinking requires diligence and perseverance.

Algorithmic thinking also requires the ability to evaluate algorithms Algorithmic thinking also requires the ability to evaluate algorithms. This involves determining if an algorithm really does solve a given task. This can be very challenging. For example, a "preflight check list" is an algorithm for preparing an aircraft for take off. And finally, Algorithmic thinking includes the ability to create new algorithms. This is probably the most challenging aspect of algorithmic thinking. Given a task, can you create a series of precise, step-by-step instructions that always solves the task correctly? Obviously the complexity of the task has a big impact on the complexity of an algorithm that will accomplish the task. Simple tasks can typically be accomplished with simple algorithms, while complex tasks typically require more complex algorithms.  

What do you observe here ? Problem 3 7 6 5 1 4 3 8 What do you observe here ?

7 6 15 5 1 15 4 3 8 15 15 15 15 15 magic constant Here, sums of each row, each column, and each main diagonal are same and this sum is called magic constant . And this square, a magic square

Introduction to Magic Square A magic square of order n is an arrangement of the numbers from 1 to n2 in an n-by-n matrix, with each number occurring exactly once ,so that each row, each column, and each main diagonal has the same sum.

Magic Square for n = 3 6 1 8 7 5 3 9 4 2 magic constant=15

Magic constant If a magic square of order n exists, the magic constant in question must be equal to n(n2 + 1)/2.

Algorithm to generate Magic square Start with the middle entry of the top row . Place number 1 in that cell. Move one cell up and one to the left cell to this, you have to assume that the top of the row “wraps round” to the bottom row and the left column “wraps round” to the right column. If this cell is empty, write the next highest number in the sequence. If the cell is not empty move down one cell within the same column. Repeat step 3 to 5 until all cells have been completed. End.

What are the limitations of this algorithm?

Problem 4 A tromino is an l-shaped tile formed by 1-by-1 adjacent squares. The problem is to cover any 2n-by- 2n chessboard with one missing square (anywhere on the board) with trominos. rominos should cover all the squares except the missing one with no overlaps.

Solution solution

Problem 5 Towers of Hanoi: We have n discs of different sizes and 3 pegs. Initially all the discs are on the first peg in order of size, the largest at the bottom, and the smallest on the top. Goal: To move all the discs to the third peg using second one as an auxiliary if necessary. Constraints: 1.Move only one disc at a time. 2.It is forbidden to place a larger disc on top of smaller one. Demonstration of Towers of Hanoi

Algorithmic Solution to Tower of Hanoi Iterative solution for an even number of disks: make the legal move between pegs A and B make the legal move between pegs A and C make the legal move between pegs B and C repeat until complete Iterative solution for an odd number of disks: In each case, a total of 2n-1 moves are made.

Recursive solution for ToH To move n discs from peg A to peg C: move n−1 discs from A to B. This leaves disc #n alone on peg A move disc #n from A to C move n−1 discs from B to C so they sit on disc #n

Another important algorithmic thinking paradigm is recursion

Problem 6 Welding Problem: To find the shortest tour for the welding robot, through a given set of n welding spots

The problem gets transformed into a graph theory problem

Travelling Sales Persons Problem Definition: To find the shortest tour through a given set of n cities that visits each city exactly once before returning to the city where it started. 2 b a 8 5 3 7 c d 1

Solution to TSP Tour Length Remarks a->b->c->d->a 2+8+1+7 = 18 a->b->d->c->a 2+3+1+5 = 11 Optimal a->c->b->d->a 5+8+3+7 = 23 a->c->d->b->a 5+1+3+2 = 11 a->d->b->c->a 7+3+8+5 = 23 a->d->c->b->a 7+1+8+2 = 18

AIRWAYS Hubli (HBX) to London(LON) - Click here for online page. (Just enter the FROM & TO textbox as above) - For images. - First Possibility. - Second Possibility.

RAILWAYS Hubli (UBL) to Manglore(MAQ) - Click here for online page. (Please enter the Source & Destination in the textbox) - For images. - First Possibility. Click here for maps. - Second Possibility. Click here for maps. -

Back

Back

Back

Back

HUBLI Back ARSIKERE MANGALORE

HUBLI Back BANGALURU MANGALORE

Such problems are typical graph problems for which there exist algorithmic solutions.

?

Thank you