SORTING 9/26/18. Prelim 1. Prelim 1. Why Sorting? InsertionSort. Some Sorting Algorithms. Tonight!!!! Two Sessions:

Size: px
Start display at page:

Download "SORTING 9/26/18. Prelim 1. Prelim 1. Why Sorting? InsertionSort. Some Sorting Algorithms. Tonight!!!! Two Sessions:"

Transcription

1 Prelim 1 2 "Organizing is wat you do efore you do someting, so tat wen you do it, it is not all mixed up." ~ A. A. Milne SORTING Tonigt!!!! Two Sessions: You sould now y now wat room to tae te final. Jenna ed you. Bring your Cornell ID!!! We will grade tis evening, and if everyting wors out well, you will receive an in early morning from Gradescope telling you to loo at your grade. Lecture 11 CS2110 Fall 2018 Prelim 1 Wy Sorting? 3 4 Recitation 5. next wee: Enums and Java Collections classes. Noting to prepare for it! Sorting is useful Dataase indexing Operations researc Compression But get A3 done. Tere are lots of ways to sort Tere isn't one rigt answer You need to e ale to figure out te options and decide wic one is rigt for your application. Today, we'll learn several different algoritms (and ow to develop tem) Some Sorting Algoritms InsertionSort 5 Insertion sort Selection sort 6 pre: 0.lengt? post: 0.lengt Quic sort Merge sort 0 i.lengt? or: or: [0..i-1] is 0 i.lengt processed? [0..i-1] is processed A loop tat processes elements of an array in increasing order as tis invariant --- ust replace y processed. 1

2 Eac iteration, i= i+1; How to eep inv true? Wat to do in eac iteration? 7 0 i.lengt? 8 0 i.lengt? e.g. 0 i.lengt ? e.g. 0 i.lengt ? 0 i.lengt ? Loop ody (inv true efore and after) ? ? ? Pus [i] to its position in [0..i], ten increase i ? Tis will 0 tae time proportional i to te numer of.lengt swaps needed ? Insertion Sort Insertion Sort 9 // sort [], an array of int // [0..i-1] is for (int i= 0; i <.lengt; i= i+1) { // Pus [i] down to its // position in [0..i] Present algoritm lie tis Note Englis statement in ody. Astraction. Says wat to do, not ow. Tis is te est way to present it. We expect you to present it tis way wen ased. Later, can sow ow to implement tat wit an inner loop 10 // sort [], an array of int // [0..i-1] is for (int i= 0; i <.lengt; i= i+1) { // Pus [i] down to its // position in [0..i] int = i; wile ( > 0 && [] < [-1]) { Swap [] and [-1]; = 1; invariant P: [0..i] is except tat [] may e < [-1] i ? example start? stop? progress? maintain invariant? Insertion Sort // sort [], an array of int // [0..i-1] is for (int i= 0; i <.lengt; i= i+1) { // Pus [i] down to its // position in [0..i] Pusing [i] down can tae i swaps. Worst case taes n-1 = (n-1)*n/2 swaps. Let n =.lengt Worst-case: O(n 2 ) (reverse- input) Best-case: O(n) ( input) Expected case: O(n 2 ) Algoritm Ave time. Worst-case time Space Stale? Insertion Sort! " #.!(" # )!(1) Yes Merge Sort Quic Sort We ll tal aout staility later 2

3 SelectionSort SelectionSort 13 pre: 0.lengt? post: 0.lengt 0 i.lengt, <= [i..] >= [0..i-1] Additional term in invariant Keep invariant true wile maing progress? 0 i.lengt e.g.: Increasing i y 1 eeps inv true only if [i] is min of [i..] 14 //sort [], an array of int Anoter common way for // [0..i-1] AND people to sort cards // [0..i-1] <= [i..] for (int i= 0; i <.lengt; i= i+1) { int m= index of min of [i..]; Swap [i] and [m]; Runtime wit n =.lengt Worst-case O(n 2 ) Best-case O(n 2 ) Expected-case O(n 2 ) 0 i lengt, smaller values larger values Eac iteration, swap min value of tis section into [i] QuicSort Algoritm Ave time. Worst-case time Space Stale? Insertion sort!(# $ ).!(# $ )!(1) Yes Selection sort! # $.!(# $ )!(1) No Quic sort Merge sort Quicsort developed y Sir Tony Hoare (e was nigted y te Queen of England for is contriutions to education and CS). 84 years old. Developed Quicsort in But e could not explain it to is colleague, so e gave up on it. Later, e saw a draft of te new language Algol 58 (wic ecame Algol 60). It ad recursive procedures. First time in a procedural programming language. A!, e said. I now ow to write it etter now. 15 minutes later, is colleague also understood it. Distras, Hoares, Grieses, 1980s Partition algoritm of quicsort pre: +1 x? x is called te pivot Swap array values around until [..] loos lie tis: post: 3

4 Partition algoritm of quicsort Partition algoritm 19 pivot Not yet partition tese can e in any order tese can e in any order Not yet Te 20 could e in te oter partition 20 pre: post: +1 x? Comine pre and post to get an invariant t <= x x? >= x invariant needs at least 4 sections Partition algoritm QuicSort procedure 21 t <= x x? >= x = ; t= ; wile ( < t) { if ([+1] <= []) { Swap [+1] and []; = +1; else { Swap [+1] and [t]; t= t-1; Taes linear time: O(+1-) Initially, wit = and t =, tis diagram loos lie te start diagram Terminate wen = t, so te? segment is empty, so diagram loos lie result diagram 22 /** Sort [..]. */ pulic static void QS(int[], int, int ) { if ([..] as < 2 elements) return; Base case int = partition(,, ); // We now [.. 1] <= [] <= [+1..] // Sort [..-1] and [+1..] QS(,, -1); QS(, +1, ); Function does te partition algoritm and returns position of pivot Worst case quicsort: pivot always smallest value Best case quicsort: pivot always middle value 23 x0 x0 x1 x0 x1 x2 >= x0 >= x1 >= x2 /** Sort [..]. */ pulic static void QS(int[], int, int ) { if ([..] as < 2 elements) return; int = partition(,, ); QS(,, -1); QS(, +1, ); n partioning at dept 0 partioning at dept 1 partioning at dept 2 Dept of recursion: O(n) Processing at dept i: O(n-i) O(n*n) 24 0 n <= x0 x0 >= x0 <=x1 x1 >= x1 x0 <=x2 x2 >=x2 dept 0. 1 segment of size ~n to partition. Dept 2. 2 segments of size ~n/2 to partition. Dept 3. 4 segments of size ~n/4 to partition. Max dept: O(log n). Time to partition on eac level: O(n) Total time: O(n log n). Average time for Quicsort: n log n. Difficult calculation 4

5 25 QuicSort complexity to sort array of lengt n Time complexity Worst-case: O(n*n) /** Sort [..]. */ Average-case: O(n log n) pulic static void QS(int[], int, int ) { if ([..] as < 2 elements) return; int = partition(,, ); // We now [.. 1] <= [] <= [+1..] // Sort [..-1] and [+1..] QS(,, -1); QS(, +1, ); Worst-case space:? Wat s dept of recursion? Worst-case space: O(n)! --dept of recursion can e n Can rewrite it to ave space O(log n) Sow tis at end of lecture if we ave time 26 Partition. Key issue. How to coose pivot pre: post: x? Popular euristics: Use w first array value (not so good) w middle array value (not so good) w Coose a random element (not so good) w median of first, middle, last, values (often used)! Coosing pivot Ideal pivot: te median, since it splits array in alf But computing te median is O(n), quite complicated Merge two adacent segments Algoritm Ave time. Worst-case time Space Stale? Insertion sort!(# $ ).!(# $ )!(1) Yes Selection sort! # $.!(# $ )!(1) No Quic sort!(# log #).!(# $ ) O(log n)* No Merge sort /* Sort [..]. Precondition: [..t] and [t+1..] are. */ pulic static merge(int[], int, int t, int ) { Copy [..t] into a new array c; Merge c and [t+1..] into [..]; t * Te first algoritm we developed taes space O(n) in te worst case, ut it can e reduced to O(log n) merged, Merge two adacent segments Merge two adacent segments 29 /* Sort [..]. Precondition: [..t] and [t+1..] are. */ pulic static merge(int[], int, int t, int ) { t t merged, 30 // Merge c and [t+1..] into [..] 0 t- pre: c x t? y invariant: post: x and y, c 0 i c.lengt ead of x tail of x u v? tail of y ead of x and ead of y, x, y are 5

6 Merge Mergesort int i = 0; int u = ; int v = t+1; wile( i <= t-){ if(v <= && [v] < c[i]) { [u] = [v]; u++; v++; else { [u] = c[i]; u++; i++; 0 t- pre: c post: t? c 0 i c.lengt u v? /** Sort [..] */ pulic static void mergesort(int[], int, int ]) { if (size [..] < 2) return; int t= (+)/2; mergesort(,, t); mergesort(, t+1, ); merge(,, t, ); t merged, QuicSort versus MergeSort 33 /** Sort [..] */ pulic static void QS (int[], int, int ) { if ( < 1) return; int = partition(,, ); QS(,, -1); QS(, +1, ); /** Sort [..] */ pulic static void MS (int[], int, int ) { if ( < 1) return; MS(,, (+)/2); MS(, (+)/2 + 1, ); merge(,, (+)/2, ); One processes te array ten recurses. One recurses ten processes te array. 34 Algoritm Ave time. Worst-case time Space Stale? Insertion sort!(# $ ).!(# $ )!(1) Yes Selection sort! # $.!(# $ )!(1) No Quic sort!(# log #).!(# $ ) O(log n)* No Merge sort!(# log #).!(# log #) O(n) Yes * Te first algoritm we developed taes space O(n) in te worst case, ut it can e reduced to O(log n) Sorting in Java 35 Java.util.Arrays as a metod sort(array) implemented as a collection of overloaded metods for primitives, sort is implemented wit a version of quicsort for Oects tat implement Comparale, sort is implemented wit timsort, a modified mergesort developed in 1993 y Tim Peters Tradeoff etween speed/space and staility/performance guarantees 6

Announcements SORTING. Prelim 1. Announcements. A3 Comments 9/26/17. This semester s event is on Saturday, November 4 Apply to be a teacher!

Announcements SORTING. Prelim 1. Announcements. A3 Comments 9/26/17. This semester s event is on Saturday, November 4 Apply to be a teacher! Announcements 2 "Organizing is wat you do efore you do someting, so tat wen you do it, it is not all mixed up." ~ A. A. Milne SORTING Lecture 11 CS2110 Fall 2017 is a program wit a teac anyting, learn

More information

"Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne SORTING

Organizing is what you do before you do something, so that when you do it, it is not all mixed up. ~ A. A. Milne SORTING "Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne SORTING Lecture 11 CS2110 Spring 2019 Prelim 1: Tuesday, 12 March 2 Visit exams page of

More information

"Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne SORTING

Organizing is what you do before you do something, so that when you do it, it is not all mixed up. ~ A. A. Milne SORTING "Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne SORTING Lecture 11 CS2110 Fall 2017 Prelim 1 2 It's on Tuesday Evening (3/13) Two Sessions:

More information

"Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne SORTING

Organizing is what you do before you do something, so that when you do it, it is not all mixed up. ~ A. A. Milne SORTING "Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne SORTING Lecture 11 CS2110 Fall 2017 Announcements 2 is a program with a teach anything,

More information

SORTING. Insertion sort Selection sort Quicksort Mergesort And their asymptotic time complexity

SORTING. Insertion sort Selection sort Quicksort Mergesort And their asymptotic time complexity 1 SORTING Insertion sort Selection sort Quicksort Mergesort And their asymptotic time complexity See lecture notes page, row in table for this lecture, for file searchsortalgorithms.zip Lecture 11 CS2110

More information

SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY

SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY Lecture 10 CS2110 Fall 2016 Miscellaneous 2 A3 due Monday night. Group early! Only 325 views of the piazza A3 FAQ yesterday morning. Everyone should

More information

CS211 Spring 2004 Lecture 06 Loops and their invariants. Software engineering reason for using loop invariants

CS211 Spring 2004 Lecture 06 Loops and their invariants. Software engineering reason for using loop invariants CS211 Spring 2004 Lecture 06 Loops and teir invariants Reading material: Tese notes. Weiss: Noting on invariants. ProgramLive: Capter 7 and 8 O! Tou ast damnale iteration and art, indeed, ale to corrupt

More information

Sorting and Searching

Sorting and Searching CS 1110: Introduction to Computing Using Pyton Lecture 23 Sorting and Searcing [Andersen, Gries, Lee, Marscner, Van Loan, Wite] Announcements Final Exam conflicts due tonigt at 11:59pm Final Exam review

More information

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 8: Sorting http://courses.cs.cornell.edu/cs2110/2018su Lecture 7 Recap 2 Introduced a formal notation for analysing the

More information

Lecture 25. Sequence Algorithms (Continued)

Lecture 25. Sequence Algorithms (Continued) Lecture 25 Sequence Algoritms (Continued) Announcements for Tis Lecture Assignment & Lab A6 is not graded yet Done by end of classes A7 due Wed, Dec. 10 Wednesday after classes Keep on top of milestones

More information

CS 234. Module 6. October 16, CS 234 Module 6 ADT Dictionary 1 / 33

CS 234. Module 6. October 16, CS 234 Module 6 ADT Dictionary 1 / 33 CS 234 Module 6 October 16, 2018 CS 234 Module 6 ADT Dictionary 1 / 33 Idea for an ADT Te ADT Dictionary stores pairs (key, element), were keys are distinct and elements can be any data. Notes: Tis is

More information

SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY

SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY 1 A3 and Prelim 2 SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 11 CS2110 Fall 2016 Deadline for A3: tonight. Only two late days allowed (Wed-Thur) Prelim: Thursday evening. 74 conflicts! If you

More information

Section 2.3: Calculating Limits using the Limit Laws

Section 2.3: Calculating Limits using the Limit Laws Section 2.3: Calculating Limits using te Limit Laws In previous sections, we used graps and numerics to approimate te value of a it if it eists. Te problem wit tis owever is tat it does not always give

More information

Hash-Based Indexes. Chapter 11. Comp 521 Files and Databases Fall

Hash-Based Indexes. Chapter 11. Comp 521 Files and Databases Fall Has-Based Indexes Capter 11 Comp 521 Files and Databases Fall 2012 1 Introduction Hasing maps a searc key directly to te pid of te containing page/page-overflow cain Doesn t require intermediate page fetces

More information

CORRECTNESS ISSUES AND LOOP INVARIANTS

CORRECTNESS ISSUES AND LOOP INVARIANTS Aout A2 and feedack. Recursion 2 CORRECTNESS ISSUES AND LOOP INVARIANTS S2 has een graded. If you got 30/30, you will proaly have no feedack. If you got less than full credit, there should e feedack showing

More information

Hash-Based Indexes. Chapter 11. Comp 521 Files and Databases Spring

Hash-Based Indexes. Chapter 11. Comp 521 Files and Databases Spring Has-Based Indexes Capter 11 Comp 521 Files and Databases Spring 2010 1 Introduction As for any index, 3 alternatives for data entries k*: Data record wit key value k

More information

MATH 5a Spring 2018 READING ASSIGNMENTS FOR CHAPTER 2

MATH 5a Spring 2018 READING ASSIGNMENTS FOR CHAPTER 2 MATH 5a Spring 2018 READING ASSIGNMENTS FOR CHAPTER 2 Note: Tere will be a very sort online reading quiz (WebWork) on eac reading assignment due one our before class on its due date. Due dates can be found

More information

Basic Techniques. Recursion. Today: Later on: Recursive methods who call themselves directly or indirectly.

Basic Techniques. Recursion. Today: Later on: Recursive methods who call themselves directly or indirectly. La 2 Recursion Basic Techniques SMD135 Programs and Data Structures Lecture 7 Sorting: Divide-and- Conquer Brute force Selection sort Insertion sort Linear proing [seaching through an unordered array]

More information

NOTES: A quick overview of 2-D geometry

NOTES: A quick overview of 2-D geometry NOTES: A quick overview of 2-D geometry Wat is 2-D geometry? Also called plane geometry, it s te geometry tat deals wit two dimensional sapes flat tings tat ave lengt and widt, suc as a piece of paper.

More information

Materials: Whiteboard, TI-Nspire classroom set, quadratic tangents program, and a computer projector.

Materials: Whiteboard, TI-Nspire classroom set, quadratic tangents program, and a computer projector. Adam Clinc Lesson: Deriving te Derivative Grade Level: 12 t grade, Calculus I class Materials: Witeboard, TI-Nspire classroom set, quadratic tangents program, and a computer projector. Goals/Objectives:

More information

CS 234. Module 6. October 25, CS 234 Module 6 ADT Dictionary 1 / 22

CS 234. Module 6. October 25, CS 234 Module 6 ADT Dictionary 1 / 22 CS 234 Module 6 October 25, 2016 CS 234 Module 6 ADT Dictionary 1 / 22 Case study Problem: Find a way to store student records for a course, wit unique IDs for eac student, were records can be accessed,

More information

Announcements. Lilian s office hours rescheduled: Fri 2-4pm HW2 out tomorrow, due Thursday, 7/7. CSE373: Data Structures & Algorithms

Announcements. Lilian s office hours rescheduled: Fri 2-4pm HW2 out tomorrow, due Thursday, 7/7. CSE373: Data Structures & Algorithms Announcements Lilian s office ours resceduled: Fri 2-4pm HW2 out tomorrow, due Tursday, 7/7 CSE373: Data Structures & Algoritms Deletion in BST 2 5 5 2 9 20 7 0 7 30 Wy migt deletion be arder tan insertion?

More information

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017 CS 137 Part 8 Merge Sort, Quick Sort, Binary Search November 20th, 2017 This Week We re going to see two more complicated sorting algorithms that will be our first introduction to O(n log n) sorting algorithms.

More information

4.2 The Derivative. f(x + h) f(x) lim

4.2 The Derivative. f(x + h) f(x) lim 4.2 Te Derivative Introduction In te previous section, it was sown tat if a function f as a nonvertical tangent line at a point (x, f(x)), ten its slope is given by te it f(x + ) f(x). (*) Tis is potentially

More information

Data Structures and Programming Spring 2014, Midterm Exam.

Data Structures and Programming Spring 2014, Midterm Exam. Data Structures and Programming Spring 2014, Midterm Exam. 1. (10 pts) Order te following functions 2.2 n, log(n 10 ), 2 2012, 25n log(n), 1.1 n, 2n 5.5, 4 log(n), 2 10, n 1.02, 5n 5, 76n, 8n 5 + 5n 2

More information

each node in the tree, the difference in height of its two subtrees is at the most p. AVL tree is a BST that is height-balanced-1-tree.

each node in the tree, the difference in height of its two subtrees is at the most p. AVL tree is a BST that is height-balanced-1-tree. Data Structures CSC212 1 AVL Trees A binary tree is a eigt-balanced-p-tree if for eac node in te tree, te difference in eigt of its two subtrees is at te most p. AVL tree is a BST tat is eigt-balanced-tree.

More information

HW 2 Bench Table. Hash Indexes: Chap. 11. Table Bench is in tablespace setq. Loading table bench. Then a bulk load

HW 2 Bench Table. Hash Indexes: Chap. 11. Table Bench is in tablespace setq. Loading table bench. Then a bulk load Has Indexes: Cap. CS64 Lecture 6 HW Benc Table Table of M rows, Columns of different cardinalities CREATE TABLE BENCH ( KSEQ integer primary key, K5K integer not null, K5K integer not null, KK integer

More information

Bounding Tree Cover Number and Positive Semidefinite Zero Forcing Number

Bounding Tree Cover Number and Positive Semidefinite Zero Forcing Number Bounding Tree Cover Number and Positive Semidefinite Zero Forcing Number Sofia Burille Mentor: Micael Natanson September 15, 2014 Abstract Given a grap, G, wit a set of vertices, v, and edges, various

More information

4.1 Tangent Lines. y 2 y 1 = y 2 y 1

4.1 Tangent Lines. y 2 y 1 = y 2 y 1 41 Tangent Lines Introduction Recall tat te slope of a line tells us ow fast te line rises or falls Given distinct points (x 1, y 1 ) and (x 2, y 2 ), te slope of te line troug tese two points is cange

More information

Areas of Parallelograms and Triangles. To find the area of parallelograms and triangles

Areas of Parallelograms and Triangles. To find the area of parallelograms and triangles 10-1 reas of Parallelograms and Triangles ommon ore State Standards G-MG..1 Use geometric sapes, teir measures, and teir properties to descrie ojects. G-GPE..7 Use coordinates to compute perimeters of

More information

CHAPTER 7: TRANSCENDENTAL FUNCTIONS

CHAPTER 7: TRANSCENDENTAL FUNCTIONS 7.0 Introduction and One to one Functions Contemporary Calculus 1 CHAPTER 7: TRANSCENDENTAL FUNCTIONS Introduction In te previous capters we saw ow to calculate and use te derivatives and integrals of

More information

Wrap up Amortized Analysis; AVL Trees. Riley Porter Winter CSE373: Data Structures & Algorithms

Wrap up Amortized Analysis; AVL Trees. Riley Porter Winter CSE373: Data Structures & Algorithms CSE 373: Data Structures & Wrap up Amortized Analysis; AVL Trees Riley Porter Course Logistics Symposium offered by CSE department today HW2 released, Big- O, Heaps (lecture slides ave pseudocode tat will

More information

1 Copyright 2012 by Pearson Education, Inc. All Rights Reserved.

1 Copyright 2012 by Pearson Education, Inc. All Rights Reserved. CHAPTER 20 AVL Trees Objectives To know wat an AVL tree is ( 20.1). To understand ow to rebalance a tree using te LL rotation, LR rotation, RR rotation, and RL rotation ( 20.2). To know ow to design te

More information

Haar Transform CS 430 Denbigh Starkey

Haar Transform CS 430 Denbigh Starkey Haar Transform CS Denbig Starkey. Background. Computing te transform. Restoring te original image from te transform 7. Producing te transform matrix 8 5. Using Haar for lossless compression 6. Using Haar

More information

Areas of Triangles and Parallelograms. Bases of a parallelogram. Height of a parallelogram THEOREM 11.3: AREA OF A TRIANGLE. a and its corresponding.

Areas of Triangles and Parallelograms. Bases of a parallelogram. Height of a parallelogram THEOREM 11.3: AREA OF A TRIANGLE. a and its corresponding. 11.1 Areas of Triangles and Parallelograms Goal p Find areas of triangles and parallelograms. Your Notes VOCABULARY Bases of a parallelogram Heigt of a parallelogram POSTULATE 4: AREA OF A SQUARE POSTULATE

More information

Sorting. Task Description. Selection Sort. Should we worry about speed?

Sorting. Task Description. Selection Sort. Should we worry about speed? Sorting Should we worry about speed? Task Description We have an array of n values in any order We need to have the array sorted in ascending or descending order of values 2 Selection Sort Select the smallest

More information

SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY. Lecture 11 CS2110 Spring 2016

SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY. Lecture 11 CS2110 Spring 2016 1 SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 11 CS2110 Spring 2016 Time spent on A2 2 Histogram: [inclusive:exclusive) [0:1): 0 [1:2): 24 ***** [2:3): 84 ***************** [3:4): 123 *************************

More information

13.5 DIRECTIONAL DERIVATIVES and the GRADIENT VECTOR

13.5 DIRECTIONAL DERIVATIVES and the GRADIENT VECTOR 13.5 Directional Derivatives and te Gradient Vector Contemporary Calculus 1 13.5 DIRECTIONAL DERIVATIVES and te GRADIENT VECTOR Directional Derivatives In Section 13.3 te partial derivatives f x and f

More information

CSE 332: Data Structures & Parallelism Lecture 8: AVL Trees. Ruth Anderson Winter 2019

CSE 332: Data Structures & Parallelism Lecture 8: AVL Trees. Ruth Anderson Winter 2019 CSE 2: Data Structures & Parallelism Lecture 8: AVL Trees Rut Anderson Winter 29 Today Dictionaries AVL Trees /25/29 2 Te AVL Balance Condition: Left and rigt subtrees of every node ave eigts differing

More information

2 The Derivative. 2.0 Introduction to Derivatives. Slopes of Tangent Lines: Graphically

2 The Derivative. 2.0 Introduction to Derivatives. Slopes of Tangent Lines: Graphically 2 Te Derivative Te two previous capters ave laid te foundation for te study of calculus. Tey provided a review of some material you will need and started to empasize te various ways we will view and use

More information

Measuring Length 11and Area

Measuring Length 11and Area Measuring Lengt 11and Area 11.1 Areas of Triangles and Parallelograms 11.2 Areas of Trapezoids, Romuses, and Kites 11.3 Perimeter and Area of Similar Figures 11.4 Circumference and Arc Lengt 11.5 Areas

More information

Section 1.2 The Slope of a Tangent

Section 1.2 The Slope of a Tangent Section 1.2 Te Slope of a Tangent You are familiar wit te concept of a tangent to a curve. Wat geometric interpretation can be given to a tangent to te grap of a function at a point? A tangent is te straigt

More information

1.4 RATIONAL EXPRESSIONS

1.4 RATIONAL EXPRESSIONS 6 CHAPTER Fundamentals.4 RATIONAL EXPRESSIONS Te Domain of an Algebraic Epression Simplifying Rational Epressions Multiplying and Dividing Rational Epressions Adding and Subtracting Rational Epressions

More information

12.2 TECHNIQUES FOR EVALUATING LIMITS

12.2 TECHNIQUES FOR EVALUATING LIMITS Section Tecniques for Evaluating Limits 86 TECHNIQUES FOR EVALUATING LIMITS Wat ou sould learn Use te dividing out tecnique to evaluate its of functions Use te rationalizing tecnique to evaluate its of

More information

Unit Outline. Comparing Sorting Algorithms Heapsort Mergesort Quicksort More Comparisons Complexity of Sorting 2 / 33

Unit Outline. Comparing Sorting Algorithms Heapsort Mergesort Quicksort More Comparisons Complexity of Sorting 2 / 33 Unit #4: Sorting CPSC : Basic Algorithms and Data Structures Anthony Estey, Ed Knorr, and Mehrdad Oveisi 0W Unit Outline Comparing Sorting Algorithms Heapsort Mergesort Quicksort More Comparisons Complexity

More information

Binary Search Tree - Best Time. AVL Trees. Binary Search Tree - Worst Time. Balanced and unbalanced BST

Binary Search Tree - Best Time. AVL Trees. Binary Search Tree - Worst Time. Balanced and unbalanced BST AL Trees CSE Data Structures Unit Reading: Section 4.4 Binary Searc Tree - Best Time All BST operations are O(d), were d is tree dept minimum d is d = log for a binary tree N wit N nodes at is te best

More information

Proceedings of the 8th WSEAS International Conference on Neural Networks, Vancouver, British Columbia, Canada, June 19-21,

Proceedings of the 8th WSEAS International Conference on Neural Networks, Vancouver, British Columbia, Canada, June 19-21, Proceedings of te 8t WSEAS International Conference on Neural Networks, Vancouver, Britis Columbia, Canada, June 9-2, 2007 3 Neural Network Structures wit Constant Weigts to Implement Dis-Jointly Removed

More information

Notes: Dimensional Analysis / Conversions

Notes: Dimensional Analysis / Conversions Wat is a unit system? A unit system is a metod of taking a measurement. Simple as tat. We ave units for distance, time, temperature, pressure, energy, mass, and many more. Wy is it important to ave a standard?

More information

A Novel QC-LDPC Code with Flexible Construction and Low Error Floor

A Novel QC-LDPC Code with Flexible Construction and Low Error Floor A Novel QC-LDPC Code wit Flexile Construction and Low Error Floor Hanxin WANG,2, Saoping CHEN,2,CuitaoZHU,2 and Kaiyou SU Department of Electronics and Information Engineering, Sout-Central University

More information

ECE 2574: Data Structures and Algorithms - Basic Sorting Algorithms. C. L. Wyatt

ECE 2574: Data Structures and Algorithms - Basic Sorting Algorithms. C. L. Wyatt ECE 2574: Data Structures and Algorithms - Basic Sorting Algorithms C. L. Wyatt Today we will continue looking at sorting algorithms Bubble sort Insertion sort Merge sort Quick sort Common Sorting Algorithms

More information

MERGESORT & QUICKSORT cs2420 Introduction to Algorithms and Data Structures Spring 2015

MERGESORT & QUICKSORT cs2420 Introduction to Algorithms and Data Structures Spring 2015 MERGESORT & QUICKSORT cs2420 Introduction to Algorithms and Data Structures Spring 2015 1 administrivia 2 -assignment 4 due tonight at midnight -assignment 5 is out -midterm next Tuesday 3 last time 4

More information

PLK-B SERIES Technical Manual (USA Version) CLICK HERE FOR CONTENTS

PLK-B SERIES Technical Manual (USA Version) CLICK HERE FOR CONTENTS PLK-B SERIES Technical Manual (USA Version) CLICK ERE FOR CONTENTS CONTROL BOX PANEL MOST COMMONLY USED FUNCTIONS INITIAL READING OF SYSTEM SOFTWARE/PAGES 1-2 RE-INSTALLATION OF TE SYSTEM SOFTWARE/PAGES

More information

2.8 The derivative as a function

2.8 The derivative as a function CHAPTER 2. LIMITS 56 2.8 Te derivative as a function Definition. Te derivative of f(x) istefunction f (x) defined as follows f f(x + ) f(x) (x). 0 Note: tis differs from te definition in section 2.7 in

More information

15-122: Principles of Imperative Computation, Summer 2011 Assignment 6: Trees and Secret Codes

15-122: Principles of Imperative Computation, Summer 2011 Assignment 6: Trees and Secret Codes 15-122: Principles of Imperative Computation, Summer 2011 Assignment 6: Trees and Secret Codes William Lovas (wlovas@cs) Karl Naden Out: Tuesday, Friday, June 10, 2011 Due: Monday, June 13, 2011 (Written

More information

MAC-CPTM Situations Project

MAC-CPTM Situations Project raft o not use witout permission -P ituations Project ituation 20: rea of Plane Figures Prompt teacer in a geometry class introduces formulas for te areas of parallelograms, trapezoids, and romi. e removes

More information

12.2 Techniques for Evaluating Limits

12.2 Techniques for Evaluating Limits 335_qd /4/5 :5 PM Page 863 Section Tecniques for Evaluating Limits 863 Tecniques for Evaluating Limits Wat ou sould learn Use te dividing out tecnique to evaluate its of functions Use te rationalizing

More information

Fault Localization Using Tarantula

Fault Localization Using Tarantula Class 20 Fault localization (cont d) Test-data generation Exam review: Nov 3, after class to :30 Responsible for all material up troug Nov 3 (troug test-data generation) Send questions beforeand so all

More information

CS 171: Introduction to Computer Science II. Quicksort

CS 171: Introduction to Computer Science II. Quicksort CS 171: Introduction to Computer Science II Quicksort Roadmap MergeSort Analysis of Recursive Algorithms QuickSort Algorithm Analysis Practical improvements Java Array.sort() methods Quick Sort Partition

More information

Sorting. Sorting. Stable Sorting. In-place Sort. Bubble Sort. Bubble Sort. Selection (Tournament) Heapsort (Smoothsort) Mergesort Quicksort Bogosort

Sorting. Sorting. Stable Sorting. In-place Sort. Bubble Sort. Bubble Sort. Selection (Tournament) Heapsort (Smoothsort) Mergesort Quicksort Bogosort Principles of Imperative Computation V. Adamchik CS 15-1 Lecture Carnegie Mellon University Sorting Sorting Sorting is ordering a list of objects. comparison non-comparison Hoare Knuth Bubble (Shell, Gnome)

More information

When a BST becomes badly unbalanced, the search behavior can degenerate to that of a sorted linked list, O(N).

When a BST becomes badly unbalanced, the search behavior can degenerate to that of a sorted linked list, O(N). Balanced Binary Trees Binary searc trees provide O(log N) searc times provided tat te nodes are distributed in a reasonably balanced manner. Unfortunately, tat is not always te case and performing a sequence

More information

Key question: how do we pick a good pivot (and what makes a good pivot in the first place)?

Key question: how do we pick a good pivot (and what makes a good pivot in the first place)? More on sorting Mergesort (v2) Quicksort Mergesort in place in action 53 2 44 85 11 67 7 39 14 53 87 11 50 67 2 14 44 53 80 85 87 14 87 80 50 29 72 95 2 44 80 85 7 29 39 72 95 Boxes with same color are

More information

You Try: A. Dilate the following figure using a scale factor of 2 with center of dilation at the origin.

You Try: A. Dilate the following figure using a scale factor of 2 with center of dilation at the origin. 1 G.SRT.1-Some Tings To Know Dilations affect te size of te pre-image. Te pre-image will enlarge or reduce by te ratio given by te scale factor. A dilation wit a scale factor of 1> x >1enlarges it. A dilation

More information

19.2 Surface Area of Prisms and Cylinders

19.2 Surface Area of Prisms and Cylinders Name Class Date 19 Surface Area of Prisms and Cylinders Essential Question: How can you find te surface area of a prism or cylinder? Resource Locker Explore Developing a Surface Area Formula Surface area

More information

KF5008 Algorithm Efficiency; Sorting and Searching Algorithms;

KF5008 Algorithm Efficiency; Sorting and Searching Algorithms; KF5008 Algorithm Efficiency; Sorting and Searching Algorithms; Efficiency: Principles An algorithm is a step-by-step procedure for solving a stated problem. The algorithm will be performed by a processor

More information

// walk through array stepping by step amount, moving elements down for (i = unsorted; i >= step && item < a[i-step]; i-=step) { a[i] = a[i-step];

// walk through array stepping by step amount, moving elements down for (i = unsorted; i >= step && item < a[i-step]; i-=step) { a[i] = a[i-step]; Sorting (Rosen, 6 th edition) Carol Zander So far, we have examined only O(n 2 ) algorithms (bubble, insertion, selection). We will now look at more efficient algorithms. Most are recursive, but the first

More information

Sorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place?

Sorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place? Sorting Binary search works great, but how do we create a sorted array in the first place? Sorting in Arrays Sorting algorithms: Selection sort: O(n 2 ) time Merge sort: O(nlog 2 (n)) time Quicksort: O(n

More information

CSE 2123 Sorting. Jeremy Morris

CSE 2123 Sorting. Jeremy Morris CSE 2123 Sorting Jeremy Morris 1 Problem Specification: Sorting Given a list of values, put them in some kind of sorted order Need to know: Which order? Increasing? Decreasing? What does sorted order mean?

More information

Sorting is a problem for which we can prove a non-trivial lower bound.

Sorting is a problem for which we can prove a non-trivial lower bound. Sorting The sorting problem is defined as follows: Sorting: Given a list a with n elements possessing a total order, return a list with the same elements in non-decreasing order. Remember that total order

More information

Sorting: Given a list A with n elements possessing a total order, return a list with the same elements in non-decreasing order.

Sorting: Given a list A with n elements possessing a total order, return a list with the same elements in non-decreasing order. Sorting The sorting problem is defined as follows: Sorting: Given a list A with n elements possessing a total order, return a list with the same elements in non-decreasing order. Remember that total order

More information

Sorting and Searching

Sorting and Searching Sorting and Searching Sorting o Simple: Selection Sort and Insertion Sort o Efficient: Quick Sort and Merge Sort Searching o Linear o Binary Reading for this lecture: http://introcs.cs.princeton.edu/python/42sort/

More information

Comparison Sorts. Chapter 9.4, 12.1, 12.2

Comparison Sorts. Chapter 9.4, 12.1, 12.2 Comparison Sorts Chapter 9.4, 12.1, 12.2 Sorting We have seen the advantage of sorted data representations for a number of applications Sparse vectors Maps Dictionaries Here we consider the problem of

More information

CESILA: Communication Circle External Square Intersection-Based WSN Localization Algorithm

CESILA: Communication Circle External Square Intersection-Based WSN Localization Algorithm Sensors & Transducers 2013 by IFSA ttp://www.sensorsportal.com CESILA: Communication Circle External Square Intersection-Based WSN Localization Algoritm Sun Hongyu, Fang Ziyi, Qu Guannan College of Computer

More information

08 A: Sorting III. CS1102S: Data Structures and Algorithms. Martin Henz. March 10, Generated on Tuesday 9 th March, 2010, 09:58

08 A: Sorting III. CS1102S: Data Structures and Algorithms. Martin Henz. March 10, Generated on Tuesday 9 th March, 2010, 09:58 08 A: Sorting III CS1102S: Data Structures and Algorithms Martin Henz March 10, 2010 Generated on Tuesday 9 th March, 2010, 09:58 CS1102S: Data Structures and Algorithms 08 A: Sorting III 1 1 Recap: Sorting

More information

Redundancy Awareness in SQL Queries

Redundancy Awareness in SQL Queries Redundancy Awareness in QL Queries Bin ao and Antonio Badia omputer Engineering and omputer cience Department University of Louisville bin.cao,abadia @louisville.edu Abstract In tis paper, we study QL

More information

Lesson 6 MA Nick Egbert

Lesson 6 MA Nick Egbert Overview From kindergarten we all know ow to find te slope of a line: rise over run, or cange in over cange in. We want to be able to determine slopes of functions wic are not lines. To do tis we use te

More information

A UPnP-based Decentralized Service Discovery Improved Algorithm

A UPnP-based Decentralized Service Discovery Improved Algorithm Indonesian Journal of Electrical Engineering and Informatics (IJEEI) Vol.1, No.1, Marc 2013, pp. 21~26 ISSN: 2089-3272 21 A UPnP-based Decentralized Service Discovery Improved Algoritm Yu Si-cai*, Wu Yan-zi,

More information

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader Prelim 2 CS 2110, November 19, 2015, 7:30 PM 1 2 3 4 5 6 Total Question True Short Complexity Searching Trees Graphs False Answer Sorting Invariants Max 20 15 13 14 17 21 100 Score Grader The exam is closed

More information

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to

More information

Chapter K. Geometric Optics. Blinn College - Physics Terry Honan

Chapter K. Geometric Optics. Blinn College - Physics Terry Honan Capter K Geometric Optics Blinn College - Pysics 2426 - Terry Honan K. - Properties of Ligt Te Speed of Ligt Te speed of ligt in a vacuum is approximately c > 3.0µ0 8 mês. Because of its most fundamental

More information

Lecture 4: Geometry II

Lecture 4: Geometry II Lecture 4: Geometry II LPSS MATHCOUNTS 19 May 2004 Some Well-Known Pytagorean Triples A Pytagorean triple is a set of tree relatively prime 1 natural numers a,, and c satisfying a 2 + 2 = c 2 : 3 2 + 4

More information

, 1 1, A complex fraction is a quotient of rational expressions (including their sums) that result

, 1 1, A complex fraction is a quotient of rational expressions (including their sums) that result RT. Complex Fractions Wen working wit algebraic expressions, sometimes we come across needing to simplify expressions like tese: xx 9 xx +, xx + xx + xx, yy xx + xx + +, aa Simplifying Complex Fractions

More information

THANK YOU FOR YOUR PURCHASE!

THANK YOU FOR YOUR PURCHASE! THANK YOU FOR YOUR PURCHASE! Te resources included in tis purcase were designed and created by me. I ope tat you find tis resource elpful in your classroom. Please feel free to contact me wit any questions

More information

Outline. Quadratic-Time Sorting. Linearithmic-Time Sorting. Conclusion. Bubble/Shaker Sort Insertion Sort Odd-Even Sort

Outline. Quadratic-Time Sorting. Linearithmic-Time Sorting. Conclusion. Bubble/Shaker Sort Insertion Sort Odd-Even Sort Outline Quadratic-Time Sorting Bubble/Shaker Sort Insertion Sort Odd-Even Sort Linearithmic-Time Sorting Heap Sort Merge Sort Quick Sort Conclusion Check out this link for animation of various sorting

More information

We can use a max-heap to sort data.

We can use a max-heap to sort data. Sorting 7B N log N Sorts 1 Heap Sort We can use a max-heap to sort data. Convert an array to a max-heap. Remove the root from the heap and store it in its proper position in the same array. Repeat until

More information

Classify solids. Find volumes of prisms and cylinders.

Classify solids. Find volumes of prisms and cylinders. 11.4 Volumes of Prisms and Cylinders Essential Question How can you find te volume of a prism or cylinder tat is not a rigt prism or rigt cylinder? Recall tat te volume V of a rigt prism or a rigt cylinder

More information

AVL Trees Outline and Required Reading: AVL Trees ( 11.2) CSE 2011, Winter 2017 Instructor: N. Vlajic

AVL Trees Outline and Required Reading: AVL Trees ( 11.2) CSE 2011, Winter 2017 Instructor: N. Vlajic 1 AVL Trees Outline and Required Reading: AVL Trees ( 11.2) CSE 2011, Winter 2017 Instructor: N. Vlajic AVL Trees 2 Binary Searc Trees better tan linear dictionaries; owever, te worst case performance

More information

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Searching data involves determining whether a value (referred to as the search key) is present in the data

More information

Numerical Derivatives

Numerical Derivatives Lab 15 Numerical Derivatives Lab Objective: Understand and implement finite difference approximations of te derivative in single and multiple dimensions. Evaluate te accuracy of tese approximations. Ten

More information

Multi-Stack Boundary Labeling Problems

Multi-Stack Boundary Labeling Problems Multi-Stack Boundary Labeling Problems Micael A. Bekos 1, Micael Kaufmann 2, Katerina Potika 1 Antonios Symvonis 1 1 National Tecnical University of Atens, Scool of Applied Matematical & Pysical Sciences,

More information

CS842: Automatic Memory Management and Garbage Collection. GC basics

CS842: Automatic Memory Management and Garbage Collection. GC basics CS842: Automatic Memory Management and Garbage Collection GC basics 1 Review Noting mmap (space allocated) Mapped space Wile owned by program, manager as no reference! malloc (object created) Never returned

More information

More on Functions and Their Graphs

More on Functions and Their Graphs More on Functions and Teir Graps Difference Quotient ( + ) ( ) f a f a is known as te difference quotient and is used exclusively wit functions. Te objective to keep in mind is to factor te appearing in

More information

3.6 Directional Derivatives and the Gradient Vector

3.6 Directional Derivatives and the Gradient Vector 288 CHAPTER 3. FUNCTIONS OF SEVERAL VARIABLES 3.6 Directional Derivatives and te Gradient Vector 3.6.1 Functions of two Variables Directional Derivatives Let us first quickly review, one more time, te

More information

COSC242 Lecture 7 Mergesort and Quicksort

COSC242 Lecture 7 Mergesort and Quicksort COSC242 Lecture 7 Mergesort and Quicksort We saw last time that the time complexity function for Mergesort is T (n) = n + n log n. It is not hard to see that T (n) = O(n log n). After all, n + n log n

More information

Quicksort (Weiss chapter 8.6)

Quicksort (Weiss chapter 8.6) Quicksort (Weiss chapter 8.6) Recap of before Easter We saw a load of sorting algorithms, including mergesort To mergesort a list: Split the list into two halves Recursively mergesort the two halves Merge

More information

What is sorting? Lecture 36: How can computation sort data in order for you? Why is sorting important? What is sorting? 11/30/10

What is sorting? Lecture 36: How can computation sort data in order for you? Why is sorting important? What is sorting? 11/30/10 // CS Introduction to Computation " UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department Professor Andrea Arpaci-Dusseau Fall Lecture : How can computation sort data in order for you? What is sorting?

More information

Read pages in the book, up to the investigation. Pay close attention to Example A and how to identify the height.

Read pages in the book, up to the investigation. Pay close attention to Example A and how to identify the height. C 8 Noteseet L Key In General ON LL PROBLEMS!!. State te relationsip (or te formula).. Sustitute in known values. 3. Simplify or Solve te equation. Use te order of operations in te correct order. Order

More information

CSC 273 Data Structures

CSC 273 Data Structures CSC 273 Data Structures Lecture 6 - Faster Sorting Methods Merge Sort Divides an array into halves Sorts the two halves, Then merges them into one sorted array. The algorithm for merge sort is usually

More information

4.2 Binary Search Trees

4.2 Binary Search Trees Binary trees 4. Binary earc Trees Definition. BT is a binary tree in symmetric order. root a left link a subtree binary tree is eiter: mpty. rigt cild of root Two disjoint binary trees (left and rigt).

More information

Cryptanalysis of LOKI. Lars Ramkilde Knudsen. Aarhus Universitet Datalogisk Afdeling. Ny Munkegade. DK-8000 Aarhus C. Abstract

Cryptanalysis of LOKI. Lars Ramkilde Knudsen. Aarhus Universitet Datalogisk Afdeling. Ny Munkegade. DK-8000 Aarhus C. Abstract 1 Cryptanalysis of LOKI Lars Ramkilde Knudsen Aarus Universitet Datalogisk Afdeling Ny Munkegade DK-8000 Aarus C. Abstract In [BPS90] Brown, Pieprzyk and Seberry proposed a new encryption primitive, wic

More information

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader Prelim 2 CS 2110, November 19, 2015, 7:30 PM 1 2 3 4 5 6 Total Question True Short Complexity Searching Trees Graphs False Answer Sorting Invariants Max 20 15 13 14 17 21 100 Score Grader The exam is closed

More information