Design and Analysis of Algorithms. Presentation Topic Divide & Conquer Paradigm to design/develop algorithms.

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

College of Information Technology & Design
CSE Lecture 3 – Algorithms I
Analysis of Algorithms CS Data Structures Section 2.6.
A simple example finding the maximum of a set S of n numbers.
1 Divide & Conquer Algorithms. 2 Recursion Review A function that calls itself either directly or indirectly through another function Recursive solutions.
Ver. 1.0 Session 5 Data Structures and Algorithms Objectives In this session, you will learn to: Sort data by using quick sort Sort data by using merge.
Search and Recursion CS221 – 2/23/09. List Search Algorithms Linear Search: Simple search through unsorted data. Time complexity = O(n) Binary Search:
1 CSE1301 Computer Programming Lecture 31: List Processing (Search)
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
CHAPTER 11 Searching. 2 Introduction Searching is the process of finding a target element among a group of items (the search pool), or determining that.
CS Discrete Mathematical Structures Mehdi Ghayoumi MSB rm 132 Ofc hr: Thur, 9:30-11:30a.
ALGORITHM ANALYSIS AND DESIGN INTRODUCTION TO ALGORITHMS CS 413 Divide and Conquer Algortihms: Binary search, merge sort.
Week 11 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Chapter 13 Recursion. Topics Simple Recursion Recursion with a Return Value Recursion with Two Base Cases Binary Search Revisited Animation Using Recursion.
SEARCHING UNIT II. Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances.
1 Linear and Binary Search Instructor: Mainak Chaudhuri
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Searching Course Lecture Slides 28 May 2010 “ Some things Man was never.
LAB#7. Insertion sort In the outer for loop, out starts at 1 and moves right. It marks the leftmost unsorted data. In the inner while loop, in starts.
CSC 211 Data Structures Lecture 13
Sorting and Searching. Searching  Problem definition: Given a value X, return the index of X in the array if such X exist. Otherwise, return NOT_FOUND(-1).
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
1 Recursive algorithms Recursive solution: solve a smaller version of the problem and combine the smaller solutions. Example: to find the largest element.
Concepts of Algorithms CSC-244 Unit 15 & 16 Divide-and-conquer Algorithms ( Binary Search and Merge Sort ) Shahid Iqbal Lone Computer College Qassim University.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Algorithm Analysis 1.
Using recursion for Searching and Sorting
CS1010 Programming Methodology
Subject Name: Design and Analysis of Algorithm Subject Code: 10CS43
OBJECT ORIENTED PROGRAMMING II LECTURE 23 GEORGE KOUTSOGIANNAKIS
Analysis of Algorithms
Searching Given a collection and an element (key) to find… Output
COP 3503 FALL 2012 Shayan Javed Lecture 15
UNIT- I Problem solving and Algorithmic Analysis
Divide-and-Conquer 6/30/2018 9:16 AM
COMP 53 – Week Seven Big O Sorting.
Chapter 7 Single-Dimensional Arrays
Chapter 4 Divide-and-Conquer
Searching & Sorting "There's nothing hidden in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting.
RECITATION 1 ANALYSIS OF ALGORITHMS
Intro to Recursion.
Searching CSCE 121 J. Michael Moore.
Growth Functions Algorithms Lecture 8
CS 3343: Analysis of Algorithms
Unit-2 Divide and Conquer
Hassan Khosravi / Geoffrey Tien
Mergesort Based on divide-and-conquer strategy
CS Two Basic Sorting Algorithms Review Exchange Sorting Merge Sorting
Divide-and-Conquer 7 2  9 4   2   4   7
Medians and Order Statistics
Searching: linear & binary
CSE 373 Data Structures and Algorithms
Divide and Conquer Algorithms Part I
Topic 24 sorting and searching arrays
Basics of Recursion Programming with Recursion
Order Statistics Def: Let A be an ordered set containing n elements. The i-th order statistic is the i-th smallest element. Minimum: 1st order statistic.
Revision of C++.
Divide-and-Conquer 7 2  9 4   2   4   7
Divide & Conquer Algorithms
Recurrences.
Topic: Divide and Conquer
The Selection Problem.
Searching.
Binary Search Binary Search Algorithm
Divide-and-Conquer 7 2  9 4   2   4   7
DIVIDE AND CONQUER.
Presentation transcript:

Design and Analysis of Algorithms

Presentation Topic Divide & Conquer Paradigm to design/develop algorithms

Content of Presentation Topic Search one problem, which can be solved by using divide, & conquer approach. Explain the problem with the help of an example. Design an algorithm-using divide & conquer approach to solve the problems. Analyse an algorithm to find its time & space complexity.

About Presented to Sir Tahir Rasheed Presented by Muhammad Ali SP(17)-BS(CS)-031 Section (A)

Problem Statement and Consideration Statement Given an array array[0.. n-1] of distinct integers, the task is to find a local minima in it. We say that an element array[x] is a local minimum if it is less than or equal to both its neighbors. Consideration I. For corner elements, we need to consider only one neighbor for comparison. II. There can be more than one local minima in an array, we need to find any one of them.

Related Example Input: array[] = {9, 8, 7, 6, 3, 4 }; Output: Index of local minima is 4 The output prints index of 3 because it is smaller than both of its neighbors.

Simple Solution The simple solution is to traverse the array linear and find the local minima. The complexity of the solution is O(n).

Divide & Conquer Binary search Array[] = {9, 8, 7, 6, 3, 4 }; Now I want to show the analyze on above given example in following steps

Algorithm int localMinUtil(int arr[], int low, int high, int n) { int mid = low + (high - low)/2; if ((mid == 0 || arr[mid-1] > arr[mid]) && (mid == n-1 || arr[mid+1] > arr[mid])) return mid; else if (mid > 0 && arr[mid-1] < arr[mid]) return localMinUtil(arr, low, (mid -1), n); else return localMinUtil(arr, (mid + 1), high, n); }

Step 1 Find the middle element Low=0, high=5 Array[] = {9, 8, 7, 6, 3, 4 };Array[] = {9, 8, 7, 6, 3, 4 }; Mid= (low + high)/2 {9, 8, 7} {6, 3, 4 } Mid index = 2 Array[2] = 7

Step 2 if ((mid == 0 || array[mid-1] > array[mid]) && (mid == n-1 || array[mid+1] > array[mid])) return mid; Mid=2, array[mid]=7, array[mid-1]=8, array[mid+1]=6 Note: This statement is not run in algorithm.

Step 3 else if (mid > 0 && array[mid-1] < array[mid]) return localMinUtil (array, low, (mid -1), n); Mid=2, array[mid]=7, array[mid-1]=8, array[mid]=7 Note: This statement is not run in algorithm.

Step 4 else return localMinUtil(array, (mid + 1), high, n); Note: This statement is run in algorithm.

Step 5 Find the middle element Low=3 high=5 Array[] = {9, 8, 7, 6, 3, 4 };Array[] = {9, 8, 7, 6, 3, 4 }; Mid= (low + high)/2 {9, 8, 7} {6, 3, 4 } Mid index = 4 {6, 3} { 4 } Array[4] = 3

Solution Statement if ((mid == 0 || array[mid-1] > array[mid]) && (mid == n-1 || array[mid+1] > array[mid])) return mid; Mid=4, array[mid]=3, array[mid-1]=6, array[mid+1]=5, Note: This statement is run in algorithm and consider as solution.

Time Complexity of the Given Algorithm int localMinUtil(int arr[], int low, int high, int n) T(N) { int mid =( low +high) /2; 1 if ((mid == 0 || arr[mid-1] > arr[mid]) && (mid == n-1 || arr[mid+1] > arr[mid])) 1 return mid; else if (mid > 0 && arr[mid-1] < arr[mid]) return localMinUtil(arr, low, (mid -1), n); n/2 else return localMinUtil(arr, (mid + 1), high, n); n/2 }

Time Complexity of the Given above Algorithm T(n)= T(n/2)+c (Equation 1) T(n/2)= T(n/4)+c (Equation 2) Substitute eq 2 into 1 T(N)= T(N/4)+2c (Equation 3) T(N/4)=T(N/8)+c (Equation 4) Substitute eq 4 into 3 T(N)= T(N/8)+3c (Equation 5)

Time Complexity of the Given above Algorithm Cont..