Cracking the Coding Interview

Slides:



Advertisements
Similar presentations
Programming Types of Testing.
Advertisements

Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3.
Debugging Introduction to Computing Science and Programming I.
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Group practice in problem design and problem solving
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
General Programming Introduction to Computing Science and Programming I.
Testing Michael Ernst CSE 140 University of Washington.
Testing CSE 140 University of Washington 1. Testing Programming to analyze data is powerful It’s useless if the results are not correct Correctness is.
Program Development Life Cycle (PDLC)
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
Introduction to Exception Handling and Defensive Programming.
C++ crash course Class 8 statements, sort, flight times program.
# ACS 168 Structured Programming Using the Computer Chapter 2 Spring 2002 Prepared by Shirley White.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Course A201: Introduction to Programming 09/16/2010.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
Controlling Program Flow with Decision Structures.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
Few More Math Operators
Last week: We talked about: History of C Compiler for C programming
Introduction to Computing Science and Programming I
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Whatcha doin'? Aims: To start using Python. To understand loops.
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Introduction to Python
Copyright © 2008 by Helene G. Kershner
Testing and Debugging.
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Debugging and Random Numbers
Copyright © 2008 by Helene G. Kershner
CSS 161: Fundamentals of Computing
CS 240 – Lecture 11 Pseudocode.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Problem Solving (design of programs) CS140: Introduction to Computing 1 8/26/13.
Testing UW CSE 160 Spring 2018.
CSE341: Programming Languages Section 1
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Testing UW CSE 160 Winter 2016.
CSE341: Programming Languages Section 1
Cracking the Coding Interview
T. Jumana Abu Shmais – AOU - Riyadh
CSCE 489- Problem Solving Programming Strategies Spring 2018
Coding Concepts (Standards and Testing)
Programming Errors Key Revision Points.
Programming.
Training & Development
Programming Fundamentals (750113) Ch1. Problem Solving
Software Development Process
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
Flowcharts and Pseudo Code
Programming Fundamentals (750113) Ch1. Problem Solving
An Introduction to Debugging
Review of Previous Lesson
Chapter 15 Debugging.
Software Development Techniques
CHAPTER 6 Testing and Debugging.
Chapter 15 Debugging.
Presentation transcript:

Cracking the Coding Interview Diego Aguirre

Problem Solving IDEAL is nice and helpful, but is that all we need to solve hard programming problems? What’s missing?

Problem Solving Remember the E in IDEAL?

Problem Solving Explore possible strategies or solutions Nice…, but HOW? It would be nice to have a sub-framework here for coding problems

Problem Solving If we were to come up with a framework to solve coding questions, what MUST be in it? Teams … Discuss

Duke’s 7 steps

I D E A L Source: The IDEAL Problem Solver

Duke’s 7 steps There is a huge gap! How do we approach it? With practice, everything is going to feel more natural

Duke’s 7 steps Step 1 … Any guesses?

Duke’s 7 steps Step 1: Work some small instances by hand Remember the TwoSum problem? String representation problem? hello -> h3o problem -> p5m solving -> s5g

Duke’s 7 steps Step 1: Work some small instances by hand Unclear problem? Ask clarification questions!

Duke’s 7 steps Step 1: Work some small instances by hand What if you are doing a simulation? … and you need to know some physics? Get all the external/domain knowledge you need

Duke’s 7 steps Step 2: Write down what you did You don’t have to solve the general problem Write down the steps you followed to solve the small instances of the problem

Duke’s 7 steps Step 2: Write down what you did Tricky part/potential pitfall: We, humans, do a lot of things without really thinking about them consciously. We just naturally do them… Chess vs. Go? Can you come up with some examples of this?

Duke’s 7 steps Step 2: Write down what you did Tricky part/potential pitfall: The computer doesn’t have common sense… We have to be super specific

Duke’s 7 steps Step 3: Find Patterns Look at the steps we wrote in step 2 and find patterns Repetition -> loops Conditions -> if statements / case analysis? Do we need to store the data? Access it? Manipulate it? -> data structures Generalize and write down the algorithm that solves the general problem

Duke’s 7 steps Step 3: Find Patterns If this is too difficult, go back to steps 1 and 2. Remember, building an algorithm is like building a house, you need to know what tools are available and how to use them. Solving a lot of other problems will help you solve new ones!

Duke’s 7 steps Step 3: Find Patterns Similar patters appear in many different programming questions (even though they might seem very different to each other at the beginning).

Duke’s 7 steps Step 4: Check by hand We now have an algorithm to solve the general problem Trace it using some small instances of the problem Some people can do this in their heads for simple algorithms. If you can’t, that’s fine, take a piece of paper and trace it there. Excellent problem solvers have excellent tracing skills… You might think that tracing is not that important, but it’s extremely important! You DON’T HAVE to do everything in your head. We have limited short-term memory, use a whiteboard / piece of paper, etc The more you do this, the easier it will become to visualize/understand algorithms

Duke’s 7 steps Step 5: Translate to Code Confident in your algorithm, translate it to code Code depends on programming language, so make sure you know how to translate the algorithm to that language. If you don’t know something (syntax), Google it! Then…. Execute it multiple times! Use interesting inputs

Duke’s 7 steps Step 6: Run Test Cases Execute it multiple times! Use interesting inputs How do we pick interesting inputs? Teams... Discuss..

Duke’s 7 steps Step 6: Run Test Cases Execute it multiple times! Use interesting inputs How do we pick interesting inputs? Try to break your own code! Think about edge cases

Duke’s 7 steps Step 7: Debug Failed Test Cases How do you debug code? Teams… discuss..

Duke’s 7 steps Step 7: Debug Failed Test Cases Apply scientific method

Duke’s 7 steps Step 7: Debug Failed Test Cases What types of problems can cause a program to crash/fail? Let’s try to generalize and group the types of errors we have encountered Teams… Discuss..

Duke’s 7 steps Step 7: Debug Failed Test Cases Syntax errors Runtime errors Logical errors

Duke’s 7 steps Step 7: Debug Failed Test Cases Syntax errors Runtime errors Logical errors

Duke’s 7 steps Step 7: Debug Failed Test Cases Syntax errors leaving out a keyword putting a keyword in the wrong place leaving out a symbol, such as a colon, comma or brackets misspelling a keyword incorrect indentation empty block

Duke’s 7 steps Step 7: Debug Failed Test Cases Runtime errors a problem which was not detected when the program was parsed, but is only revealed when a particular line is executed. When a program comes to a halt because of a runtime error, we say that it has crashed.

Duke’s 7 steps Step 7: Debug Failed Test Cases Runtime errors division by zero performing an operation on incompatible types using an identifier which has not been defined accessing a list element, dictionary value or object attribute which doesn’t exist trying to access a file which doesn’t exist

Duke’s 7 steps Step 7: Debug Failed Test Cases Logical Errors Most difficult to fix. The program runs without crashing, but produces an incorrect result. Error in the program’s logic

Duke’s 7 steps Step 7: Debug Failed Test Cases Logical Errors using the wrong variable name indenting a block to the wrong level using integer division instead of floating-point division getting operator precedence wrong making a mistake in a boolean expression off-by-one, and other numerical errors

Duke’s 7 steps Step 7: Debug Failed Test Cases Syntax or Runtime error -> Back to Step 5 Logical error -> Back to Step 3