12
COMPUTER PROGRAMMING

COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Embed Size (px)

Citation preview

Page 1: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

COMPUTER PROGRAMMING

Page 2: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Algorithms• The following points will be addressed during this lecture:• What are algorithms?• Why is the study of algorithms worthwhile?• What is the role of algorithms relative to other

technologies used in computers?

Page 3: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Algorithms• an algorithm 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 a sequence of computational steps that transform the input into the output.

• a tool for solving a well-specified computational problem.

Page 4: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Algorithms• Example “Sorting numbers”:

• sorting a sequence of numbers into decreasing or increasing order.

• Normal problem appears in practise.

• how we formally define the sorting problem?

Page 5: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Algorithms• Input: A sequence of n numbers a1; a2; ….. ;an .

• Output: A permutation (reordering) a’1; a’2; ….. ;a’n

of the input sequence such that

a’1< a’2< ….. <a’n .

• example, given the input sequence (31; 59; 26; 41; 58), a sorting algorithm would return as output the sequence (26; 31; 41; 58; 59).

Page 6: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Algorithms• the input sequence is called an instance of the sorting

problem.

• In general, an instance of a problem consists of the input) needed to compute a solution to the problem.

• What is a correct algorithm? What is an incorrect algorithm?

• An algorithm is said to be correct if, for every input instance, it halts with the correct output.

• So, the correct algorithm solves the given computational problem.

Page 7: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Algorithms

• An incorrect algorithm might not give an answer at all on some input instances, or it might give an incorrect answer.

• Can the incorrect algorithms be useful?• Yes, if the error rate is controllable.

How to specify an algorithm?• In English like a computer program• Or as a hardware design.

Page 8: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Specification of an algorithm.• the requirement for the specification:• the specification must provide a precise description of the

computational procedure to be followed.

What kinds of problems are solved by algorithms?• Sorting a sequence of numbers is not the only problem

for whom algorithms were developed.

Page 9: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Ex. Of Problems• Example of problems:• The Human Genome Project has made great progress

toward 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.

Page 10: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Ex. Of Problems

• The Internet enables people all around the world to quickly access and retrieve large amounts of information. With the aid of clever algorithms, sites on the Internet are able to manage and manipulate this large volume of data. Examples of problems that make essential use of algorithms include finding good routes on which the data will travel.

Page 11: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Ex. Of Problems

• Electronic commerce enables goods and services to be negotiated and exchanged electronically, and it depends on the privacy of personal information such as credit card numbers, passwords, and bank statements. The core technologies used in electronic commerce include public-key cryptography and digital signatures which are based on numerical algorithms and number theory.

Page 12: COMPUTER PROGRAMMING. Algorithms The following points will be addressed during this lecture: What are algorithms? Why is the study of algorithms worthwhile?

Algorithm characteristics• Common characteristics to many interesting algorithmic

problems:

• They have many candidate solutions, majority of them do not solve the problem at hand. Finding one that does, or one that is “best,” can present quite a challenge.

• they have practical applications. finding the shortest path provides the easiest examples.