Loops.

Slides:



Advertisements
Similar presentations
CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Advertisements

Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the five essential properties of an algorithm.
Sorting Algorithms 1. 2 Selection Sort: Array-Based Lists List sorted by selecting elements in the list – Select elements one at a time – Move elements.
1 CSE1301 Computer Programming: Lecture 28 List Sorting.
Sorting and Searching. Searching List of numbers (5, 9, 2, 6, 3, 4, 8) Find 3 and tell me where it was.
Text Chapters 1, 2. Sorting ä Sorting Problem: ä Input: A sequence of n numbers ä Output: A permutation (reordering) of the input sequence such that:
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/23/2009.
Searches & Sorts V Deena Engel’s class Adapted from W. Savitch’s text An Introduction to Computers & Programming.
Query Execution :Nested-Loop Joins Rohit Deshmukh ID 120 CS-257 Rohit Deshmukh ID 120 CS-257.
Computer Programming Sorting and Sorting Algorithms 1.
Lecture 14: A Programming Example: Sorting Yoni Fridman 7/24/01 7/24/01.
CS2420: Lecture 8 Vladimir Kulyukin Computer Science Department Utah State University.
Sorting 2 An array a is sorted (ascending order) if: for all i a[i]  a[j] Probably the most well-studied algorithmic problem in Computer Science There.
Selection Sort
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
Chapter 19: Searching and Sorting Algorithms
Computer Science 101 Introduction to Sorting. Sorting One of the most common activities of a computer is sorting data Arrange data into numerical or alphabetical.
Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali : 1.Compare items 1 and 2; swap them if necessary 2.Compare 2 and 3; swap.
Bubble Sort 18 th December 2014 With Mrs
Selection Sort
1 Introduction to Sorting Algorithms Sort: arrange values into an order Alphabetical Ascending numeric Descending numeric Two algorithms considered here.
Lists in Python Selection Sort Algorithm. Sorting A very common activity for computers Not just in business, sorting is used in databases, graphics, simulations,
Static block can be used to check conditions before execution of main begin, Suppose we have developed an application which runs only on Windows operating.
Feasibility and Infeasibility Are all problems easy to solve?
Loop Invariants and Binary Search Chapter 4.4, 5.1.
Review 1 Merge Sort Merge Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Bubble sort. Quite slow, but simple Principles: Compare 2 numbers next to each other (lets call it current and the one next to it) If the current number.
Learning and remembering.
Sort Algorithm.
Chapter 16: Searching, Sorting, and the vector Type
CSCE 210 Data Structures and Algorithms
CS212: Data Structures and Algorithms
The Need for Algorithms
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
COMP108 Algorithmic Foundations Polynomial & Exponential Algorithms
Sending a few stragglers home
Lesson 5-15 AP Computer Science Principles
CS1371 Introduction to Computing for Engineers
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer.
Teach A level Computing: Algorithms and Data Structures
Conditinoal Constructs Review
Sorting CSCE 121 J. Michael Moore
Selection Sort Sorted Unsorted Swap
CPS120: Introduction to Computer Science
Analysis of Bubble Sort and Loop Invariant
Conditinoal Constructs Review
MSIS 655 Advanced Business Applications Programming
Sorting … and Insertion Sort.
Algorithm and Ambiguity
Bubble Sort Key Revision Points.
Principles of Computing – UFCFA3-30-1
Topic 24 sorting and searching arrays
My Take on the Largest Number Algorithm
Prime numbers.
Parallel sorting.
Welcome back to Software Development!
Test Plans Making the world safe for software
Welcome back to Software Development!
Presents a preliminary view of sorting algorithms
Bubble sort.
Welcome back to Software Development!
Introduction to Computer Science
Print the following triangle, using nested loops
Designing Software.
Chapter 19 Searching, Sorting and Big O
Lecture No 5A Advance Analysis of Institute of Southern Punjab Multan
Principles of Computing – UFCFA3-30-1
CS100A Sections Dec Loop Invariant Review C Review and Example
the fourth iteration of this loop is shown here
CMPT 225 Lecture 16 – Heap Sort.
Presentation transcript:

Loops

Loops Three keys to making a loop work:

Loops Three keys to making a loop work: Getting it started right

Loops Three keys to making a loop work: Getting it started right Keeping it moving along

Loops Three keys to making a loop work: Getting it started right Keeping it moving along Determining when to quit looping

Loops Three keys to making a loop work: Getting it started right – initialization Keeping it moving along Determining when to quit looping

Loops Three keys to making a loop work: Getting it started right – initialization Keeping it moving along – iteration Determining when to quit looping

Loops Three keys to making a loop work: Getting it started right – initialization Keeping it moving along – iteration Determining when to quit looping – exit conditions

Get smallest # (smallest # algo) New list starts w/2nd item Start w/full list Remember start of list Get smallest # (smallest # algo) Swap w/1st New list starts w/2nd item New list have #? No Yes Orig list is sorted

Get smallest # (smallest # algo) New list starts w/2nd item Start w/full list Remember start of list Get smallest # (smallest # algo) Swap w/1st Loop New list starts w/2nd item New list have #? No Yes Orig list is sorted

Get smallest # (smallest # algo) New list starts w/2nd item Start w/full list Initialization Remember start of list Get smallest # (smallest # algo) Swap w/1st Loop New list starts w/2nd item New list have #? No Yes Orig list is sorted

Get smallest # (smallest # algo) New list starts w/2nd item Start w/full list Initialization Remember start of list Get smallest # (smallest # algo) Swap w/1st Loop New list starts w/2nd item Iteration get to next loop New list have #? No Yes Orig list is sorted

Get smallest # (smallest # algo) New list starts w/2nd item Start w/full list Initialization Remember start of list Get smallest # (smallest # algo) Swap w/1st Loop New list starts w/2nd item Iteration get to next loop New list have #? No Exit condition Yes Orig list is sorted

Testing Your Algorithm

Testing Your Algorithm Pretend you are the computer

Testing Your Algorithm Pretend you are the computer “Execute” your algorithm step-by-step

Testing Your Algorithm Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping)

Testing Your Algorithm Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions

Testing Your Algorithm Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions Try to do each step exactly as you wrote it

Testing Your Algorithm Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions Try to do each step exactly as you wrote it Start with an easy set of data (i.e. your number list)

Testing Your Algorithm Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions Try to do each step exactly as you wrote it Start with an easy set of data (i.e. your number list) Make sure you do this with boundary condition data

Testing Your Algorithm Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions Try to do each step exactly as you wrote it Start with an easy set of data (i.e. your number list) Make sure you do this with boundary condition data Questions?

Clear and Unclear Windows