Presentation is loading. Please wait.

Presentation is loading. Please wait.

D IVIDE AND CONQUER STRATEGY, D ATA TYPE, A LGORITHM DESIGN AND PRACTICE. Week 13 Mr.Mohammed Rahmath.

Similar presentations


Presentation on theme: "D IVIDE AND CONQUER STRATEGY, D ATA TYPE, A LGORITHM DESIGN AND PRACTICE. Week 13 Mr.Mohammed Rahmath."— Presentation transcript:

1 D IVIDE AND CONQUER STRATEGY, D ATA TYPE, A LGORITHM DESIGN AND PRACTICE. Week 13 Mr.Mohammed Rahmath

2 D IVIDE AND CONQUER STRATEGY A divide and conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same (or related) type, until these become simple enough to be solved directly. The solutions to the sub-problems are then combined to give a solution to the original problem. Mr.Mohammed Rahmath

3

4 A DVANTAGES OF DIVIDE AND CONQUER STRATEGY Solving difficult problems Algorithm efficiency Parallelism Memory access Roundoff control Mr.Mohammed Rahmath

5 D ATA TYPE Data type is define as the type of data. Example: integers, Boolean, characters, floating- point numbers, alphanumeric strings… Mr.Mohammed Rahmath

6 A LGORITHM Definition : an algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing, and automated reasoning. Mr.Mohammed Rahmath

7 S TEPS IN DEVELOPMENT OF A LGORITHMS 1. Problem definition 2. Development of a modal 3. Specification of Algorithm 4. Designing an Algorithm 5. Checking the correctness of Algorithm 6. Analysis of Algorithm 7. Implementation of Algorithm 8. Program testing 9. Documentation Preparation Mr.Mohammed Rahmath

8 E XAMPLE Q) Write a algorithm to find out number is odd or even? step 1 : start step 2 : input number step 3 : rem=number mod 2 step 4 : if rem=0 then print "number even" else print "number odd" endif step 5 : stop Mr.Mohammed Rahmath

9 Q) Write an algorithm to add two numbers entered by user. Step 1: Start Step 2: Declare variables num1, num2 and sum. Step 3: Read values num1 and num2. Step 4: Add num1 and num2 and assign the result to sum. sum←num1+num2 Step 5: Display sum Step 6: Stop Mr.Mohammed Rahmath

10 Q) Write an algorithm to check whether a number entered by user is prime or not. Step 1: Start Step 2: Declare variables n,i,flag. Step 3: Initialize variables flag←1 i←2 Step 4: Read n from user. Step 5: Repeat the steps until i<(n/2) 5.1 If remainder of n÷i equals 0 flag←0 Go to step 6 5.2 i←i+1 Step 6: If flag=0 Display n is not prime else Display n is prime Step 7: Stop Mr.Mohammed Rahmath

11 Q) Write an algorithm to find the largest among three different numbers entered by user. Step 1: Start Step 2: Declare variables a,b and c. Step 3: Read variables a,b and c. Step 4: If a>b If a>c Display a is the largest number. Else Display c is the largest number. Else If b>c Display b is the largest number. Else Display c is the greatest number. Step 5: Stop Mr.Mohammed Rahmath

12 S ESSION 13 E ND Mr.Mohammed Rahmath


Download ppt "D IVIDE AND CONQUER STRATEGY, D ATA TYPE, A LGORITHM DESIGN AND PRACTICE. Week 13 Mr.Mohammed Rahmath."

Similar presentations


Ads by Google