Algorithms - Computer Science I - Notes | COP 3502, Study notes of Computer Science

Material Type: Notes; Class: Computer Science I; Subject: Computer Programming; University: University of Central Florida; Term: Spring 2005;

Typology: Study notes

Pre 2010

Uploaded on 11/08/2009

koofers-user-p74
koofers-user-p74 🇺🇸

9 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ALGORITHMS
An algorithm is a detailed sequence of actions to perform to
accomplish some task. The name comes from an Iranian mathematician
Al-Khawarizmi.
A more precise definition
– A finite set of step-by-step instructions for a problem-solving or
computation procedure, especially one that can be implemented by a
computer.
OR
- A mathematical procedure that can usually be explicitly encoded in a
set of computer language instructions that manipulate data.
However, the steps of an algorithm are not dependent on any specific
computer language.
It gives an idea of the logical steps used, without bothering about the
syntax of a language.
It helps us in checking if the solution process is correct and efficient,
even before it is run on a computer.
An algorithm can be coded in any computer language.
You might say that the algorithm can be described through a “pseudo
code“. Here are some examples of algorithms.
Finding minimum of 3 numbers:
1. Read the three numbers into a, b and c.
pf3
pf4

Partial preview of the text

Download Algorithms - Computer Science I - Notes | COP 3502 and more Study notes Computer Science in PDF only on Docsity!

ALGORITHMS

An algorithm is a detailed sequence of actions to perform to accomplish some task. The name comes from an Iranian mathematician Al-Khawarizmi. A more precise definition

  • A finite set of step-by-step instructions for a problem-solving or computation procedure, especially one that can be implemented by a computer. OR
  • A mathematical procedure that can usually be explicitly encoded in a set of computer language instructions that manipulate data. However, the steps of an algorithm are not dependent on any specific computer language. It gives an idea of the logical steps used, without bothering about the syntax of a language. It helps us in checking if the solution process is correct and efficient, even before it is run on a computer. An algorithm can be coded in any computer language. You might say that the algorithm can be described through a “pseudo code“. Here are some examples of algorithms.

Finding minimum of 3 numbers:

  1. Read the three numbers into a, b and c.
  1. let min be the variable to hold the minimum value.
  2. if (a < b) then set min = a else set min = b
  3. if (c < min) then set min = c
  4. Print min.

To find smallest divisor of a number. (Alg. A)

  1. If number is even, smallest divisor =2, Go to step 7.
  2. Let divisor be 3.
  3. remainder = number mod divisor
  4. if remainder=0, smallest divisor = 3, Go to step 7.
  5. As long as remainder is not zero & divisor < number keep on doing the following: 5a. divisor = divisor +2. 5b. remainder = number mod divisor. 6., if divisor = number , smallest divisor = 1, else smallest divisor = divisor
  6. print smallest divisor.

To find smallest divisor of a number (Alg. B)

  1. If number is even, smallest divisor =2, Go to step 8.
  2. If number is divisible by 3, smallest divisor = 3, Go to step 8.
  3. Let divisor be 3.
  4. Find factor = number/divisor (get nearest integer value)
  5. remainder = number mod 3 6 As long as remainder is not zero & divisor < factor keep on doing the following;