Download presentation
Presentation is loading. Please wait.
Published byAlfred Armstrong Modified over 9 years ago
1
Pseudocode Guidelines for Writing Algorithms High-level description: –Begin with an English description of how the algorithm works. –Include a general overview of the approach and goals. –You may want to include examples and diagrams of the data structures that help make the operation of the algorithm more clear. –For recursive algorithms it is often useful to clearly describe the base and inductive cases that make the algorithm correct. –About one or two paragraphs of text is usually enough.
2
Language and Syntax Follow basic C and/or C++ syntax. –Dynamically created structures should be allocated using "new" and deallocated using "delete". –Avoid the use of advanced C++ features like iterators, templates, class inheritance, etc. –Do not rely on pre-defined classes from the Weiss book unless that is part of the assignment (as it was in the case of hw #1).
3
Functions and Operators You may assume that you have at your disposal the basic operations of the data type you are manipulating. Introduce definitions for the relational operators applied to non-numeric types. –For example: Define (F < G) for nodes F and G to hold iff (F.data < G.data) This should be done only to clarify, never to obscure, the presentation.
4
Additional Tips Include meaningful comments in the body of the pseudocode. Try to make the program as succinct and elegant as you can. This is not only good style but usually makes the algorithm easier for others to understand. Pseudocode should be typed (preferred) or VERY neatly handwritten.
5
Lists and writing pseudocode Given 2 sorted lists, L 1 and L 2, write a procedure to compute L 1 U L 2 (the union of the two lists). The resulting list should be sorted as well.
6
Recursive Algorithms Provide a recursive algorithm that given a binary tree determines the number of leaves in the tree.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.