National Institute of Textile Engineering & Research
Department of Computer Science and Engineering
Course title: Data Structure and Algorithms
Course code: CSE 1201
Submitted by : Submitted to
Name : Samiul Hasan
ID: CS 2102013
Anichur Rahman
Lecturer , NITER
Quick Sort
CONTENTS
• What is Quick Sort
• Algorithm
• Working procedure at a glance
• Pseudocode
• Divide-and-conqure procedure
• Conclusion
What is Quick Sort
Quick sort is a sorting algorithm that uses the divide-and-conquer
strategy to sort an array by partitioning it into two sub-arrays and
recursively sorting them.
Algorithm
Given an array of n elements (e.g., integers):
• If array only contains one element, return
• Else
• pick one element to use as pivot.
• Partition elements into two sub-arrays:
• Elements less than or equal to pivot
• Elements greater than pivot
Quicksort two sub-arrays
Working procedure of quick sort
[8, -2, 5, 2, 6, 7, 1, 3]
3
-2,2,1 8,5,6,7
5,6
-2 2
1
7
6
8
5
Pseudocode:
Array Partitioning
According to pseudocode let we got a array:
8 -2 5 2 6 7 1 3
Suppose the given array is :
8 -2 5 2 6 7 1 3
pivot
Suppose the given array is :
8 -2 5 2 6 7 1 3
8
-2
5
2
6 7
3
1
Suppose the given array is :
8 -2 5 2 6 7 1 3
8
-2 5
2 6 7
3
1
-2 2
1
Suppose the given array is :
8 -2 5 2 6 7 1 3
8
-2 5
2 6 7
3
1
-2 2
1
5
8
6
7
Suppose the given array is :
8 -2 5 2 6 7 1 3
8
-2
5
2
6 7
3
1
-2 2
1
5 8
6
7
5
6
Conquer Stage:
-2 2
1
8
7
5 6
-2 1 2
-2 2
1
8
7
5 6
-2 1 2
5 6
-2 2
1
8
7
5 6
-2 1 2
5 6 8
-2 2
1
8
7
5 6
-2 1 2
5 6 8
-2 1 2 5 6 8
Code
Conclusion
Quick Sort is a widely used sorting algorithm that follows the divide-and-conquer approach,
recursively dividing the input array into two smaller sub-arrays and sorting them based on a
chosen pivot element. It has an average time complexity of O(nlogn) and is often faster in
practice than other popular sorting algorithms like Merge Sort and Heap Sort.
Thank You

Quicksort algorithm and implantation process

  • 1.
    National Institute ofTextile Engineering & Research Department of Computer Science and Engineering Course title: Data Structure and Algorithms Course code: CSE 1201 Submitted by : Submitted to Name : Samiul Hasan ID: CS 2102013 Anichur Rahman Lecturer , NITER
  • 2.
    Quick Sort CONTENTS • Whatis Quick Sort • Algorithm • Working procedure at a glance • Pseudocode • Divide-and-conqure procedure • Conclusion
  • 3.
    What is QuickSort Quick sort is a sorting algorithm that uses the divide-and-conquer strategy to sort an array by partitioning it into two sub-arrays and recursively sorting them.
  • 4.
    Algorithm Given an arrayof n elements (e.g., integers): • If array only contains one element, return • Else • pick one element to use as pivot. • Partition elements into two sub-arrays: • Elements less than or equal to pivot • Elements greater than pivot Quicksort two sub-arrays
  • 5.
    Working procedure ofquick sort [8, -2, 5, 2, 6, 7, 1, 3] 3 -2,2,1 8,5,6,7 5,6 -2 2 1 7 6 8 5
  • 6.
  • 7.
    Array Partitioning According topseudocode let we got a array: 8 -2 5 2 6 7 1 3
  • 8.
    Suppose the givenarray is : 8 -2 5 2 6 7 1 3 pivot
  • 9.
    Suppose the givenarray is : 8 -2 5 2 6 7 1 3 8 -2 5 2 6 7 3 1
  • 10.
    Suppose the givenarray is : 8 -2 5 2 6 7 1 3 8 -2 5 2 6 7 3 1 -2 2 1
  • 11.
    Suppose the givenarray is : 8 -2 5 2 6 7 1 3 8 -2 5 2 6 7 3 1 -2 2 1 5 8 6 7
  • 12.
    Suppose the givenarray is : 8 -2 5 2 6 7 1 3 8 -2 5 2 6 7 3 1 -2 2 1 5 8 6 7 5 6
  • 13.
  • 14.
  • 15.
  • 16.
    -2 2 1 8 7 5 6 -21 2 5 6 8 -2 1 2 5 6 8
  • 17.
  • 18.
    Conclusion Quick Sort isa widely used sorting algorithm that follows the divide-and-conquer approach, recursively dividing the input array into two smaller sub-arrays and sorting them based on a chosen pivot element. It has an average time complexity of O(nlogn) and is often faster in practice than other popular sorting algorithms like Merge Sort and Heap Sort.
  • 19.