Lecture Algorithms and data structures: Chapter 6 - Quick Sort

This topic will describe: The concrete data structures that can be used to store information, the basic forms of memory allocation, the prototypical examples of these: arrays and linked lists, other data structures, finally we will discuss the run-time of queries and operations on arrays and linked lists. | Review 1 Insertion Sort Insertion Sort Algorithm Time Complexity Best case Average case Worst case Examples Quick Sort 2 Quick Sort Quick Sort Algorithm Time Complexity Best case Average case Worst case Examples Introduction It is one of the widely used sorting techniques Quick sort is an efficient algorithm It is also called the partition exchange sort It has a very good time complexity in average case It is an algorithm of the divide-and conquer type 3 How it works? The quick sort algorithm works by partitioning the array to be sorted Each partitions are internally sorted recursively In partition the first element of an array is chosen as a key value This key value can be the first element of an array If A is an array then key = A [0], and rest of the elements are grouped into two portions such that One partition contains elements smaller than key value Another partition contains elements larger than the key value 4 cont Two pointers, up and low, are initialized to the upper and lower bounds of the sub array During execution, at any point each element in a position above up is greater than or equal to key value And each element in a position below low pointer is less than or equal to key up pointer will move in a decrement And low pointer will move in an increment 5 Let A be an array A[1],A[2],A[3] A[n] of n numbers, then Step 1: Choose the first element of the array as the key . key=A[1] Step 2: Place the low pointer in second position of the array and up pointer in the last position of the array . low=2 and up=n Step 3: Repeatedly increase the low pointer by one position until A[low]=key Step 5: if up>low, interchange A[low] with A[up], swap=A[low], A[low]=A[up], A[up]=swap Step 6: Repeat steps 3,4 and 5 until the condition in step 5 fails (. up<=low) then interchange A[up] with key 6 The given array is partitioned into two sub-arrays, the sub-array A[1],A[2], A[k-1] is . | Review 1 Insertion Sort Insertion Sort Algorithm Time Complexity Best case Average case Worst case Examples Quick Sort 2 Quick Sort Quick Sort Algorithm Time Complexity Best case Average case Worst case Examples Introduction It is one of the widely used sorting techniques Quick sort is an efficient algorithm It is also called the partition exchange sort It has a very good time complexity in average case It is an algorithm of the divide-and conquer type 3 How it works? The quick sort algorithm works by partitioning the array to be sorted Each partitions are internally sorted recursively In partition the first element of an array is chosen as a key value This key value can be the first element of an array If A is an array then key = A [0], and rest of the elements are grouped into two portions such that One partition contains elements smaller than key value Another partition contains elements larger than the key value 4 cont Two pointers, up and low, are initialized to the upper and

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.