Saturday, May 14, 2016
Sunday, March 13, 2016
Stress Testing: the [Almost] Silver Bullet for Debugging | Coursera
- It is very important to write programs that work correctly on all the allowed inputs.
- Testing is essential to writing correct programs.
- First test on a few small manual tests, then test for each type of answer, then test on large test cases for time limit and memory limit, then test on corner cases.
- After that, apply stress testing to ensure your program works - it will almost always lead to correct solution. You can do it before your first attempt to submit your solution - and will often get it right from the first attempt!
- Stress testing consists of implementing the intended solution, another simple possible slow solution, a test generator and an infinite loop which generates tests and compares answers of the two solutions.
- Always try to find the smallest test cases on which your solution fails.
- Try different regions of the test space when generating cases for stress testing.
Saturday, March 12, 2016
Saturday, February 27, 2016
Heapsort Algorythm
procedure heapsort(a, count) is input: an unordered array a of length count (Build the heap in array a so that largest value is at the root) heapify(a, count) (The following loop maintains the invariants that a[0:end] is a heap and every element beyond end is greater than everything before it (so a[end:count] is in sorted order)) end ← count - 1 while end > 0 do (a[0] is the root and largest value. The swap moves it in front of the sorted elements.) swap(a[end], a[0]) (the heap size is reduced by one) end ← end - 1 (the swap ruined the heap property, so restore it) siftDown(a, 0, end)
(Put elements of 'a' in heap order, in-place) procedure heapify(a, count) is (start is assigned the index in 'a' of the last parent node) (the last element in a 0-based array is at index count-1; find the parent of that element) start ← iParent(count-1) while start ≥ 0 do (sift down the node at index 'start' to the proper place such that all nodes below the start index are in heap order) siftDown(a, start, count - 1) (go to the next parent node) start ← start - 1 (after sifting down the root all nodes/elements are in heap order) (Repair the heap whose root element is at index 'start', assuming the heaps rooted at its children are valid) procedure siftDown(a, start, end) is root ← start while iLeftChild(root) ≤ end do (While the root has at least one child) child ← iLeftChild(root) (Left child of root) swap ← root (Keeps track of child to swap with) if a[swap] < a[child] swap ← child (If there is a right child and that child is greater) if child+1 ≤ end and a[swap] < a[child+1] swap ← child + 1 if swap = root (The root holds the largest element. Since we assume the heaps rooted at the children are valid, this means that we are done.) return else swap(a[root], a[swap]) root ← swap (repeat to continue sifting down the child now)
Depth-first search - Wikipedia, the free encyclopedia
Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. One starts at the root(selecting some arbitrary node as the root in the case of a graph) and explores as far as possible along each branch beforebacktracking.
A recursive implementation of DFS:[5]
1 procedure DFS(G,v): 2 label v as discovered 3 for all edges from v to w in G.adjacentEdges(v) do 4 if vertex w is not labeled as discovered then 5 recursively call DFS(G,w)
A non-recursive implementation of DFS:[6]
1 procedure DFS-iterative(G,v): 2 let S be a stack 3 S.push(v) 4 while S is not empty 5 v = S.pop() 6 if v is not labeled as discovered: 7 label v as discovered 8 for all edges from v to w in G.adjacentEdges(v) do 9 S.push(w)
Sunday, January 24, 2016
Saturday, January 9, 2016
Robustness (computer science)
Robustness (computer science) - Wikipedia, the free encyclopedia: "In computer science, robustness is the ability of a computer system to cope with errors during execution. Robustness can also be defined as the ability of an algorithm to continue operating despite abnormalities in input, calculations, etc.
Subscribe to:
Posts (Atom)