csci-100 introduction to computing algorithms part i
TRANSCRIPT
![Page 1: CSCI-100 Introduction to Computing Algorithms Part I](https://reader036.vdocument.in/reader036/viewer/2022082517/56649de45503460f94adb0b4/html5/thumbnails/1.jpg)
CSCI-100Introduction to Computing
AlgorithmsPart I
![Page 2: CSCI-100 Introduction to Computing Algorithms Part I](https://reader036.vdocument.in/reader036/viewer/2022082517/56649de45503460f94adb0b4/html5/thumbnails/2.jpg)
• AlgorithmsThe central concept underlying all computation is that of the algorithm
An algorithm is a step-by-step sequence of instructions for carrying out some task
Programming can be viewed as the process of designing and implementing algorithms that a computer can carry out
A programmer’s job is to: • Create an algorithm for accomplishing a given objective, then • Translate the individual steps of the algorithm into a
programming language that the computer can understand
![Page 3: CSCI-100 Introduction to Computing Algorithms Part I](https://reader036.vdocument.in/reader036/viewer/2022082517/56649de45503460f94adb0b4/html5/thumbnails/3.jpg)
Dictionary definition• Procedure for solving a mathematical problem in a finite
number of steps that frequently involves repetition of an operation
• A step-by-step method for accomplishing a task
Informal description• An ordered sequence of instructions that is guaranteed
to solve a specific problem– STEP 1: Do something.– STEP 2: Do something.– STEP 3: Do something.
. . . . . .
– STEP N: Stop. You are finished.
![Page 4: CSCI-100 Introduction to Computing Algorithms Part I](https://reader036.vdocument.in/reader036/viewer/2022082517/56649de45503460f94adb0b4/html5/thumbnails/4.jpg)
![Page 5: CSCI-100 Introduction to Computing Algorithms Part I](https://reader036.vdocument.in/reader036/viewer/2022082517/56649de45503460f94adb0b4/html5/thumbnails/5.jpg)
• Categories of operationsSequential operations
• Carry out a single well-defined task; when that task is finished, the algorithm moves on to the next operation
– Add 1 cup of butter to the mixture in the bowl– Subtract the amount of the check from the current
account balance
Conditional operations• Ask a question and then select the next operation to be
executed on the basis of the answer to that question– If the mixture is too dry, then add one-half cup of water to
the bowl
Iterative operations
• Tell us to go back and repeat the execution of a previous block of instructions
– Repeat previous operations until mixture has thickened
![Page 6: CSCI-100 Introduction to Computing Algorithms Part I](https://reader036.vdocument.in/reader036/viewer/2022082517/56649de45503460f94adb0b4/html5/thumbnails/6.jpg)
• ExampleAlgorithm for programming your VCR
(DONE IN CLASS)
![Page 7: CSCI-100 Introduction to Computing Algorithms Part I](https://reader036.vdocument.in/reader036/viewer/2022082517/56649de45503460f94adb0b4/html5/thumbnails/7.jpg)
• Steps to solving problemsUnderstand the problem
Devise a plan
Carry out your plan
Examine the solution
EXAMPLE: finding the oldest person in a room full of people. We will consider 2 different algorithms for solving this problem
![Page 8: CSCI-100 Introduction to Computing Algorithms Part I](https://reader036.vdocument.in/reader036/viewer/2022082517/56649de45503460f94adb0b4/html5/thumbnails/8.jpg)
• Algorithm 1Line up all the people along one wall
Ask the first person to state his or her name and birthday, then write this information down on a piece of paper
For each successive person in line:• Ask the person for his or her name and birthday• if the stated birthday is earlier than the birthday on the
paper, cross out old information and write down the name and birthday of this person
![Page 9: CSCI-100 Introduction to Computing Algorithms Part I](https://reader036.vdocument.in/reader036/viewer/2022082517/56649de45503460f94adb0b4/html5/thumbnails/9.jpg)
• Algorithm 2Line up all the people along one wall
As long as more than one person in the line, repeatedly• Have the people pair up (1st with 2nd, 3rd with 4th, etc) – if
there is an odd number of people, the last person will be without a partner
• Ask each pair of people to compare their birthdays• Request that the younger of the two leave the line
![Page 10: CSCI-100 Introduction to Computing Algorithms Part I](https://reader036.vdocument.in/reader036/viewer/2022082517/56649de45503460f94adb0b4/html5/thumbnails/10.jpg)
• Algorithm AnalysisAlgorithm 1 involves asking each person’s birthday and then comparing it to the birthday written on the page
• The amount of time to find the oldest person is proportional to the number of people
• If you double the amount of people, the time needed to find the oldest person will also double
Algorithm 2 allows you to perform multiple comparisons simultaneously
• The time needed to find the oldest person is proportional to the number of rounds it takes to shrink the line down to one person
– Which turns out to be the logarithm (base 2) of the number of people
• If you double amount of people, the time needed to find the oldest person increases by the cost of one more comparison