Lecture 3 Tuesday, February 10, 2015 [With the help of free online resources]

Slides:



Advertisements
Similar presentations
Back to Sorting – More efficient sorting algorithms.
Advertisements

CS 206 Introduction to Computer Science II 02 / 27 / 2009 Instructor: Michael Eckmann.
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 6.
1 Divide & Conquer Algorithms. 2 Recursion Review A function that calls itself either directly or indirectly through another function Recursive solutions.
DIVIDE AND CONQUER APPROACH. General Method Works on the approach of dividing a given problem into smaller sub problems (ideally of same size).  Divide.
Lecture 3 Tuesday, February 10, 2015 [With the help of free online resources]
CMPS1371 Introduction to Computing for Engineers SORTING.
 2003 Prentice Hall, Inc. All rights reserved. 1 Recursion Recursive functions –Functions that call themselves –Can only solve a base case If not base.
Fall 2008Programming Development Techniques 1 Topic 3 Linear Recursion and Iteration September 2008.
Lesson 19 Recursion CS1 -- John Cole1. Recursion 1. (n) The act of cursing again. 2. see recursion 3. The concept of functions which can call themselves.
Insertion sort, Merge sort COMP171 Fall Sorting I / Slide 2 Insertion sort 1) Initially p = 1 2) Let the first p elements be sorted. 3) Insert the.
Lecture 3 Nearest Neighbor Algorithms Shang-Hua Teng.
CSE 326: Data Structures Lecture #3 Analysis of Recursive Algorithms Alon Halevy Fall Quarter 2000.
Lecture 2: Divide and Conquer I: Merge-Sort and Master Theorem Shang-Hua Teng.
16/23/2015 9:48 AM6/23/2015 9:48 AM6/23/2015 9:48 AMRecursion Recursion Recursion is when a function calls itself to implement an algorithm. Really a paradigm.
ICS103 Programming in C Lecture 11: Recursive Functions
CS2420: Lecture 9 Vladimir Kulyukin Computer Science Department Utah State University.
Lecture 6 Divide and Conquer for Nearest Neighbor Problem Shang-Hua Teng.
Chapter 15 Recursive Algorithms. 2 Recursion Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Unit 1. Sorting and Divide and Conquer. Lecture 1 Introduction to Algorithm and Sorting.
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
1.7 Arrays academy.zariba.com 1. Lecture Content 1.Basic Operations with Arrays 2.Console Input & Output of Arrays 3.Iterating Over Arrays 4.List 5.Cloning.
ALGORITHM ANALYSIS AND DESIGN INTRODUCTION TO ALGORITHMS CS 413 Divide and Conquer Algortihms: Binary search, merge sort.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19: Recursion.
Department of Computer Science and Engineering, HKUST 1 HKUST Summer Programming Course 2008 Recursion.
Chapter 14: Recursion Starting Out with C++ Early Objects
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions and Recursion Outline Function Templates Recursion Example Using Recursion: The Fibonacci Series.
Recursion. Basic problem solving technique is to divide a problem into smaller subproblems These subproblems may also be divided into smaller subproblems.
Lecture 8. How to Form Recursive relations 1. Recap Asymptotic analysis helps to highlight the order of growth of functions to compare algorithms Common.
C++ Beginner Tutorial: Functions IV Recursion. What is recursion? A property of function to be able to call itself… Get factorial of a given number: Factorial.
Advance Data Structure and Algorithm COSC600 Dr. Yanggon Kim Chapter 1.
Comp 245 Data Structures Recursion. What is Recursion? A problem solving concept which can be used with languages that support the dynamic allocation.
Recursion and Dynamic Programming. Recursive thinking… Recursion is a method where the solution to a problem depends on solutions to smaller instances.
10/14/ Algorithms1 Algorithms - Ch2 - Sorting.
Data Structures R e c u r s i o n. Recursive Thinking Recursion is a problem-solving approach that can be used to generate simple solutions to certain.
1 CSE 20 Lecture 11 Function, Recursion & Analysis CK Cheng UC San Diego.
By: Lokman Chan Recursive Algorithm Recursion Definition: A function that is define in terms of itself. Goal: Reduce the solution to.
Main Index Contents 11 Main Index Contents Building a Ruler: drawRuler() Building a Ruler: drawRuler() Merge Algorithm Example (4 slides) Merge Algorithm.
Chapter 5 – Functions II Outline Recursion Examples Using Recursion: The Fibonacci Series.
LECTURE 20: RECURSION CSC 212 – Data Structures. Humorous Asides.
CSC317 1 So far so good, but can we do better? Yes, cheaper by halves... orkbook/cheaperbyhalf.html.
Sorting Algorithms Merge Sort Quick Sort Hairong Zhao New Jersey Institute of Technology.
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
1 Recursion Recursive function: a function that calls itself (directly or indirectly). Recursion is often a good alternative to iteration (loops). Its.
CMPT 238 Data Structures More on Sorting: Merge Sort and Quicksort.
Chapter 6 (Lafore’s Book) Recursion Hwajung Lee.  Definition: An algorithmic technique. To solve a problem on an instance of size n, the instance is:
Fundamentals of Algorithms MCS - 2 Lecture # 11
CMPS 5433 Programming Models
Unit 1. Sorting and Divide and Conquer
Lecture 4 Divide-and-Conquer
Algorithm Design Methods
Applied Algorithms (Lecture 17) Recursion Fall-23
Algorithm Analysis (for Divide-and-Conquer problems)
Growth Functions Algorithms Lecture 8
Data Structures & Algorithms
Exam 2 Review 1.
Data Structures and Algorithms
Programming application CC213
CSE 373 Data Structures and Algorithms
Divide and Conquer Algorithms Part I
Divide & Conquer Algorithms
Advanced Programming Techniques
Last Class We Covered Recursion Stacks Parts of a recursive function:
Recursive Algorithms 1 Building a Ruler: drawRuler()
ITEC324 Principle of CS III
Presentation transcript:

Lecture 3 Tuesday, February 10, 2015 [With the help of free online resources]

Divide and Conquer Divide and Conquer? Split the entire range into smaller manageable parts. Solve each part separately. Combine the results to get result for the original larger problem. Merge

Divide and Conquer Recursive Divide and Conquer? Doing Divide and Conquer recursively. i.e., First divide into two parts, then divide each of those two parts into two more smaller parts and so on until reach a small enough size. cilk_for is also implemented as a recursive divide and conquer. Splits the loop range in a divide and conquer way ………

Homework: Implement it and show the performance.

Merge Sort: Sort n numbers recursively using divide and conquer. Picture: Wikipedia

Divide and Conquer Fibonacci number: In mathematics, the Fibonacci numbers or Fibonacci sequence are the numbers in the following integer sequence …. F(n) = F(n - 1) + F (n - 2) int fib(int n) { if (n < 2) return n; int x = fib(n-1); int y = fib(n-2); return x + y; } int fib(int n) { if (n < 2) return n; int x = cilk_spawn fib(n-1); int y = fib(n-2); cilk_sync; return x + y; }

Matrix-multiplication Iterative-MM ( Z, X, Y ) // X, Y, Z are n × n matrices, // where n is a positive integer 1. for i ← 1 to n do 3. Z[ i ][ j ] ← 0 4. for k ← 1 to n do 2. for j ← 1 to n do 5. Z[ i ][ j ] ← Z[ i ][ j ] + (X[ i ][ k ] * Y[ k ][ j ]) Par-Iterative-MM ( Z, X, Y ) // X, Y, Z are n × n matrices, // where n is a positive integer 1. parallel for i ← 1 to n do 3. Z[ i ][ j ] ← 0 4. for k ← 1 to n do 2. parallel for j ← 1 to n do 5. Z[ i ][ j ] ← Z[ i ][ j ] + X[ i ][ k ] ⋅ Y[ k ][ j ] Source:

Links for c/c++ tutorial CZ5kHTiQHcm-l2q8j06ofd (probably by this time you know all) CZ5kHTiQHcm-l2q8j06ofd Source: google!

Group Homework1 [1]. Teach yourself c/c++ Watch these online videos and other resources freely available in Google and write a 10 page group report on c/c++ basic data types, for loops, input, output, arrays and metrics with dynamic allocation, and function l2q8j06ofd (probably by this time you know all) [2]. Write all the codes discussed in the class so far. Compile them and generate output. Vary n and take the time using the cilktime function. Report the change in running time with n. Fix n to the largest and vary # of cores and report the running time.