Algorithm and complex analysis, Summaries of Data Structures and Algorithms

Algorithm and complex analysis. Data structures

Typology: Summaries

2020/2021

Uploaded on 12/14/2022

ferdinand-madus
ferdinand-madus 🇳🇬

1 document

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSC431: ALGORITHMS AND COMPLEXITY ANALYSIS (2
UNITS)
Principles of good programming style, Expression, and
Documentation, Structured Programming Concepts, Debugging,
Testing, Verifying, Code Inspection, Semantic Analysis, String
Processing, Data Structure. Recursion; Efficiency of algorithm.
Algorithm strategies: Fundamental computing, Numerical,
sequential and binary search trees, hash table, graph and its
representation. Basic algorithmic analysis.
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Algorithm and complex analysis and more Summaries Data Structures and Algorithms in PDF only on Docsity!

CSC431: ALGORITHMS AND COMPLEXITY ANALYSIS (

UNITS)

Principles of good programming style, Expression, and

Documentation, Structured Programming Concepts, Debugging,

Testing, Verifying, Code Inspection, Semantic Analysis, String

Processing, Data Structure. Recursion; Efficiency of algorithm.

Algorithm strategies: Fundamental computing, Numerical,

sequential and binary search trees, hash table, graph and its

representation. Basic algorithmic analysis.

CSC 431

Programming Style Programming style is set of coding rules followed by all the programmers to write the code. It is a set of guidelines used to format programming instructions. When multiple programmers work on the same software project, they frequently need to work with the program code written by some other developer. This becomes tedious or at times impossible, if all developers do not follow some standard programming style to code the program. An appropriate programming style includes using function and variable names relevant to the intended task, using well-placed indentation, commenting code for the convenience of reader and overall presentation of code. This makes the program code readable and understandable by all, which in turn makes debugging and error solving easier. Also, proper coding style helps ease the documentation and updating. Principles of Good Programming Styles Guidelines can be developed from coding conventions used in an organisation with variations of style occurring for different programming languages. Key elements of programming style guide include i. Naming Conventions, ii. Use of Comments iii. Indenting and White Spaces. iv. General Formatting In some languages (e.g. Python), indenting is used to indicate control structures (hence correct indentation is required), whilst in other languages indenting is used to improve the visible appearance and readability of the code (e.g. Java). i. Naming Conventions When naming variables, functions/methods, classes, files etc. it is important to follow a naming convention, and use correct English spelling (this assists with search/find/replace operations). Naming conventions are used to improve visual appearance and reduce the effort needed to read and understand the code. They can vary in different programing languages. The following items are a good guide:

  1. All naming should be descriptive where appropriate.
  2. Avoid abbreviation where possible
  3. Spaces must not be used. Some languages would use dashes for names (e.g. total-height in Lisp), while other languages would use an underscore (e.g. total_height in Python, SQL). Java uses mixed case for variables starting with lowercase e.g. totalHeight.
  4. Constants are usually defined as all uppercase using underscores to separate words. e.g. MAX_HEIGHT. ii. Use of Comments Comments improve program readability. As with naming conventions, it is important to use correct English spelling. Please note that different programming languages allow different commenting styles.
  5. Be consistent with your use of commenting syntax, for example:
  1. // is more readable than:
  2. if (conditionA&&conditionB)
  3. {doSomething;}
  4. else{doNothing;} iv. General Formatting
  5. Keep line lengths to 80 characters or less where appropriate.
  6. Adopt the same formatting conventions as previously written code if adding to or modifying an existing code base.
  7. BE CONSISTENT!

Program Documentation Any written text, illustrations or video that describe a software or program to its users is called program or software document. User can be anyone from a programmer, system analyst and administrator to end user. At various stages of development multiple documents may be created for different users. In modular programming documentation becomes even more important because different modules of the software are developed by different teams. If anyone other than the development team wants to or needs to understand a module, good and detailed documentation will make the task easier. These are some guidelines for creating the documents − ● Documentation should be from the point of view of the reader ● Document should be unambiguous ● There should be no repetition ● Industry standards should be used ● Documents should always be updated ● Any outdated document should be phased out Types of Program Documentation The documentation process starts from the problem analysis phase to debugging and testing. Documentation consists two types of documentation, they are:

  1. Programmer's Documentation
  2. User's Documentation 1. Programmer's Documentation Programmer’s documentation contains all the technical details. Without proper documentation it is very difficult even for the original programmer to update and maintain the program. A programmer’s documentation contains the necessary information that a programmer requires to update and maintain the program. A well-maintained documentation should involve the following documents: ● Requirement documentation - This documentation works as key tool for software designer, developer and the test team to carry out their respective tasks. This document contains all the functional, non-functional and behavioral description of the intended software. Details of this document can include: previously stored data about the software, already running software at the client’s end, client’s interview, questionnaires and research. Generally it is stored in the form of spreadsheet or word processing document with the high-end software management team. This documentation works as foundation for the software to be developed and is majorly used in verification and validation phases. Most test-cases are built directly from requirement documentation. ● Software Design documentation - These documentations contain all the necessary information, which are needed to build the software. It contains: (a) High-level software architecture, (b) Software design details, (c) Data flow diagrams, (d) Database design

Structured Programming In the process of coding, the lines of code keep multiplying, thus, size of the software increases. Gradually, it becomes next to impossible to remember the flow of program, difficult to share, debug and modify the program. The solution to this is structured programming. Structured programming also known as Modular Programming is a subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify. Structured programming frequently employs a top-down design model, in which developers map out the overall program structure into separate subsections. These functions are also known as modules , subprogram , subroutines and procedures. A defined function or set of similar functions is coded in a separate module or submodule, which means that the code can be loaded into memory more efficiently and that modules can be reused in other programs. After a module has been tested individually, it is then integrated with other modules into the overall program structure. Structured programming encourages the developer to use subroutines and loops instead of using simple jumps in the code, thereby bringing clarity in the code and improving its efficiency Structured programming also helps programmer to reduce coding time and organize code properly. A key characteristic of a structured statement is the presence of single entry and single exit point. This characteristic implies that during execution, a structured statement starts from one defined point and terminates at another defined point (there should be an entry and exit point for each module). This is one of the reasons why the Structured Programming Approach is well accepted in the programming world. Structured programming also focuses on reducing the following statements from the program:

  1. GOTO’ statements.
  2. ‘Break’ or ‘Continue’ outside the loops.
  3. Multiple exit points to a function, procedure, or subroutine. For example, multiple ‘Return’ statements should not be used.
  4. Multiple entry points to a function, procedure, or a subroutine. Elements of Structured Programs The structured program mainly consists of three types of elements: ● Sequence Structure : are used for the sequentially executed statements. ● Selection or Decision Structure : are used for conditional execution of statements (‘IF, IF...THEN, IF...THEN…ELSE, CASE construct) ● Iteration or Looping or Repetition Structure : are used for performing some repetitive tasks in the program (WHILE loop, FOR loop , DO WHILE, DO UNTIL loop) Advantages of Structured Programming
  5. It is user friendly and easy to understand.
  6. Similar to English vocabulary of words and symbols.
  7. It is easier to learn.
  1. They require less time to write.
  2. They are easier to maintain.
  3. These are mainly problem oriented rather than machine based.
  4. Program written in a higher level language can be translated into many machine languages and therefore can run on any computer for which there exists an appropriate translator.
  5. It is independent of machine on which it is used i.e. programs developed in high level languages can be run on any computer. Disadvantages of Structured Programming
  6. Since it is Machine-Independent, it takes time to convert into machine code.
  7. The object code generated by a translator might be inefficient compared to an equivalent assembly language program.
  8. The program depends upon changeable factors like data-types. Therefore it needs to be updated with the need on the go.
  9. Usually the development in this approach takes longer time as it is language-dependent. Whereas in the case of assembly language, the development takes lesser time as it is fixed for the machine.

var test var test var average average = test1 + test 2 + test3 / 3 print average When you run the program, you get results that are obviously incorrect. It is not a syntax error as the code can be compiled and run, it is a logic error. What is the logic error? The program is dividing test3 by 3 and then adding it to test1 and test2. Should be (test1 + test2 + test3)/

  1. The student is also having problems with the following code. var first_number As integer var second_number As integer var result As integer result = first_number * second_number He inputs 13.5 as the first number and 3 as the second number but the result is 39 and not 40.5 as he was expecting. What is the logic error? The student has declared all of the variables as integers and so the computer will treat 13.5 as 13. Hence the result is 39. The student should have declared them as variables able to hold decimal numbers e.g. as float or double.
    1. Run Time Error: A runtime error is a program error that occurs while the program is running. Run time error occurs during the execution of program. Common examples of runtime error include dividing by zero, referencing missing files, Stack overflow, floating point error, calling invalid functions, or not handling certain input correctly etc. Example of Run time Error Debugging Process The process of finding bugs or errors and fixing them in any application or software is called debugging. Even after taking full care during program design and coding, some errors may

remain in the program and these errors appear during compilation or linking or execution. Debugging is generally done by program developer. To make the software programs or products bug-free, this process should be done before releasing them into the market. Steps involved in Debugging The steps involved in this process are,

1. Identify the Error: A bad identification of an error can lead to wasted developing time. It is usual that production errors reported by users are hard to interpret and sometimes the information we receive is misleading. It is import to identify the actual error. 2. Find the Error Location: After identifying the error correctly, you need to go through the code to find the exact spot where the error is located. In this stage, you need to focus on finding the error instead of understanding it. 3. Analyze the Error: In the third step, you need to use a bottom-up approach from the error location and analyze the code. This helps you in understanding the error. Analyzing a bug has two main goals, such as checking around the error for other errors to be found, and to make sure about the risks of entering any collateral damage in the fix. 4. Prove the Analysis: Once you are done analyzing the original bug, you need to find a few more errors that may appear on the application. This step is about writing automated tests for these areas with the help of a test framework. 5. Cover Lateral Damage: In this stage, you need to create or gather all the unit tests for the code where you are going to make changes. If you run these unit tests at this stage, they all should pass. 6. Fix & Validate: The final stage is the fix all the errors and run all the test scripts to check if they all pass. Benefits of Debugging Debugging has many benefits such as: ● It reports an error condition immediately. This allows earlier detection of an error and makes the process of software development stress-free and unproblematic. ● It also provides maximum useful information of data structures and allows easy interpretation. ● Debugging assists the developer in reducing useless and distracting information. ● Through debugging the developer can avoid complex one-use testing code to save time and energy in software development. Debugging Strategies ● It is important to study the system in depth in order to understand the system. It helps the debugger to construct different representations of systems that are to be debugged. ● Backward analysis of the problem traces the program backward from the location of failure message in order to identify the region of faulty code. You need to study the region of defect thoroughly to find the cause of defects. ● Forward analysis of the program involves tracking the program forward using breakpoints or print statements at different points in the program. It is important to focus on the region where the wrong outputs are obtained.