COMPUTER 2430 Object Oriented Programming and Data Structures I

Slides:



Advertisements
Similar presentations
CSE Lecture 3 – Algorithms I
Advertisements

Sorting A fundamental operation in computer science (many programs need to sort as an intermediate step). Many sorting algorithms have been developed Choose.
 Sort: arrange values into an order  Alphabetical  Ascending numeric  Descending numeric  Does come before or after “%”?  Two algorithms considered.
CS 171: Introduction to Computer Science II Simple Sorting Ymir Vigfusson.
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
Insertion Sort for (i = 1; i < n; i++) {/* insert a[i] into a[0:i-1] */ int t = a[i]; int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j];
Time Complexity s Sorting –Insertion sorting s Time complexity.
Chapter 16: Searching, Sorting, and the vector Type.
Chapter 19: Searching and Sorting Algorithms
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
LAB#7. Insertion sort In the outer for loop, out starts at 1 and moves right. It marks the leftmost unsorted data. In the inner while loop, in starts.
Simple Iterative Sorting Sorting as a means to study data structures and algorithms Historical notes Swapping records Swapping pointers to records Description,
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Data Structure Introduction.
Data Structure & Algorithm
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.
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
Searching Topics Sequential Search Binary Search.
April 27, 2017 COSC Data Structures I Review & Final Exam
Lecture 2 What is a computational problem? What is an instance of a problem? What is an algorithm? How to guarantee that an algorithm is correct? What.
Chapter 16: Searching, Sorting, and the vector Type.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 8a. Sorting(1): Elementary Algorithms.
Sort Algorithm.
CSCE 210 Data Structures and Algorithms
Chapter 16: Searching, Sorting, and the vector Type
CSCE 210 Data Structures and Algorithms
Searching and Sorting Algorithms
COP 3503 FALL 2012 Shayan Javed Lecture 15
Searching – Linear and Binary Searches
Lecture 14 Searching and Sorting Richard Gesick.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Week 15 – Monday CS221.
Algorithm Analysis CSE 2011 Winter September 2018.
Sorting Data are arranged according to their values.
Teaching Computing to GCSE
Describing algorithms in pseudo code
Bubble, Selection & Insertion sort
Data Structures & Algorithms Priority Queues & HeapSort
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
CS 2430 Object Oriented Programming and Data Structures I
MSIS 655 Advanced Business Applications Programming
Sorting Data are arranged according to their values.
Lecture 11 Searching and Sorting Richard Gesick.
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
IT 4043 Data Structures and Algorithms
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
Algorithmic Complexity
COMPUTER 2430 Object Oriented Programming and Data Structures I
Simple Sorting Methods: Bubble, Selection, Insertion, Shell
Figure 7.1 Some queue operations. Figure 7.1 Some queue operations.
Topic 24 sorting and searching arrays
COMPUTER 2430 Object Oriented Programming and Data Structures I
Given value and sorted array, find index.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Introduction to Data Structure
CS 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
Jeff West - Quiz Section 16
Exercise 5 1. We learned bubble sort during class. This problem requires you to modify the code for bubble sorting method to implement the selection sorting.
Algorithms Sorting.
Chapter 19 Searching, Sorting and Big O
Insertion Sort Array index Value Insertion sort.
Applications of Arrays
EE 312 Software Design and Implementation I
10.3 Bubble Sort Chapter 10 - Sorting.
COMPUTER 2430 Object Oriented Programming and Data Structures I
CMPT 225 Lecture 16 – Heap Sort.
Presentation transcript:

COMPUTER 2430 Object Oriented Programming and Data Structures I

Expected Learning Outcomes Develop software using elementary data structures. Design, implement, and test programs using classes, inheritance, and polymorphism. Compare and contrast algorithm efficiency at a very basic level. Write module tests, system tests, and develop test specifications. Perform simple object-oriented analysis and design. Work in a small team (two or three people) on the analysis, design, implementation, and testing of a project.

Quiz 5 What is the Big O for each of the following: Deleting from a regular array and keep the order O(N) for (int i = index; i < count – 1; i ++) items[i] = items[i + 1]; count --;

Quiz 5 What is the Big O for each of the following: 2. The Queue method remove of circular array implementation O(1) Object obj = items[front]; front = (front + 1) % items.length; return obj;

Quiz 5 What is the Big O for each of the following: 3. Finding the sum of a list of numbers O(N) int sum = 0; for (int i = 0; i < count; i ++) sum += items[i];

Quiz 5 What is the Big O for each of the following: 3. Finding the sum of a list of Additive instances O(N) Additive sum = new Additive(); for (int i = 0; i < count; i ++) sum = sum.plus(items[i]);

Quiz 5 What is the Big O for each of the following: 4. Insertion Sort, average case O(N2) for i = 1 to (size - 1) j = i while j > 0 and a[j] < a[j - 1] Swap a[j], a[j - 1] j --

Quiz 5 for I = (N + 4) downto 2 for J = (I - 2) to (N + 5) if --- The total number of times “if” is executed is: ___________________

Two Formulas How Many last – first + 1 What is the sum? (first + last) * (number of items) / 2

How Many? last – first + 1 first – last + 1 1 + 2 + 3 + . . . + 10 20 + 19 + 18 + . . . + 5 + 4 + 3 3 + 4 + 5 + . . . + 18 + 19 + 20

What is the Sum? s = 20 + 19 + . . . + 4 + 3 s = 3 + 4 + . . . + 19 + 20 2*s = (20 + 3) + (19 + 4) + . . . + (4+19) + (3 +20) = (first + last) * (number of items) s = (first + last) * (first – last + 1) / 2

Quiz 5 Pass I First of J Last of J # of Comparisons N+4 N+3 N+2 . 4 3 for I = (N + 4) downto 2 for J = (I - 2) to (N + 5) if --- The total number of times “if” is executed is: ___________________ Pass I First of J Last of J # of Comparisons N+4 N+3 N+2 . 4 3 2 N+2 N+1 N . 2 1 N+5 . 4 5 6 . N+4 N+5 N+6

Quiz 5 for I = (N + 4) downto 2 for J = (I - 2) to (N + 5) if --- The total number of times “if” is executed is: ___________________ 4 + 5 + 6 + . . . + (N+4) + (N+5) + (N+6) = (4 + (N+6)) * ((N+6) – 4 + 1) / 2 = (N+10) * (N+3) / 2 = (N2 + 13N + 30) / 2

Quiz 5: Sorting a. Bubble Sort, 3rd iteration (I = 0, 1, 2) I = 0 7 1 6 5 2 8 3 4 1 7 2 6 5 3 8 4 1 2 7 3 6 5 4 8 1 2 3 7 4 6 5 8

Quiz 5: Sorting b. Insertion Sort, 3rd iteration (I = 1, 2, 3) I = 1 7 1 6 5 2 8 3 4 1 7 6 5 2 8 3 4 1 6 7 5 2 8 3 4 1 5 6 7 2 8 3 4

Quiz 5: Sorting c. Selection Sort, 3rd iteration (I = 0, 1, 2) I = 0 7 1 6 5 2 8 3 4 1 7 6 5 2 8 3 4 1 2 6 5 7 8 3 4 1 2 3 5 7 8 6 4

Binary Search Code Tracing Array of integers Array of Date Array of Comparable Tracing In array Not in array Format

Quiz 6 Wednesday Binary search Hashing Counting

Expected Learning Outcomes Develop software using elementary data structures. Design, implement, and test programs using classes, inheritance, and polymorphism. Compare and contrast algorithm efficiency at a very basic level. Write module tests, system tests, and develop test specifications. Perform simple object-oriented analysis and design. Work in a small team (two or three people) on the analysis, design, implementation, and testing of a project.

Prog 6 Must use PFigure as is It’s different from Pfig of Lab12 Minimum of three sub-classes from Pfigure One drawing and one picture Must make and use a PFigureList Containing instances from at least two sub-classes Polymorphism! Move cannot just left-right, up-down, or bounce

SE Tool Time plan Time Log Monday, Dec 3, by 11 pm Punch in/out when working on Prog 6

Prog 6 Group folders

Counting Exercise