Table of Contents ALGORITHM

Table of Contents ALGORITHM

Table of Contents ALGORITHM .................................................................................................................................................. 1 Expressing algorithms ............................................................................................................................... 2 Symbols ..................................................................................................................................................... 2 PROGRAM STRUCTURE IN PASCAL PROGRAMMING .................................................................................... 4 Program Structure .................................................................................................................................... 4 Comments ................................................................................................................................................. 5 Punctuation ............................................................................................................................................... 6 Indentation ............................................................................................................................................... 6 IDENTIFIERS ................................................................................................................................................... 6 CONSTANTS ................................................................................................................................................... 7 VARIABLES AND DATA TYPES ........................................................................................................................ 8 ASSIGNMENT AND OPERATIONS .................................................................................................................. 9 DATA TYPES ................................................................................................................................................. 12 Ordinal type ............................................................................................................................................ 12 Integer ................................................................................................................................................. 12 Boolean ............................................................................................................................................... 12 Char ..................................................................................................................................................... 12 Real Type ................................................................................................................................................. 13 String ....................................................................................................................................................... 13 INPUT .......................................................................................................................................................... 15 OUTPUT ....................................................................................................................................................... 16 Formatting Output .................................................................................................................................. 17 STANDARD FUNCTIONS .............................................................................................................................. 17 MAKING DECISIONS .................................................................................................................................... 21 IF THEN .................................................................................................................................................... 21 IF THEN ELSE ........................................................................................................................................... 22 NESTED IF ................................................................................................................................................ 23 Logical Operators and Boolean Expressions ........................................................................................... 23 CASE OF ................................................................................................................................................... 26 LOOPS .......................................................................................................................................................... 29 FOR..DO ................................................................................................................................................... 30 WHILE..DO ............................................................................................................................................... 32 REPEAT..UNTIL ........................................................................................................................................ 33 ONE-DIMENSIONAL ARRAYS ....................................................................................................................... 34 Sorting arrays .......................................................................................................................................... 35 TWO DIMENSIONAL ARRAYS ...................................................................................................................... 36 ENUMERATED DATA TYPES ......................................................................................................................... 37 SUBRANGES................................................................................................................................................. 39 RECORDS ..................................................................................................................................................... 40 PROCEDURES ............................................................................................................................................... 42 Global and Local variables ...................................................................................................................... 44 Using Procedures with Parameters ........................................................................................................ 45 The Variable Parameter .......................................................................................................................... 46 FUNCTIONS ................................................................................................................................................. 46 REFERENCE: ................................................................................................................................................. 48 ALGORITHM An algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem. The word derives from the name of the mathematician, Mohammed ibn-Musa al-Khwarizmi, who was part of the royal court in Baghdad and who lived from about 780 to 850. Al-Khwarizmi's work is the likely source for the word algebra as well. In mathematics and computer science, an algorithm usually means a small procedure that solves a recurrent problem. To make a computer do anything, you have to write a computer program. A computer program can be viewed as an elaborate algorithm. To write a computer program, you have to tell the computer, step by step, exactly what you want it to do. The computer then "executes" the program, following each step mechanically, to accomplish the end goal. When you are telling the computer what to do, you also get to choose how it's going to do it. That's where computer algorithms come in. The algorithm is the basic technique used to get the job done. Let's follow an example to help get an understanding of the algorithm concept. Let's say that you have a friend arriving at the airport , and your friend needs to get from the airport to your house. Here are four different algorithms that you might give your friend for getting to your home: • The taxi algorithm : – Go to the taxi stand. – Get in a taxi. – Give the driver my address. • The call-me algorithm : – When your plane arrives, call my cell phone . – Meet me outside baggage claim . • The rent-a-car algorithm : – Take the shuttle to the rental car place. – Rent a car. – Follow the directions to get to my house. • The bus algorithm : – Outside baggage claim, catch bus number 70. – Transfer to bus 14 on Main Street. – Get off on Elm street. – Walk two blocks north to my house. All four of these algorithms accomplish exactly the same goal, but each algorithm does it in completely different way. Each algorithm also has a different cost and a different travel time. Taking a taxi, for example, is probably the fastest way, but also the most expensive. 1 Taking the bus is definitely less expensive, but a whole lot slower. You choose the algorithm based on the circumstances. In computer programming, there are often many different ways -- algorithms -- to accomplish any given task. Each algorithm has advantages and disadvantages in different situations. Sorting is one place where a lot of research has been done, because computers spend a lot of time sorting lists. Here are five different algorithms that are used in sorting: • Bin sort • Merge sort • Bubble sort • Shell sort • Quicksort If you have a million integer

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    49 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us