TUTORIAL 6 – BUBBLE SORTING AN ARRAY

Slides:



Advertisements
Similar presentations
ALGORITHMS - PART 2 CONDITIONAL BRANCH CONTROL STRUCTURE
Advertisements

Decision Maths 1 Sorting Algorithms Bubble Sort A V Ali : 1.Start at the beginning of the data set. 2.Compare the first two elements,
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions.
COPYRIGHT 2003: Dr. David Scanlan, CSUS OBJECTIVES: Explain the need for arrays. Coding an array. Basic algorithms: Largest, Smallest, Sum, Standard Deviation,
An Introduction to Programming with C++ Fifth Edition
Searching and Sorting Arrays
CHAPTER 7: SORTING & SEARCHING Introduction to Computer Science Using Ruby (c) Ophir Frieder at al 2012.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Examples using Arrays. Summing Squares Problem: To compute the sum of the squares of N numbers N is given N values are also given These should be read.
AEEE 195 – Repetition Structures: Part B Spring semester 2011.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
BUBBLE SORT. Introduction Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
LAB#6. 2 Overview Before we go to our lesson we must know about : 1. data structure. 2.Algorithms. data structure is an arrangement of data in a computer.
Arrays An array is a data object that can hold multiple objects, all of the same type. We can think of an array as a storage box which has multiple compartments.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Sorting and Shuffling Arrays CS 233G Intermediate C++ Programming for Games.
CPS120: Introduction to Computer Science Sorting.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
Consultation Hours. Mubashir: – Tuesday from 12:30 to 1:30 with ease of Students. Zohaib – Wednesday b/w 9:30 -10:30 Location: TA Room (next to HOD Office)
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Chapter 9: Sorting and Searching Arrays
Alternate Version of STARTING OUT WITH C++ 4th Edition
CS212: Data Structures and Algorithms
Q1: Draw a simple flowchart to show a decision.
UMBC CMSC 104 – Section 01, Fall 2016
Outline lecture Revise arrays Entering into an array
Michele Weigle - COMP 14 - Spr 04 Catie Welsh March 30, 2011
Arrays 2.
ALGORITHMS CONDITIONAL BRANCH CONTROL STRUCTURE
Upsorn Praphamontripong CS 1110 Introduction to Programming Fall 2016
Recitation 13 Searching and Sorting.
GC211Data Structure Lecture2 Sara Alhajjam.
Simple Sorting Algorithms
Basic Array Definition
Alg2_1c Extra Material for Alg2_1
Sorting Algorithms.
Chapter 7 Arrays.
Siti Nurbaya Ismail Senior Lecturer
Arrays, For loop While loop Do while loop
CS Week 7 Jim Williams, PhD.
Linear and Binary Search
Selection Sort – an array sorting algorithm
And now for something completely different . . .
Control Structures: for & while Loops
1) C program development 2) Selection structure
Sorting … and Insertion Sort.
Search,Sort,Recursion.
Big-O, Ω, ϴ Trevor Brown CSC263 Tutorial 1 Big-O, Ω, ϴ Trevor Brown
CS 1111 Introduction to Programming Spring 2019
Searching.
Visit for More Learning Resources
Sorting Damian Gordon.
Arrays ICS2O.
EECE.2160 ECE Application Programming
Search,Sort,Recursion.
Programming Logic and Design Fifth Edition, Comprehensive
Simple Sorting Algorithms
Data Structures and Algorithms Introduction to Pointers
Bubble sort.
CS250 Introduction to Computer Science II
Simple Sorting Algorithms
Lecture 03 & 04 Method and Arrays Jaeki Song.
Simple Sorting Algorithms
Visit for more Learning Resources
Introduction to Computer Science
Presentation transcript:

TUTORIAL 6 – BUBBLE SORTING AN ARRAY COS 151 TUTORIAL TUTORIAL 6 – BUBBLE SORTING AN ARRAY ENKH & IVA S. March 16, 2018

Admin Bringing textbooks to Practicals and Tutorials Extra help – COSTutorium! See Study Guide for times Make sure you’re attending Practicals & Tutorials, you need them for Exam Entrance! “You are required to have a mark for at least 60% of the practical lab experience tasks (i.e. 8 of the 12 sessions) to gain examination entrance. Note that simply completing a practical lab experience is insufficient, and that a mark must be awarded (read the submission instructions of each lab experience for information on what is required to get a mark for your work).” “You must have a result for at least 70% of the tutorials (i.e. 9 of the 13 tutorials) to gain examination entrance. Once again, this means that you must have a mark for the tutorials in question”

Functional, but NOT structured

Cannot have multiple decision diamonds point to the same statement block

Two loops cannot point back to the same position – a loop must always point back above its own diamond

Declaring Arrays e.g. num arr[5] = 3, 1, 7, 9, 4; In the above example, arr holds 5 elements and has an index from 0 to 4. Remember: The index of the first element is always 0.

Manipulating arrays Addition e.g. arr[0] + arr[1] = 3 + 1 Subtraction Multiplication Max, Min, etc… num arr[5] = 3, 1, 7, 9, 4;

Bubble Sort Simple Sorting Algorithm Comparison-based Adjacent elements are compared If elements are not in order, SWAP them

Pseudocode while swapped swapped = false for j from 0 to N - 1 swapped = true while swapped swapped = false for j from 0 to N - 1 if a[j] > a[j + 1] swap( a[j], a[j + 1] )

Bubble Sort - Example

https://visualgo.net/bn/sorting Bubble Sort Animation https://visualgo.net/bn/sorting

Task - Question 1 [Total: 7] Draw a structured flowchart that declares an array containing 5 numeric values (initialized as follows: 5, 9, 2, 7, 3). The program should then use bubble sort to modify the array so that the values are stored in ascending order.

References http://www.algorithmist.com/index.php/Bubble_sort https://www.tutorialspoint.com/data_structures_algorithms/bubb le_sort_algorithm.htm https://visualgo.net/bn/sorting