0% found this document useful (0 votes)
10 views7 pages

Laboratory No.6

The document outlines the objectives and key concepts of algorithm development, including definitions, characteristics, and methods of representation such as pseudocode and flowcharts. It provides step-by-step guidance for developing algorithms and includes examples and activities for analysis and creation. The document emphasizes the importance of efficiency in algorithms, comparing linear and binary search methods.

Uploaded by

columnakim93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

Laboratory No.6

The document outlines the objectives and key concepts of algorithm development, including definitions, characteristics, and methods of representation such as pseudocode and flowcharts. It provides step-by-step guidance for developing algorithms and includes examples and activities for analysis and creation. The document emphasizes the importance of efficiency in algorithms, comparing linear and binary search methods.

Uploaded by

columnakim93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Laboratory No.

Algorithm Development

Objectives

By the end of this lecture, students will be able to:

• Define what an algorithm is.

• Identify characteristics of a good algorithm.

• Develop simple algorithms using pseudocode and flowcharts.

• Analyze the correctness and efficiency of algorithms.

Introduction

2.1 What is an Algorithm?

• Definition: A step-by-step procedure or formula for solving a problem.

• Examples in Daily Life:

o Recipe for cooking.

o Instructions for assembling furniture.

• Characteristics:

o Finiteness (must terminate).

o Definiteness (clear steps).

o Input and Output.

o Effectiveness (achievable steps).

2.2 Algorithm Representation

• Pseudocode: Writing steps in simple, human-readable text.

• Flowchart: Visual representation using standard symbols.


Examples:

2.3 Steps to Develop an Algorithm

1. Understand the problem.

2. Plan the solution.


3. Write the pseudocode.

4. (Optional) Draw the flowchart.

5. Test the algorithm.

2.4 Example Algorithm:

Problem: Find the largest of three numbers.


Pseudocode:

1. Start.

2. Input three numbers: A, B, C.

3. If A > B and A > C, then output A is the largest.

4. Else if B > A and B > C, then output B is the largest.

5. Else, output C is the largest.

6. Stop.

Activities

Activity 1: Algorithm Analysis

Task: Identify errors in the given pseudocode.


Pseudocode:

1. Start.

2. Input two numbers: X, Y.

3. If X > Y, then output "X is smaller".

4. Else, output "Y is smaller".

5. Stop.

Answer Key:

• The output in step 3 should be corrected to "X is larger".

Activity 2: Develop an Algorithm

Task: Write a pseudocode for calculating the factorial of a number N.


Answer Key:

1. Start.

2. Input N.
3. Set Factorial = 1.

4. For i from 1 to N:

o Factorial = Factorial * i.

5. Output Factorial.

6. Stop.

Activity 3: Create a Flowchart

Task: Create a flowchart for determining if a number is even or odd.


Answer Key:

• Flowchart Steps:

1. Start.

2. Input a number (N).

3. Check N % 2 == 0:

▪ Yes: Output "Even".

▪ No: Output "Odd".

4. Stop.
Activity 4: Efficiency Analysis

Task: Which algorithm is more efficient, and why?


• Algorithm 1: Linear search to find a number in a list.

• Algorithm 2: Binary search to find a number in a sorted list.

Answer Key:

• Binary search is more efficient because it has a time complexity of O(log n), while linear search
has O(n). Binary search reduces the problem size by half with each step.

You might also like