1. Trang chủ
  2. » Công Nghệ Thông Tin

Session 07 Introduction to Programming

34 244 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 34
Dung lượng 1,19 MB

Nội dung

C was initially used for systems programmingA system program forms a portion of the operating system of the computer or its support utilitiesOperating Systems, Interpreters, Editors, Assembly programs are usually called system programsThe UNIX operating system was developed using CThere are C compilers available for almost all types of PC’s

LBC, Session 7 Searching and Sorting FPT APTECH COMPUTER EDUCATION HANOI Objectives • Explain the need of searching and sorting • Discuss basic sorting algorithms: – Bubble Sort – Insertion Sort • Discuss basic searching algorithms: – Linear Search – Binary Search LBC/Session 7 2 Sorting • Sorting involves arranging the array data in a specified order such as ascending or descending • Data in an array is easier to search when the array is sorted • Two of methods to sort arrays: Selection Sort and Bubble Sort LBC/Session 7 3 Sorting (cont’d) • In the selection sort method, the value present in each element is compared with the subsequent elements in the array to obtain the least/greatest value • There are 2 approaches in bubble sort implementation:  Bottom-up  Top-down LBC/Session 7 4 Bubble Sort • • 12 6 12 6 22 14 22 14 8 8 17 22 17 22 6 12 14 8 14 8 17 22 For an array of n elements Repeat these following steps n-1 times:  With a[i] and a[i+1]:  If a[i] greater than a[i+1] then swap there location. LBC/Session 7 5 Bubble Sort int i,j,temp,arr[5]={23,90,9,25,16}; for (int i=0; i[...]...Insertion Sort 1 17 45 18 12 22 2 3 4 5 6 2 3 4 5 6 23 1 LBC /Session 7 11 Insertion Sort 1 2 17 23 1 2 45 18 12 22 3 4 5 6 3 4 5 6 LBC /Session 7 12 Insertion Sort 1 2 3 17 23 45 1 2 3 18 12 22 4 5 6 4 5 6 LBC /Session 7 13 Insertion Sort 1 2 3 4 17 18 23 45 1 2 3 4 LBC /Session 7 12 22 5 6 5 6 14 Insertion Sort 1 2 3 4 5 6 12 17 18 22 23 45 1 2 3 4 5 6 LBC /Session 7 15 Insertion Sort int data[5] = { 23, 90, 9,... data[i+1] = data[i]; i ; } data[i+1] = tmp; } LBC /Session 7 16 Searching For this lesson, we discuss two kinds of searching: • Linear search • Binary search LBC /Session 7 17 Linear Searching  This is the simplest way to find an element in an array by visiting all elements of the array until the item is found  Also called Sequential searching LBC /Session 7 18 Linear Searching int data[] = {5,2,9,7,6,10};... i ... put to the ‘right’ location, the array is sorted LBC /Session 7 Insertion Sort 23 17 45 18 LBC /Session 12 22 Insertion Sort 23 17 45 18 12 22 LBC /Session Insertion Sort 23 17 45 18 12 22 6 LBC /Session. .. the subsequent elements in the array to obtain the least/greatest value • There are approaches in bubble sort implementation:  Bottom-up  Top-down LBC /Session Bubble Sort • • 12 12 22 14 22... 17 45 18 12 22 6 23 LBC /Session 11 Insertion Sort 17 23 45 18 12 22 6 LBC /Session 12 Insertion Sort 17 23 45 18 12 22 6 LBC /Session 13 Insertion Sort 17 18 23 45 LBC /Session 12 22 6 14 Insertion

Ngày đăng: 08/10/2015, 22:23

TỪ KHÓA LIÊN QUAN