21 Pages

lect-sorting

Course: ECE 242, Fall 2009
School: UMass (Amherst)
Rating:
 
 
 
 
 

Word Count: 591

Document Preview

242 ECE Spring 2003 Data Structures in Java http://rio.ecs.umass.edu/ece242 Elementary Sorting Algorithms Prof. Lixin Gao ECE242 Spring 2003 Data Structures in Java, Prof. Gao 1 Today's Topics Selection Sorting Insertion Sorting ECE242 Spring 2003 Data Structures in Java, Prof. Gao 2 Sorted Listing Phone book sorted by name Course list in registration Guide sorted by department sorted by course...

Register Now

Unformatted Document Excerpt

Coursehero >> Massachusetts >> UMass (Amherst) >> ECE 242

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
242 ECE Spring 2003 Data Structures in Java http://rio.ecs.umass.edu/ece242 Elementary Sorting Algorithms Prof. Lixin Gao ECE242 Spring 2003 Data Structures in Java, Prof. Gao 1 Today's Topics Selection Sorting Insertion Sorting ECE242 Spring 2003 Data Structures in Java, Prof. Gao 2 Sorted Listing Phone book sorted by name Course list in registration Guide sorted by department sorted by course number ECE242 roster list sorted by last name ECE242 Spring 2003 Data Structures in Java, Prof. Gao 3 Why Sorting? Without sorting how can I find your phone number quickly? where is ECE242 course schedule? In BlockBuster video store, more than 1,000 movies where is "Matrix"? ECE242 Spring 2003 Data Structures in Java, Prof. Gao 4 Sorting Sorting by keys Easy to find what you want Easy to manage these stuff. ECE242 Spring 2003 Data Structures in Java, Prof. Gao 5 Sorting Integers How to sort the integers in this array? 20 8 5 10 7 5 7 8 10 20 ECE242 Spring 2003 Data Structures in Java, Prof. Gao 6 Elementary Sorting Algorithms Selection Sort Insertion Sort Bubble Sort ...... ECE242 Spring 2003 Data Structures in Java, Prof. Gao 7 Selection Sorting Main idea: find the smallest element put it in the first position find the next smallest element put it in the second position ... ECE242 Spring 2003 Data Structures in Java, Prof. Gao 8 Pseudo-code for Selection Sorting Step: 1. select the smallest element among data[i]~ data[data.length-1]; 2. swap it with data[i]; 3. if not finishing, repeat 1&2 ECE242 Spring 2003 Data Structures in Java, Prof. Gao 9 Swap Action (SelectionSorting) 20 8 5 5 5 5 ECE242 Spring 2003 5 10 7 8 20 10 7 7 20 10 8 7 7 8 10 20 8 10 20 10 Data Structures in Java, Prof. Gao SelectionSort SelectionSort(int[] array){ for( i=0; i<array.length-1; i++ ) { // find the minimum value index // among array[i], array[i+1], ... array[length-1]; int minIndex = i; for( int j=i+1; j<=array.length-1; j++ ) if( array[j] < array[minIndex]) minIndex = j; ECE242 Spring 2003 Data Structures in Java, Prof. Gao 11 SelectionSort (continued) //swap array[minIndex] with array[i] int temp = array[minIndex]; array[minIndex] = array[i]; array[i] = } temp; } ECE242 Spring 2003 Data Structures in Java, Prof. Gao 12 Complete Example SelectionSorting.java int [] array = new int [5]; // initialize the value array[0] = 20; array[1] = 8; array[2] = 5; array[3] = 10; array[4] = 7; // call SelectionSort method SelectionSort(array); ECE242 Spring 2003 Data Structures in Java, Prof. Gao 13 Insertion Sorting Main Idea: Starts by considering the first two elements of the array data, if out of order, swap them Consider the third element, insert it into the proper position among the first three elements. Consider the forth element, insert it into the proper position among the first four elements. ...... ECE242 Spring 2003 Data Structures in Java, Prof. Gao 14 Pseudo-code for Insertion Sorting Place ith item in proper position: 1. temp = data[i] 2. shift those elements data[j] which greater than temp to right by one position 3. place temp in its proper position ECE242 Spring 2003 Data Structures in Java, Prof. Gao 15 Insert Action: i=1 temp 8 8 20 8 5 10 7 i = 1, first iteration 20 20 5 10 7 --- 8 20 5 10 7 ECE242 Spring 2003 Data Structures in Java, Prof. Gao 16 Insert Action: i=2 temp 5 5 5 --ECE242 Spring 2003 8 20 5 10 7 8 20 20 10 7 8 5 8 20 10 7 8 20 10 7 i = 2, second iteration Data Structures in Java, Prof. Gao 17 Insert Action: i=3 temp 10 10 --5 5 5 8 20...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

UMass (Amherst) - ECE - 242
ECE 242 Spring 2003Data Structures in Javahttp:/rio.ecs.umass.edu/ece242Elementary Sorting AlgorithmsProf. Lixin GaoECE242 Spring 2003 Data Structures in Java, Prof. Gao 1Today's Topics Selection Sorting Insertion SortingECE242 Spring 20
UMass (Amherst) - ECE - 242
Array: does not mention array.length String: does not mention string.length()Stack: examples for procedure callHeapSort: examples are different with the result from code.
Allan Hancock College - PAGE - 971
Lathyrus Lathyrism Newsletter 3 (2003)Rainfed rice-based 3-crop systems with paira/utera crops in West Bengal, IndiaN.R. DasDepartment of Agronomy, Faculty of Agriculture, Bidhan Chandra Agricultural University P.O. Mohanpur 741 252, Nadia, West
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|12 Feb 2002 21:43:36 -0000 vti_extenderversion:SR|4.0.2.5526 vti_cacheddtm:TX|12 Feb 2002 21:43:36 -0000 vti_filesize:IR|36864 vti_cachedlinkinfo:VX|H|http:/rio.ecs.umass.edu/ece242 H|http:/rio.ecs.umas
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|22 Feb 2002 19:29:52 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|87552 vti_title:SR|ECE 242 Spring 2002 Data Structures in Java vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|s
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|06 May 2002 19:12:48 -0000 vti_extenderversion:SR|4.0.2.5526 vti_backlinkinfo:VX|schedule.htm vti_cacheddtm:TX|07 May 2002 17:23:58 -0000 vti_filesize:IR|287744 vti_cachedlinkinfo:VX|H|http:/rio.ecs.uma
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|25 Feb 2002 22:34:32 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|130560 vti_title:SR|PowerPoint Presentation vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|schedule.htm vti_cac
LSU - PHYS - 2101
PHYS 2101Spring 2009I. II.Introduction to the course Chapter 1 in 90 secondsIII. Setting up NSL problems IV. Vectors V. Newton's Second LawPHYS 2101Spring 2009Section 4 5Name Ray Chastain Ray ChastainDays and Times 2:40 3:30 MWF 9:1
LSU - PHYS - 2101
PHYS 2101Spring 2009I. Angular Momentum and Torque II. Conservation of Angular MomentumPHYS 2101Spring 2009EX1:A penguin of mass m falls from rest from the edge of a crevice in the ice. What is the angular momentum torque on the penguin a
LSU - PHYS - 2101
PHYS 2101Spring 2009I. I. I. I.Universal Law of Gravitation Superposition Principle Shell Theorem Gravity near the Earth's Surface m1m2 Fg = G 2 r r12PHYS 2101Spring 2009EX1:Four 2-kg particles are arranged in the x-y plane. Particle
LSU - PHYS - 2101
PHYS 2101Spring 2008I. Gravitational Potential Energy I. Potential Energy of a System of Particles I. Conservation of Energy A. Escape Speed B. Kepler's 3rd LawPHYS 2101Spring 2008CT1:You move a ball of mass m away from the surface of the
LSU - PHYS - 2101
PHYS 2101Spring 2009I. Pascal's Principle I. Simple Harmonic Motion A. Periodic Motion B. Equations of Motion C. Forces and SHMPHYS 2101Spring 2009PHYS 2101Spring 2009Position at time tAngular frequency TimePhase shiftx(t) = Acos(
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|28 Feb 2002 22:10:18 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|53248 vti_title:SR|ECE 242 Spring 2002 Data Structures in Java vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|s
LSU - PHYS - 2101
PHYS 2101Spring 20081. Heat and Temperature 2. Temperature Scales 3. Heat Capacity A. Specific Heat B. Latent HeatPHYS 2101Spring 2008 Which of the following statements are correct? (There may be more than one.) 1 - Heat is a form of energy,
LSU - PHYS - 2101
PHYS 2101Spring 20081. Heat Capacity A. Specific Heat B. Latent Heat 1. P-V diagrams and Work 2. Thermodynamic ProcessesPHYS 2101Spring 2008EX1:If 0.25 kg of boiling water is poured into a tub containing 2 kg of water at 20, how much heat
LSU - PHYS - 2101
PHYS 2101Spring 20091. Superposition of Waves 2. Interference 3. Standing Waves 4. ResonancePHYS 2101Spring 2009CT1:You send a traveling wave along a particular string Instead of increasing the frequency of the by oscillating one end. You
LSU - PHYS - 2101
PHYS 2101Spring 20081. Heat and Temperature 2. Temperature Scales 3. Heat Capacity A. Specific Heat B. Latent HeatPHYS 2101Spring 2008 Which of the following statements are correct? (There may be more than one.) 1 - Heat is a form of energy,
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|05 Mar 2002 16:37:14 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|66048 vti_title:SR|PowerPoint Presentation vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|schedule.htm vti_cach
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|07 Mar 2002 17:19:30 -0000 vti_extenderversion:SR|4.0.2.5526 vti_cacheddtm:TX|07 Mar 2002 17:19:30 -0000 vti_filesize:IR|27648 vti_cachedlinkinfo:VX|H|http:/rio.ecs.umass.edu/ece242 H|http:/rio.ecs.umas
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|01 Apr 2002 22:07:12 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|121856 vti_title:SR|PowerPoint Presentation vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|schedule.htm vti_cac
University of Texas - CH - 302
CH302 Random Musings April 21, 2009 1. We are rolling downhill to the finish line. In these musings are the question types for Quiz 5, Exam 3 and the Final Exam. Be thinking about the strategy you will be using to earn the grade you want in this cour
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|13 Apr 2002 03:14:32 -0000 vti_extenderversion:SR|4.0.2.5526 vti_backlinkinfo:VX|schedule.htm vti_cacheddtm:TX|18 Apr 2002 23:37:44 -0000 vti_filesize:IR|127488 vti_cachedlinkinfo:VX|H|http:/rio.ecs.uma
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|19 Feb 2002 22:16:10 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|68096 vti_title:SR|PowerPoint Presentation vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|schedule.htm vti_cach
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|26 Mar 2002 19:35:12 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|86016 vti_title:SR|PowerPoint Presentation vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|schedule.htm vti_cach
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|30 Jan 2002 04:23:54 -0000 vti_extenderversion:SR|4.0.2.2717 vti_filesize:IR|38400 vti_title:SR|PowerPoint Presentation vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|schedule.htm vti_cach
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|04 Feb 2002 17:04:02 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|44544 vti_title:SR|PowerPoint Presentation vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|schedule.htm vti_cach
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|04 Feb 2002 16:01:12 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|49152 vti_title:SR|PowerPoint Presentation vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|schedule.htm vti_cach
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|05 Feb 2002 22:58:20 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|74752 vti_title:SR|PowerPoint Presentation vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|schedule.htm vti_cach
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|07 Feb 2002 19:38:02 -0000 vti_extenderversion:SR|4.0.2.5526 vti_backlinkinfo:VX|schedule.htm vti_cacheddtm:TX|07 Feb 2002 22:34:50 -0000 vti_filesize:IR|69632 vti_cachedlinkinfo:VX|H|http:/rio.ecs.umas
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|12 Feb 2002 23:46:54 -0000 vti_extenderversion:SR|4.0.2.5526 vti_filesize:IR|71168 vti_title:SR|PowerPoint Presentation vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|schedule.htm vti_cach
UMass (Amherst) - ECE - 242
vti_encoding:SR|utf8-nlvti_timelastmodified:TR|22 Mar 2002 15:33:10 -0000vti_extenderversion:SR|4.0.2.5526