Download presentation
Presentation is loading. Please wait.
Published byMarjory Malone Modified over 9 years ago
1
CSCI-100 Introduction to Computing Algorithms Part I
2
Algorithms The 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
3
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.
5
Categories of operations Sequential 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
6
Example Algorithm for programming your VCR (DONE IN CLASS)
7
Steps to solving problems Understand 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
8
Algorithm 1 Line 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
9
Algorithm 2 Line up all the people along one wall As long as more than one person in the line, repeatedly Have the people pair up (1 st with 2 nd, 3 rd with 4 th, 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
10
Algorithm Analysis Algorithm 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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.