{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

algorithms - Basics of Algorithms Computers are devices...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Computers are devices that do only one kind of thing: They carry out algorithms to process information. To computer scientists, the algorithm is the central unifying concept of computing, the mode of thought that is the core of the computing perspective. What is an algorithm? A set of logical steps to accomplish a task. A “recipe of action”. A way of describing behavior. Everyday Algorithms What is wrong with the following algorithm? (From the back of a shampoo bottle.) Directions: Wet hair. Apply a small amount of shampoo, lather, rinse, repeat. Algorithms - 1 Basics of Algorithms Chocolate Chip Cookies Ingredients: 2 ¼ cups flour 1 tsp salt 1 tsp baking soda 2 eggs ¾ cup brown sugar 1 tsp vanilla extract ¾ cup granulated sugar 1 cup soft butter 12 oz. semi-sweet chocolate chips Steps: Preheat oven to 375 degrees Combine flour, salt, baking soda, in bowl. Set mixture aside. Combine sugars, butter, vanilla and beat until creamy. Add eggs and beat. Add dry mixture and mix well. Stir in chocolate chips. Drop mixture by teaspoons onto ungreased cookie sheet. Bake 8 to 10 minutes.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
If you follow this algorithm, you will never finish washing your hair! Algorithms in Computing In the realm of computer algorithms, an algorithm is useful only if: The algorithm accepts input data (not all do, however). The algorithm processes that data in some fashion. The algorithm produces some output (the results). However, to be a correct algorithm, it must correctly solve the problem for any valid input data. Also, for the same input data, it must always give the same answer. Invalid input data should produce an error message or some other indication that the algorithm cannot correctly solve the problem. It should not produce an answer when given incorrect data since the user will think that the answer is valid. Successful algorithms must consider all possible cases presented by acceptable data. You will succeed more quickly at constructing algorithms if you make it a habit to: Think about the problem and its data, then Enumerate all the special cases that the algorithm must handle. Describing Algorithms In specifying behavior, an algorithm must be: Precise Unambiguous Complete Correct There are various techniques that can be used to describe algorithms: Natural language (English) Pictures (flow-charts) Pseudocode or a specific programming language Algorithms - 2
Image of page 2
Example – Algorithm Representation Consider an algorithm for registering for classes at UCF. Natural Language Algorithm 1. Make a list of courses you want to register for, in order of priority. 2. Start with an empty schedule. Number of hours = 0. 3. Choose highest priority class on list. 4. If the chosen class is not full and its class time does not conflict with any class already in the schedule, then register for the class: 4a. Add the class to the schedule.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern