1 / 15

Today’s Topics

Today’s Topics. O-Notation Testing/Debugging Data Structures Next Class: Writing correct programs:Column 4. O-Notation. Running times (number of operations) in terms of the input size Best-case, worst-case, expected (average) case

tea
Download Presentation

Today’s Topics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Today’s Topics • O-Notation • Testing/Debugging • Data Structures • Next Class: Writing correct programs:Column 4

  2. O-Notation • Running times (number of operations) in terms of the input size • Best-case, worst-case, expected (average) case • Example: quicksort has worst-case of n2 but best/average case of n log n.

  3. Cases

  4. So what?

  5. Testing/Debugging • Testing – Does my program do what it is supposed to do?? • Debugging – Why does my program do that!!??!!

  6. Testing • Formal discipline • Focus on informal approach • Goal: Make the program fail! • Testing can only show bugs, not verify their absence • Why test? Increase confidence in the correctness of the code

  7. Testing Approaches • Specification based – test input derived from the formal or informal problem description (black box) • Implementation based – test input derived from the structure of the code (white box) • There are hybrid approaches as well

  8. General Testing Strategies • Test incrementally • Test simple parts first • Know what output you expect • Program defensively – check pre- and post- conditions, check cases even if unlikely. • Regression testing – save your test cases

  9. Test Case Strategies • Test at boundaries – empty case, input limit, limit + 1 • Special cases • Classes of inputs • Exercising code • Statement level • Branch (choice level) • Function level

  10. Debugging • Less of a formal discipline – backwards reasoning • When you find a problem (during your incremental testing!): • Look for familiar patterns – Have I seen this bug before? • Examine the most recent change • Look for multiple occurrences of the bug • Debug now, not later • Read the code • Explain the code to someone else

  11. Finding reproducible bugs • Display output • Stack trace • Assertions to check pre and post conditions • Draw a picture • Use a debugger

  12. Non-reproducible bugs • On a given input, sometimes the problem occurs, sometimes not • Uninitialized variables • Memory allocation problems • Dangling pointers • External environment (file characteristics, environment variables,…)

  13. Data Structures • Choice of data structures key to success • Array/matrix • Linked lists • Linked structures – trees, graphs, …

  14. A Node Too Far: Data Structures • Unordered graph – can represent with an array of links per node or a 2D matrix array[30] with name and marker . . . . . . 2D matrix of connections between node i and j . . .

  15. A Node Too Far: Algorithm • For node k and TTL n, DFS from k of length n, marking nodes as visited DFS_to_n(int k, int n){ if (n > 0) { mark node k for (i=0;i<MAX_NODES;++i) if (matrix(k,i) == 1) DFS_to_n(i,n-1) } } • After DFS, count the number of unmarked nodes:

More Related