slide1

22
06/06/22 By:Mr. Sachin S. Bhandari 1 Name: Sachin Sharma Bhandari Qualification: MTech. In Information Technology,Kathmandu University,Nepal Bachelor of Electrical and Electronics Engineering, Kathmandu University,Nepal Experience: Lecturer, Software Engineering Department,2007, CAMT, ChiangMai University, Thailand Senior Lecturer & Head of Department, 2000, Computer & Electronics Engineering Department, Kantipur Engineering College, Tribhuvan University,Nepal Email: [email protected],[email protected]

Upload: thiti-sununta

Post on 07-Nov-2014

2.159 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 1

Name: Sachin Sharma Bhandari

Qualification: MTech. In Information Technology,Kathmandu University,NepalBachelor of Electrical and Electronics Engineering, Kathmandu University,Nepal

Experience: Lecturer, Software Engineering Department,2007,CAMT, ChiangMai University, Thailand

Senior Lecturer & Head of Department, 2000,Computer & Electronics Engineering Department,Kantipur Engineering College, Tribhuvan University,Nepal

Email: [email protected],[email protected]

Page 2: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 2

Introduction to

The Design & Analysis of

Algorithms

Page 3: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 3

Aims of the Module

• Fundamentals about basic and useful algorithms.

• How to design algorithms.

• How to prove their correctness.

• How to measure their performance (in terms of time and space), and

• How to improve their performance if possible.

Page 4: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 4

Indicative Content

• Introduction to Algorithm

• Fundamentals of the analysis of algorithm efficiency

• Design of algorithm

• Number-theoretic algorithms

• Limitations of algorithms and NP-completeness

• Space and time trade offs

• Approximation algorithms

Page 5: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 5

Why do you need to study Algorithms?

• For being a computer professional.

• To know a standard set of important algorithms from different areas of computing.

• To design new algorithms and analyze their efficiency.

• Usefulness in developing analytical skills.

Page 6: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 6

Algorithms• Informally, it is a step- by- step method of solving some problem.

• It is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output.

• An algorithm is thus a sequence of computational steps that transforms the input into the output.

• An algorithm can be specified in English, as a computer program, or even as hardware design.

• Derived from the name of the ninth-century Persian mathematician al-Khowarizmi.

• Today, “algorithm” typically refers to a solution that can be executed by a computer.

Page 7: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 7

Fundamentals of Algorithmic Problem Solving

Understand the problem

Design an Algorithm

Prove correctness

Analyze the algorithm

Code the algorithm

Decide on:Computational means,

Exact vs. approximate solving,Data structure(s),

Algorithm design technique

Fig. Algorithm design and analysis process

Page 8: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 8

Analyzing an Algorithm

• Time Efficiency

How fast the algorithm runs.

• Space Efficiency

How much extra memory the algorithm needs.

• Simplicity

• Generality

Page 9: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 9

Concept of Algorithms

• Input:

• Output:

• Precision: The steps are preciously stated.

• Determinism: The intermediate results of each step of execution are unique and are determined only by the inputs and results of the preceding steps

• Finiteness: The algorithm terminates; that is, it stops after finitely many

instructions have been executed.

• Correctness: The output produced by the algorithm is correct.

• Generality: The algorithm applies to a set of inputs.

Page 10: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 10

Example

• Example: 1 Finding the Maximum of three numbers.

• x=a• If b>x, then x=b.• If c>x, then x=c.

Page 11: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 11

What kinds of problems are solved by algorithms?

Sorting is by no means the only computational problem for which algorithms have been developed. Practical applications of algorithms are ubiquitous (everywhere) and include the following examples.

•The Human Genome Project has the goals of identifying all the 100,000 genes in human DNA, determining the sequences of the 3 billion chemical base pairs that make up human DNA, storing this information in databases, and developing tools for data analysis. Each of these steps requires sophisticated algorithms.

•The internet enables people all around the world to quickly access and retrieve large amounts of information. For this, clever algorithms are employed to manage and manipulate this large volume of data.

Page 12: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 12

(contd.)• Electronic commerce enables goods and services to be negotiated

and exchanged electronically. The ability to keep information such as credit card numbers, passwords,, and bank statements private is essential if electronic commerce is to be used widely. Public-key cryptography and digital signatures are among the core technologies used and are based on numerical algorithms and number theory.

Page 13: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 13

Algorithms as a Technology

• Computers may be fast, but they are not infinitely fast. And memory may be cheap, but it is not free. Computing time is therefore a bounded resource, and so is space in memory. These resources should be used wisely, and algorithms that are efficient in terms of time or space will help you do so.

• Algorithms devised to solve the same problems often differ dramatically in their efficiency. For example: Two algorithms for sorting (Insertion and Merge Sort).

• Total system performance depends on choosing efficient algorithms as much as on choosing fast hardware. Like Intuitive graphical user interfaces (GUIs), object-oriented systems and local area and wide area networking etc.

Page 14: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 14

Pseudo code for Algorithms • Pseudo code is so named because it resembles the actual code of

computer language such as C++ and Java.

• Many versions of Pseudo code.

• It consists of a title, a brief description of the algorithm, the input and output parameters, and the functions containing the instructions of the algorithm.

Page 15: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 15

Review of Data Structures Data Structure

• It is data together with structural relations on the data to promote efficient processing of the data.

• For example: an array structures data provides sequentially and random (i.e. constant time) access to the data.

Abstract Data Types

• ADT consists of data together with functions that operate on data.

• It is abstract in the sense that how the data are represented and how the functions are implemented are not specified. Only the behavior of the functions is specified.

Page 16: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 16

(contd.)

For example: Stack is an ABT with functions• Stack_init ( ): make the stack empty.• Empty ( ): Return true if the stack is empty otherwise false.• Push ( val ): Add the item val to the stack.• Pop ( ): Remove the item most recently added to the stack.• Top ( ): Return the item most recently added to the stack, but don’t

remove it.

Explanation: The preceding function specifications define a stack but do not tell how to implement the stack. In a specific implementation, as long as the functions have the properties specified, the ADT is a stack.

Page 17: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 17

(contd.)

Queues• It is similar to stack but the difference is that when an item is deleted

from a queue, the least recently item is deleted.

• Enqueue (for add) and Dequeue (for delete)

• Adding an element at the rear of a queue and deleting an element form the front of a queue.

• For example: Waiting in line for tickets to a rocket concert.

Page 18: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 18

(contd.)

Linked Lists• However, inserting at the beginning of an array of n elements takes

time Θ (n) because all n items must move over one cell to make room for the added element.

• Deleting the first element form an array of n elements also take time Θ (n).

• A linked list provides constant time insertions and deletions anywhere in the list, but accessing an element takes time Θ (n) in the worst case.

Page 19: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 19

(contd.)

Binary Trees• Rooted tree in which each node has either no children, one child, or

two children. If a node has one child, that child is designated as either a left child or a right child (but not both) and If a node has two children, one child is designated a left child and other a right child.

Page 20: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 20

Assignment1.0 Write a pseudo code for an algorithm for finding real roots of

quadratic equation. ( you may assume the availability of the square root function sqrt(x).)

2.0 Describe the algorithm used by your favorite ATM machine in dispensing cash.

3.0 Design a simple algorithm for the string-matching problem.

4.0 Indicate how the ADT priority queue can be implemented as a. an sorted array.b. an (unsorted) array.c. a binary search tree.

Page 21: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 21

Assignment (contd..)

5.0) For each of the following applications, indicate the most appropriate data structure:

a. answering telephone calls in the order of their known priorities

b. sending backlog orders to customers in order they have been received

c. implementing a calculator for computing simple arithmetical expressions.

Page 22: Slide1

04/08/23 By:Mr. Sachin S. Bhandari 22

Thank You !