0% found this document useful (0 votes)
56 views

CCC121-07-Sorting Algorithms

The document discusses various searching and sorting algorithms. It provides an overview of linear search and binary search as two common searching algorithms. Linear search sequentially checks each element while binary search divides the search space in half with each comparison. The document also summarizes selection sort, insertion sort, merge sort, quicksort, and heap sort as common sorting algorithms. It provides interactive examples and videos for each algorithm to help understand how they work.

Uploaded by

Joshua Madula
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

CCC121-07-Sorting Algorithms

The document discusses various searching and sorting algorithms. It provides an overview of linear search and binary search as two common searching algorithms. Linear search sequentially checks each element while binary search divides the search space in half with each comparison. The document also summarizes selection sort, insertion sort, merge sort, quicksort, and heap sort as common sorting algorithms. It provides interactive examples and videos for each algorithm to help understand how they work.

Uploaded by

Joshua Madula
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Searching

& Sorting Algorithms


CCC121 – Data Structures and Algorithms
Discussions

01 Searching Algorithms

02 Sorting Algorithms
Note
Several resources will be presented in the following sections. These resources
provide interactive examples where you can run it and modify it for practice
purposes. Some resources also provide videos in the bottom part of the webpage
to understand the topic easier.

Suggestion: Running some of the interactive examples might not work on some mobile browsers.
You may copy & paste it instead on a mobile IDE (Ex. Dcoder) and run the program.
Searching Algorithms

Check the video link below for an overview introduction of trees:


• Binary Search

Searching Algorithms are designed to check for an element or retrieve an element from
any data structure where it is stored. Based on the type of search operation, these
algorithms are generally classified into two categories:

• Sequential Search: In this, the list or array is traversed sequentially and every element is
checked. For example: Linear Search.

• Interval Search: These algorithms are specifically designed for searching in sorted data-
structures. These type of searching algorithms are much more efficient than Linear
Search as they repeatedly target the center of the search structure and divide the search
space in half. For Example: Binary Search.
Searching Algorithms

Linear Search

Linear search is a very simple search algorithm. In this type of search, a sequential search
is made over all items one by one. Every item is checked and if a match is found then that
particular item is returned, otherwise the search continues till the end of the data collection.

Click the following resources for more details:


• Linear Search (Interactive Examples and Video)
Searching Algorithms

Binary Search

Binary search is a fast search algorithm with run-time complexity of Ο(log n). This search
algorithm works on the principle of divide and conquer. For this algorithm to work properly,
the data collection should be in the sorted form.

Binary search looks for a particular item by comparing the middle most item of the
collection. If a match occurs, then the index of item is returned. If the middle item is
greater than the item, then the item is searched in the sub-array to the right of the middle
item. Otherwise, the item is searched for in the sub-array to the left of the middle item.
This process continues on the sub-array as well until the size of the subarray reduces to
zero.
Searching Algorithms

Binary Search

Click the following resources for more details:


• Binary Search (Interactive Examples and Video)

Divide and Conquer


Divide and Conquer is an algorithmic paradigm. A typical Divide and Conquer algorithm
solves a problem using following three steps.

• Divide: Break the given problem into subproblems of same type.


• Conquer: Recursively solve these subproblems
• Combine: Appropriately combine the answers
Sorting Algorithms

Sorting Algorithm is used to rearrange a given array or list elements according to a


comparison operator on the elements. The comparison operator is used to decide the
new order of element in the respective data structure.

Some of the most common sorting algorithms are:


• Selection Sort
• Bubble Sort
• Merge Sort
• Quick Sort
• Heap Sort
Sorting Algorithms

Selection Sort

Selection sort is conceptually the most simplest sorting algorithm. This algorithm will first
find the smallest element in the array and swap it with the element in the first position,
then it will find the second smallest element and swap it with the element in the second
position, and it will keep on doing this until the entire array is sorted.

It is called selection sort because it repeatedly selects the next-smallest element and
swaps it into the right place.

Click the following resources for more details:


• Selection Sort (Interactive Examples and Video)
• Selection Sort Lecture Video
Sorting Algorithms

Insertion Sort

Insertion sort is the sorting mechanism where the sorted array is built having one item at a
time. The array elements are compared with each other sequentially and then arranged
simultaneously in some particular order. The analogy can be understood from the style we
arrange a deck of cards. This sort works on the principle of inserting an element at a
particular position, hence the name Insertion Sort.

Click the following resources for more details:


• Insertion Sort (Interactive Examples and Video)
• Insertion Sort Lecture Video
Sorting Algorithms

Bubble Sort

Bubble sort is a simple sorting algorithm. This sorting algorithm is comparison-based


algorithm in which each pair of adjacent elements is compared and the elements are
swapped if they are not in order. This algorithm is not suitable for large data sets as its
average and worst case complexity are of O(n2) where n is the number of items.

Click the following resources for more details:


• Bubble Sort (Interactive Examples and Video)
• Bubble Sort Lecture Video
Sorting Algorithms

Merge Sort

Merge sort is a sorting technique based on divide and conquer technique. With worst-case
time complexity being Ο(n log n), it is one of the most respected algorithms. Merge sort
first divides the array into equal halves and then combines them in a sorted manner.

Click the following resources for more details:


• Merge Sort (Interactive Examples and Video)
• Merge Sort Lecture Video
Sorting Algorithms

Heap Sort

Heap sort can be understood as the improved version of the binary search tree. It does not
create a node as in case of binary search tree instead it builds the heap by adjusting the
position of elements within the array itself. In which method a tree structure called heap is
used where a heap is a type of binary tree.

Click the following resources for more details:


• Heap Sort (Interactive Examples and Video)
• Heap Sort Lecture Video
Sorting Algorithms

Quick Sort

Quick sort is a highly efficient sorting algorithm and is based on partitioning of array of
data into smaller arrays. A large array is partitioned into two arrays one of which holds
values smaller than the specified value, say pivot, based on which the partition is made
and another array holds values greater than the pivot value.

Quick sort partitions an array and then calls itself recursively twice to sort the two resulting
subarrays. This algorithm is quite efficient for large-sized data sets as its average and
worst case complexity are of O(nlogn), where n is the number of items.

Click the following resources for more details:


• Quick Sort (Interactive Examples)
• Quick Sort Example Video
• You will have a long quiz on Tuesday (Dec. 14) on sorting algorithms.
END OF PRESENTATION

You might also like