Skip to content

Instantly share code, notes, and snippets.

View OmarMalik's full-sized avatar

Omar Malik OmarMalik

  • Gainesville, VA
View GitHub Profile

Pop Quiz 1

Question: Give an example of a trade off between reliability and cost of execution.
Answer:

  • Exception handling - You sacrifice cost of execution by enabling exception handling but increase program reliability, particularly important in the case of embedded systems.
  • Recursive methods - Recursive methods may often be more reliable than iterative methods, but you will sometimes sacrifice performance using a recursive method as there can be much more overhead involved in pushing multiple method calls to the runtime stack.
  • Dynamic typing - Utilizing dynamic type checking will favor the cost of execution but sacrifice reliability if the program runs into a type check error during runtime.
  • Array bounds - Bound checking on arrays. If the bounds are checked invalid memory accesses can be caught but slow down execution time (it has to check the bounds for every access to the array).

Pop Quiz 2

int main(int argc, char **argv)
{
int listenfd, port;
char * root = NULL;
int opt;
while ((opt = getopt(argc, argv, "p:R:")) > 0)
{
switch(opt)
{
@OmarMalik
OmarMalik / flood.java
Created April 30, 2019 15:26
omar's flood fill
class Solution {
public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
boolean[][] visited = new boolean[image.length][image[0].length];
Queue<Point> q = new ArrayDeque<Point>();
q.add(new Point(sr, sc));
visited[sr][sc] = true;
while (!q.isEmpty()) {
Point curr = q.remove();