[B ] Introduction to Computer Engineering (컴퓨터공학 개론)

Slides:



Advertisements
Similar presentations
Programming and Data Structure
Advertisements

Chapter 7 Problem Solving and Algorithms. 2 Chapter Goals Describe the computer problem-solving process and relate it to Polya’s How to Solve It list.
Problem Solving and Algorithms
Sorting I Chapter 8 Kruse and Ryba. Introduction Common problem: sort a list of values, starting from lowest to highest. –List of exam scores –Words of.
Visual C++ Programming: Concepts and Projects
1 CSE1301 Computer Programming: Lecture 28 List Sorting.
An Introduction to Sorting Chapter 9. 2 Chapter Contents Selection Sort Iterative Selection Sort Recursive Selection Sort The Efficiency of Selection.
An Introduction to Sorting Chapter 8. 2 Chapter Contents Selection Sort Iterative Selection Sort Recursive Selection Sort The Efficiency of Selection.
Chapter 3: Sorting and Searching Algorithms 3.2 Simple Sort: O(n 2 )
Sorting Algorithms: Selection, Insertion and Bubble.
Algorithms for Sorting Things. Why do we need to sort things? Internal Telephone Directory –sorted by department then by name My local video store holds.
Week 11 Sorting Algorithms. Sorting Sorting Algorithms A sorting algorithm is an algorithm that puts elements of a list in a certain order. We need sorting.
Chapter 13 Lists. List  List  A variable-length, linear collection of homogeneous components  Example  StudentRec Students[100];  A list of 100 students.
Lecture 5 Searching and Sorting Richard Gesick. The focus Searching - examining the contents of the array to see if an element exists within the array.
Problem Solving and Algorithms
Applications of Arrays (Searching and Sorting) and Strings
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
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.
Sorting. Algorithms Sorting reorders the elements in an array or list in either ascending or descending order. Sorting reorders the elements in an array.
Chapter 14: Searching and Sorting
Chapter 5 Searching and Sorting. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Examine the linear search and binary.
Chapter 7 Problem Solving and Algorithms. 2 Problem Solving Problem solving The act of finding a solution to a perplexing, distressing, vexing, or unsettled.
Introduction to C++ Programming Language Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University,
September 26, 2011 Sorting and Searching Lists. Agenda Review quiz #3 Team assignment #1 due tonight  One per team Arcade game Searching  Linear  Binary.
Lists in Python Selection Sort Algorithm. Sorting A very common activity for computers Not just in business, sorting is used in databases, graphics, simulations,
Sorting Algorithms: Selection, Insertion and Bubble.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
Chapter 10: Class Vector and String, and Enumeration Types Java Programming: Program Design Including Data Structures Program Design Including Data Structures.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 14 Searching and Sorting.
Chapter 16: Searching, Sorting, and the vector Type.
Sort Algorithm.
UNIT - IV SORTING By B.Venkateswarlu Dept of CSE.
Sorting Chapter 14.
Chapter 16: Searching, Sorting, and the vector Type
Insertion sort Loop invariants Dynamic memory
Chapter 9: Sorting and Searching Arrays
Alternate Version of STARTING OUT WITH C++ 4th Edition
CS212: Data Structures and Algorithms
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Array and List Algorithms
Lecture 14 Searching and Sorting Richard Gesick.
Introduction to Search Algorithms
Chapter 9: Searching, Sorting, and Algorithm Analysis
Sorting Algorithms.
Alg2_1c Extra Material for Alg2_1
Object-Oriented Programming
Sorting Algorithms: Selection, Insertion and Bubble
Design and Analysis of Algorithms
Problem Solving and Algorithms
Data Structures 2018 Quiz Answers
Algorithm Efficiency and Sorting
Algorithm design and Analysis
Objectives At the end of the class, students are expected to be able to do the following: Understand the purpose of sorting technique as operations on.
Sorting Algorithms.
Welcome to CIS 068 ! Lesson 9: Sorting CIS 068.
Chapter 8 Arrays Objectives
Lecture 11 Searching and Sorting Richard Gesick.
Searching and Sorting Arrays
Straight Selection Sort
Computer Architecture and the Fetch-Execute Cycle
Principles of Computing – UFCFA3-30-1
Searching and Sorting Arrays
CSE 12 – Basic Data Structures
Chapter 8 Arrays Objectives
Sorting Algorithms.
Chapter 19 Searching, Sorting and Big O
Insertion Sort.
Principles of Computing – UFCFA3-30-1
Insertion Sort Array index Value Insertion sort.
Module 8 – Searching & Sorting Algorithms
Presentation transcript:

[B3611900] Introduction to Computer Engineering (컴퓨터공학 개론) Chapter 7-2 Seungkyu Lee Assistant Professor, Dept. of Computer Engineering Kyung Hee University

Quiz #4 2. Given the following state of memory (in hexadecimal), what are the contents of the A register (16 bits) after the execution of the following two instructions? Memory: address contents 0001 A2 0002 11 0003 00 0004 FF   Instructions: C1 00 01 70 00 01 A register: (in hexadecimal)

Quiz #4

Assignment #5 Exercises in your textbook Ch.6 – 33,34,41,44,55 Ch.7 – 43,63,64,66,67 Mid-term Exam Date: Oct. 22 (Tuesday), in class 10 Problems Scope: Ch.1~Ch.7 You can use English, Korean or Both!

Selection Sort Figure 7.11 Example of a selection sort (sorted elements are shaded)

Selection Sort Selection Sort Set firstUnsorted to 0 WHILE (current < length – 1) Find smallest unsorted item Swap firstUnsorted item with the smallest Set firstUnsorted to firstUnsorted + 1 6 6

Selection Sort Find smallest unsorted item Set indexOfSmallest to firstUnsorted Set index to firstUnsorted + 1 WHILE (index <= length – 1) IF (data[index] < data[indexOfSmallest]) Set indexOfSmallest to index Set index to index + 1 Set index to indexOfSmallest 7 7

Selection Sort Swap firstUnsorted with smallest Set tempItem to data[firstUnsorted] Set data[firstUnsorted] to data[indexOfSmallest] Set data[indexOfSmallest] to tempItem 8 8

Bubble Sort

Bubble Sort Bubble Sort Set firstUnsorted to 0 Set index to firstUnsorted + 1 Set swap to TRUE WHILE (index < length AND swap) Set swap to FALSE “Bubble up” the smallest item in unsorted part Set firstUnsorted to firstUnsorted + 1

Bubble Sort Bubble up Set index to length – 1 WHILE (index > firstUnsorted + 1) IF (data[index] < data[index – 1]) Swap data[index] and data[index – 1] Set swap to TRUE Set index to index - 1 11 11

Insertion Sort If you have only one item in the array, it is already sorted. If you have two items, you can compare and swap them if necessary, sorting the first two with respect to themselves. Take the third item and put it into its place relative to the first two Now the first three items are sorted with respect to one another

Insertion Sort The item being added to the sorted portion can be bubbled up as in the bubble sort

Insertion Sort InsertionSort Set current to 1 WHILE (current < length) Set index to current Set placeFound to FALSE WHILE (index > 0 AND NOT placeFound) IF (data[index] < data[index – 1]) Swap data[index] and data[index – 1] Set index to index – 1 ELSE Set placeFound to TRUE Set current to current + 1 14 14

Future Life?