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

Session 07 Introduction to Programming

34 245 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

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

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

Trang 1

FPT APTECH COMPUTER EDUCATION HANOI

LBC, Session 7

Searching and Sorting

Trang 2

• Explain the need of searching and sorting

• Discuss basic sorting algorithms:

Trang 3

data in a specified order such as

ascending or descending

when the array is sorted

Selection Sort and Bubble Sort

Trang 4

Sorting (cont’d)

value present in each element is

compared with the subsequent

elements in the array to obtain the least/greatest value

sort implementation:

 Bottom-up

 Top-down

Trang 5

148 1488 17 22

17

148

126

6

 With a[i] and a[i+1]:

 If a[i] greater than a[i+1] then swap there location.

Bubble Sort

Trang 7

Insertion Sort

• Main Ideas for sorting using

Insertion Sort:

– For each element of the array, put it to the

‘right’ position between other sorted elements– When the last element is put to the ‘right’

location, the array is sorted

Trang 8

23 17 45 18 12 22

Insertion Sort

Trang 9

23 17 45 18 12 22

Insertion Sort

Trang 12

23 17

Trang 18

Linear Searching

element in an array by visiting all elements of the array until the item

is found

Trang 20

equals, end searching

Step 2: If the comparison returns ‘less than’ repeat step

1 with the left-side part of the array

Step 3: If the comparison returns ‘greater than’ repeat

step 1 with the right-side part of the array

Trang 21

8 2

0

64 14

13 25 33 43 51 53 72 84 93 95 96 97 6

Trang 22

Binary Searching - Example

Example: Find number 33 in the sorted array below:

8 2

0

64 14

13 25 33 43 51 53 72 84 93 95 96 97 6

Trang 23

Binary Searching - Example

Example: Find number 33 in the

sorted array below:

8 2

0

64 14

13 25 33 43 51 53 72 84 93 95 96 97 6

Trang 24

Binary Searching - Example

Example: Find number 33 in the

sorted array below:

8 2

0

64 14

13 25 33 43 51 53 72 84 93 95 96 97 6

Trang 25

Binary Searching - Example

Example: Find number 33 in the

sorted array below:

8 2

0

64 14

13 25 33 43 51 53 72 84 93 95 96 97 6

Trang 26

Binary Searching - Example

Example: Find number 33 in the

sorted array below:

8 2

0

64 14

13 25 33 43 51 53 72 84 93 95 96 97 6

lo mid hi

Trang 27

Binary Searching - Example

Example: Find number 33 in the

sorted array below:

8 2

0

64 14

13 25 33 43 51 53 72 84 93 95 96 97 6

lo hi

Trang 28

Binary Searching - Example

Example: Find number 33 in the

sorted array below:

8 2

0

64 14

13 25 33 43 51 53 72 84 93 95 96 97 6

lo hi mid

Trang 29

Binary Searching - Example

Example: Find number 33 in the

sorted array below:

8 2

0

64 14

13 25 33 43 51 53 72 84 93 95 96 97 6

lo hi mid

Trang 30

Binary Searching – Impl.

Trang 31

Binary Searching – Impl.

Trang 32

• Variables and constants

• Identifier and guidelines for naming identifiers

• Data types

• Basic data types: char, int, float, double, void

• Derived data types: unsigned, short, long

Trang 33

Review (cont’d)

• Input output in C:

– Formatted

– Unformatted

• Conditional statement: if else, switch.

• Loop: for, while, do while.

• Array

• String/character arrays.

Trang 34

• Textbook, Chapter 19

• Sort Animation

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

TỪ KHÓA LIÊN QUAN