Computer programming III. Algorithms.

Slides:



Advertisements
Similar presentations
Algorithm Design Techniques
Advertisements

An intro to programming concepts with Scratch Session 8 of 10 sessions Working with lists; sorting a list.
Back to Sorting – More efficient sorting algorithms.
Recursion Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein.
Bubble Sort Algorithm It is so named because numbers (or letters) which are in the wrong place “bubble-up” to their correct positions (like fizzy lemonade)
For Monday Read 10.3 Homework: –Chapter 10, exercise 10.
Quicksort Quicksort     29  9.
Search and Sort.
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
CMPS1371 Introduction to Computing for Engineers SORTING.
CS203 Programming with Data Structures Sorting California State University, Los Angeles.
Sorting Algorithms What is it: An algorithm that puts the elements of a list in a certain order.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/23/2009.
TDDB56 DALGOPT-D DALG-C Lecture 8 – Sorting (part I) Jan Maluszynski - HT Sorting: –Intro: aspects of sorting, different strategies –Insertion.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 5. Recursive Algorithms.
New Mexico Computer Science For All Introduction to Algorithms Maureen Psaila-Dombrowski.
F453 Computing Searches. Binary Trees Not this kind of tree!
Recursion Bryce Boe 2013/11/18 CS24, Fall Outline Wednesday Recap Lab 7 Iterative Solution Recursion Binary Tree Traversals Lab 7 Recursive Solution.
Iterative Process. A process of repeating the same procedure over and over again.A process of repeating the same procedure over and over again.
Adapted from instructor resource slides Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
Merge Sort: Taught By Example CO1406: Algorithms and Data Structures Module Lecturer: Dr. Nearchos Paspallis Week 10 Lab - Practice with Merge sort and.
Can you put these children’s TV shows in date order - earliest to latest?
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
Progression in KS3/4 Algorithms MONDAY 30 TH NOVEMBER SUE SENTANCE.
Lists and Sorting Algorithms
Recursion To understand recursion, you first have to understand recursion.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion (Continued) Prof. Katherine Gibson Prof. Jeremy Dixon Based on slides from UPenn’s.
Searching and Sorting Algorithms
CMSC201 Computer Science I for Majors Lecture 20 – Recursion (Continued) Prof. Katherine Gibson Based on slides from UPenn’s CIS 110, and from previous.
Computer programming II. Algorithms.
CSCI 104 Sorting Algorithms
Computer programming IV. Algorithms.
Sorting Algorithms.
Exam Hints.
Quick-Sort 9/12/2018 3:26 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Quick-Sort To understand quick-sort, let’s look at a high-level description of the algorithm 1) Divide : If the sequence S has 2 or more elements, select.
Growth Functions Algorithms Lecture 8
Chapter 4: Divide and Conquer
“Human Sorting” It’s a “Problem Solving” game:
Sorting Algorithms Ellysa N. Kosinaya.
Global Challenge Night Sensor Lesson 2.
Computational Thinking for KS3
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
CS 3343: Analysis of Algorithms
The first number is posted telling what random number was selected, I did this for testing purposes, in the real thing it would not be there. Since the.
Global Challenge Night Sensor Lesson 2.
Global Challenge Night Sensor Lesson 2.
ICT Gaming Lesson 2.
Global Challenge Night Sensor Lesson 2.
CS 1114: Sorting and selection (part two)
Quick-Sort 4/25/2019 8:10 AM Quick-Sort     2
Computational Thinking
Divide & Conquer Sorting
Global Challenge Night Sensor Lesson 2.
Last Class We Covered Recursion Stacks Parts of a recursive function:
Global Challenge Night Sensor Lesson 2.
Quiz: Computational Thinking
Mod 3 Lesson 2 Me First! Sorting
“Human Sorting” It’s a “Problem Solving” game:
Divide-and-conquer approach
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Stacks, Queues, ListNodes
Sorting and selection Prof. Noah Snavely CS1114
Understanding Computational Thinking
Presentation transcript:

Computer programming III. Algorithms

Recap: What is computer programming? Telling computers to solve a problem Think about the problem and generate a solution (algorithm) Break down the problem into step by step solution Write the solution in a language that computer can understand (coding) Algorithm for going to school in the morning

Coding Write the step by step instruction in a programming language repetition Write the step by step instruction in a programming language Scratch (https://scratch.mit.edu) sequencing conditional logic https://www.tynker.com/blog/articles/ideas-and-tips/how-to-explain-algorithms-to-kids/

Coding: Decision Trees Guess a number between 0 and 3: If the number is bigger than 1 then: If the number is bigger than 2 then: The number is 3 Else: The number is 2 If the number is bigger than 0 then: The number is 1 The number is 0 X > 1? X > 0? X > 2? X = 0 X = 1 X = 2 X = 3 no yes

Coding: Decision Trees

Algorithm: Pattern Recognition Rock-Paper-Scissors: Human VS Computer The computer guesses what we are going to do next based on the patterns of our previous throws http://www.nytimes.com/interactive/science/rock-paper-scissors.html

Algorithm: Pattern Recognition bakaji bavwa bamona bana The women saw the children

Algorithm: Pattern Recognition The child: muana The children: bana The woman: mukaji The women: bakaji The man: muluma The men: baluma The lion: ntambwe The lions: bantambwe The small lions: tubantambwe The small lion: kantambwe Saw: mumona/bamona/tumona/kamona

More Programming Exercise Create a story using scratch Choose Your Own Adventure story

ALGORITHM: Divide and conquer

Algorithm: Divide et Impera Divide and Conquer Break the problem to similar but smaller pieces Solve the smaller problems Iteratively merge the solutions of smaller problems to get the solution of the bigger problems

Algorithm: Sorting We sort things all the time! Packing, moving, ... How can we teach computers how to sort things? http://sambosma.blogspot.com/2009/07/

Algorithm: Selection sort While there is still some heights to be sorted: Select the shortest from the set and put it to one side 45

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 1

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 2

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 2

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 3

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 3

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 4

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 4

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 5

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 5

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 6

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 6

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 7

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 8

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 8

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 9

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 9

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 10

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 10

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 11

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 11

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 12

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 12

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 13

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 13

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 14

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 14

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 15

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 16

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 16

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 17

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 17

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 18

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 19

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 20

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 20

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 21

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 21

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 22

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 22

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 23

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 24

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 24

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 25

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 25

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 26

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 27

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 28

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 29

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 29

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 30

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 30

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 31

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 32

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 32

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 33

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 33

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 34

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 35

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 36

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 37

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 37

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 38

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 38

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 39

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 40

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 40

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 41

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 41

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 42

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 43

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 44

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 45

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 46

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 46

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 47

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 48

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 48

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 49

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 49

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 50

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 51

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 52

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 53

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 54

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 55

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 56

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 56

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 57

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 57

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 58

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 59

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 60

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 61

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 62

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 63

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 64

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 64

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 65

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 65

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 66

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 67

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 68

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 69

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 70

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 71

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 72

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 73

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 73

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 74

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 75

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 76

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 77

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 78

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 79

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 80

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 81

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 82

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 83

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 84

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 85

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 86

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 87

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 88

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 89

Algorithm: Bubble sort While there is still some change: Go through the list and swap side-by-side objects that are in the wrong order of heights 90

Algorithm: Quick Sort While the group has more than 1 object Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups

Algorithm: Quick Sort 9 While the group has more than 1 object Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups 9

Algorithm: Quick Sort 9 While the group has more than 1 object Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups 9

Algorithm: Quick Sort 16 While the group has more than 1 object Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups 16

Algorithm: Quick Sort 16 While the group has more than 1 object Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups 16

Algorithm: Quick Sort 19 While the group has more than 1 object Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups 19

Algorithm: Quick Sort 19 While the group has more than 1 object Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups 19

Algorithm: Quick Sort 19 While the group has more than 1 object Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups 19

Algorithm: Quick Sort 19 While the group has more than 1 object Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups 19

Next week: Algorithm: Divide and Conquer Tower of Hanoi (https://www.mathsisfun.com/games/towerofhanoi.html)

Questions?