Pseudocode.docx angel
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Pseudocode.docx angel

on

  • 3,227 views

psuedocode

psuedocode

Statistics

Views

Total Views
3,227
Views on SlideShare
3,227
Embed Views
0

Actions

Likes
1
Downloads
79
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Pseudocode.docx angel Document Transcript

  • 1. PseudocodeFrom Wikipedia, the free encyclopediaJump to: navigation, searchIn computer science and numerical computation, pseudocode is an informal high-leveldescription of the operating principle of a computer program or other algorithm. It uses thestructural conventions of a programming language, but is intended for human reading rather thanmachine reading. Pseudocode typically omits details that are not essential for humanunderstanding of the algorithm, such as variable declarations, system-specific code and somesubroutines. The programming language is augmented with natural language description details,where convenient, or with compact mathematical notation. The purpose of using pseudocode isthat it is easier for people to understand than conventional programming language code, and thatit is an efficient and environment-independent description of the key principles of an algorithm.It is commonly used in textbooks and scientific publications that are documenting variousalgorithms, and also in planning of computer program development, for sketching out thestructure of the program before the actual coding takes place.No standard for pseudocode syntax exists, as a program in pseudocode is not an executableprogram. Pseudocode resembles, but should not be confused with skeleton programs, includingdummy code, which can be compiled without errors. Flowcharts and UML charts can be thoughtof as a graphical alternative to pseudocode, but are more spacious on paper.Contents 1 Application 2 Syntax 3 Mathematical style pseudocode 4 Machine compilation of pseudo-code style languages o 4.1 Natural language grammar in programming languages o 4.2 Mathematical programming languages  4.2.1 Alternative forms of pseudocode 5 See also 6 External linksApplicationTextbooks and scientific publications related to computer science and numerical computationoften use pseudocode in description of algorithms, so that all programmers can understand them,even if they do not all know the same programming languages. In textbooks, there is usually anaccompanying introduction explaining the particular conventions in use. The level of detail ofthe pseudo-code may in some cases approach that of formalized general-purpose languages.
  • 2. A programmer who needs to implement a specific algorithm, especially an unfamiliar one, willoften start with a pseudocode description, and then "translate" that description into the targetprogramming language and modify it to interact correctly with the rest of the program.Programmers may also start a project by sketching out the code in pseudocode on paper beforewriting it in its actual language, as a top-down structuring approach.SyntaxAs the name suggests, pseudocode generally does not actually obey the syntax rules of anyparticular language; there is no systematic standard form, although any particular writer willgenerally borrow style and syntax; for example, control structures from some conventionalprogramming language. Popular syntax sources include Pascal, BASIC, C, C++, Java, Lisp, andALGOL. Variable declarations are typically omitted. Function calls and blocks of code, such ascode contained within a loop, are often replaced by a one-line natural language sentence.Depending on the writer, pseudocode may therefore vary widely in style, from a near-exactimitation of a real programming language at one extreme, to a description approaching formattedprose at the other.This is an example of pseudocode (for the mathematical game bizz buzz):Fortran style pseudo code Pascal style pseudo code C style pseudo code: void function bizzbuzzprogram bizzbuzz procedure bizzbuzz for (i = 1; i<=100; i++)do i = 1 to 100 for i := 1 to 100 do { set print_number to set print_number to set print_number totrue true; true; if i is divisible by if i is divisible by if i is divisible by3 3 then 3 print "Bizz" print "Bizz"; print "Bizz"; set print_number set print_number set print_numberto false to false; to false; if i is divisible by if i is divisible by if i is divisible by5 5 then 5 print "Buzz" print "Buzz"; print "Buzz"; set print_number set print_number set print_numberto false to false; to false; if print_number, if print_number, if print_number,print i print i; print i; print a newline print a newline; print a newline;end do end }See also category: Articles with example pseudocodeMathematical style pseudocodeIn numerical computation, pseudocode often consists of mathematical notation, typically fromset and matrix theory, mixed with the control structures of a conventional programming
  • 3. language, and perhaps also natural language descriptions. This is a compact and often informalnotation that can be understood by a wide range of mathematically trained people, and isfrequently used as a way to describe mathematical algorithms. For example, the sum operator(capital-sigma notation) or the product operator (capital-pi notation) may represent a for loop andperhaps a selection structure in one expression:ReturnNormally non-ASCII typesetting is used for the mathematical equations, for example by meansof TeX or MathML markup, or proprietary formula editors.These are examples of articles that contain mathematical style pseudo code: Algorithm Karmarkars algorithm Conjugate gradient method Particle swarm optimization Ford-Fulkerson algorithm Stone method Gauss–Seidel method Successive over-relaxation Generalized minimal Symbolic Cholesky decomposition residual method Tridiagonal matrix algorithm Jacobi eigenvalue algorithm Jacobi methodMathematical style pseudocode is sometimes referred to as pidgin code, for example pidginALGOL (the origin of the concept), pidgin Fortran, pidgin BASIC, pidgin Pascal, pidgin C, andpidgin Lisp.Machine compilation of pseudo-code style languagesNatural language grammar in programming languagesVarious attempts to bring elements of natural language grammar into computer programminghave produced programming languages such as HyperTalk, Lingo, AppleScript, SQL, Informand to some extent Python. In these languages, parentheses and other special characters arereplaced by prepositions, resulting in quite talkative code. These languages are typicallydynamically typed, meaning that variable declarations and other boilerplate code can be omitted.Such languages may make it easier for a person without knowledge about the language tounderstand the code and perhaps also to learn the language. However, the similarity to naturallanguage is usually more cosmetic than genuine. The syntax rules may be just as strict andformal as in conventional programming, and do not necessarily make development of theprograms easier.Mathematical programming languages
  • 4. An alternative to using mathematical pseudocode (involving set theory notation or matrixoperations) for documentation of algorithms is to use a formal mathematical programminglanguage that is a mix of non-ASCII mathematical notation and program control structures. Thenthe code can be parsed and interpreted by a machine.Several formal specification languages include set theory notation using special characters.Examples are: Z notation Vienna Development Method Specification Language (VDM-SL).Some array programming languages include vectorized expressions and matrix operations asnon-ASCII formulas, mixed with conventional control structures. Examples are: A programming language (APL), and its dialects APLX and A+. Pseudocode Examples An algorithm is a procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed. An algorithm is merely the sequence of steps taken to solve a problem. The steps are normally "sequence," "selection, " "iteration," and a case-type statement. In C, "sequence statements" are imperatives. The "selection" is the "if then else" statement, and the iteration is satisfied by a number of statements, such as the "while," " do," and the "for," while the case-type statement is satisfied by the "switch" statement. Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are reasonably straightforward. All statements showing "dependency" are to be indented. These include while, do, for, if, switch. Examples below will illustrate this notion. What is pseudocode? Pseudocode consists of short, English phrases used to explain specific tasks within a programs algorithm. Pseudocode should not include keywords in any specific computer languages. It should be written as a list of consecutive phrases. You should not use flowcharting symbols but you can draw arrows to show looping processes. Indentation can be used to show the logic in pseudocode as well. For example, a first-year, 9th grade Visual Basic programmer should be able to read and understand the pseudocode written by a 12th grade AP Data Structures student. In fact, the VB programmer could take the other students pseudocode and generate a VB program based on that pseudocode. Why is pseudocode necessary? The programming process is a complicated one. You must first understand the program specifications, of course, Then you need to organize your thoughts and create the program. This is a difficult task when the program is not trivial (i.e. easy). You must break the main tasks that must be accomplished into smaller ones in order to be able to eventually write fully developed code. Writing pseudocode WILL save you time later during the construction & testing phase of a programs development.
  • 5. How do I write pseudocode?First you may want to make a list of the main tasks that must be accomplished on a pieceof scratch paper. Then, focus on each of those tasks. Generally, you should try to breakeach main task down into very small tasks that can each be explained with a short phrase.There may eventually be a one-to-one correlation between the lines of pseudocode andthe lines of the code that you write after you have finished pseudocoding.It is not necessary in pseudocode to mention the need to declare variables. It is wisehowever to show the initialization of variables. You can use variable names inpseudocode but it is not necessary to be that specific. The word "Display" is used in someof the examples. This is usually general enough but if the task of printing to a printer, forexample, is algorithmically different from printing to the screen, you may make mentionof this in the pseudocode. You may show functions and procedures within pseudocodebut this is not always necessary either. Overall, remember that the purpose of pseudocodeis to help the programmer efficiently write code. Therefore, you must honestly attempt toadd enough detail and analysis to the pseudocode. In the professional programmingworld, workers who write pseudocode are often not the same people that write the actualcode for a program. In fact, sometimes the person who writes the pseudocode does notknow beforehand what programming language will be used to eventually write theprogram.Example:Original Program Specification:Write a program that obtains two integer numbers from the user. It will print out the sumof those numbers.Pseudocode:Prompt the user to enter the first integerPrompt the user to enter a second integerCompute the sum of the two user inputsDisplay an output prompt that explains the answer as the sumDisplay the resultUse this template when typing your pseudocode into MS Word: