Computer Science: Data Structures and Algorithms
Discuss Typescript Features
"Typescript is javascript for application-scale development" Typescript is a superset of Javascript; strongly typed, object oriented, compiled language.
Whats the difference between var, let, and const?
"var" is an ES5 declaration "let" and "const" came around with ES6. Take this code: var greeter = "hey hi"; var times = 4; if (times > 3) { var greeter = "say Hello instead"; } console.log(greeter) //"say Hello instead" This won't "say hello instead" because you can't redefine greeter.
Name and describe all the types of joins (5 main types) (+2 uncommon types of joins)
*Outer join*: selects the rows that do not have a common element *Full join*: return all rows of all tables in the joins *Inner join*: select the rows that have a common element in both tables. *Left join*: returns everything from the left table and only the matching elements from the right table *Right join*: returns everything from the right table and only the matching elements from the left table. uncommon: *Cross join*: When everything matches to everything on another table. The num of rows in the first table is multiplied by the num of rows in the second table if no WHERE clause is used. *Self join*: used in one-to-many relationships; table of all employees and you wanted to map employees and their supervisors, you'd need to use self.join
Data Structures: Name 4 typical methods for Queues
*enqueue(item)* adds item AKA *push* *dequeue()* removes item AKA *pop* *peek()* look at the oldest item without "completing" it *is_empty()* boolean You can add any method within a queue, but you'll need to know the runtime for those methods
Iterating in Javascript:
*for statement* (var step; for (let step = 0; step < 5; step++) { // Runs 5 times, with values of step 0 through 4.) *do...while statement* (var i = 0; do { i += 1; console.log(i); } while (i < 5);) *while statement* var n = 0; var x = 0; while (n < 3) { n++; x += n; } *labeled statement* markLoop: while (theMark == true) { doSomething(); } *break statement* for (var i = 0; i < a.length; i++) { if (a[i] == theValue) { break; } } *continue statement* while (i < 5) { i++; if (i == 3) { continue; } *for...in statement* (will log the index position of each item in an array) for (variable in object) statement *for...of statement* (will log the value of each item in the array) for (variable of object) statement
Data Structures: Name 4 typical methods for Stacks
*push(item)* adds item *pop()* removes item *peek()* look at the next item without removing it *is_empty()* boolean
Give a few examples of how Javascript can be used
- Client side validation - Dynamic dropdowns - Displaying and manipulating date and time (with libraries) - Accessing form information - Displaying popup windows and dialog boxes - If you add a string to ints, it will return a string of those ints (concatenation) "1" + 2+ 3 = 123 - If you add an int to string, it will return a mix of arithmetic and concatenation 1+2+"5" = 35
Discuss Python Features
- Interpreted language - Object-Oriented language - Dynamic - High Level
Data Structures: Discuss Stacks and Queues in comparison to Lists
- Stacks and Queues are collections of data - They're ordered (like lists) - They're restricted, which is helpful for clarity and efficiency, but allow fewer operations than lists (ex: if you want to dequeue from the front, using a list is not an O(1) operation like it is with a queue)
name two common uses for closures
-> Closures are commonly used to give objects data privacy. Data privacy is an essential property that helps us program to an interface, not an implementation. (helps us build more robust software because implementation details are more likely to change in breaking ways than interface contracts) -> Closures can also be used to create stateful functions whose return values may be influenced by their internal state
Computer Science: Discuss Object Oriented Programming. What does it mean? What are the benefits?
1. Modularity for easier troubleshooting (modular structure) 2. Reuse of code through inheritance (reuse and maintenance) 3. Flexibility through polymorphism (easily adapted and modified by the programmer.) 4. Faster development, better productivity.
Design Question: 'How would you design a Hotel Reservation website?'
1. start with functionality/ info we will need of website: - *hotel* (name, address, id) - *location* (city, state, street name, landmark) - *room* (room type, room ID, hotel ID, status (free/booked)) - *user* (name, payment type, email, DOB, mobile number) - *payments* (type details, payment status(paid, pending, etc) - *facilities* (features, pool, WiFi) - *duration* ( checkin, booked, checkout) - *bookings* (booking ID, user ID, hotel ID) 2. Step into the intricacies - Once a user "adds to cart", only make that unavailable for 20 mins. (next web request should be made before then to actually book the hotel) 3. Confirmation and removing from the database
(Might require pen/paper) Using the Python implementation of Quick Sort from the instructions: Given the list [8, 4, 1, 6, 5, 2, 7, 3]: When this function is initially called, what is the value of pivot?
5
6. What is the difference between a tree and a graph?
A tree is a restricted kind of graph where there are no loops or cycles.
Explain-This: What is a web request? (What's in them? Be able to explain HTML, DOM, and JS)
A web request is initiated when a client's browser uses a URL to identify an IP address. From there, the browser establishes a connection with the web server- ...skipping the passing of data...- when data is passed from the server to the client's browser, an HTML page can become a document object model (a tree-like structure that expresses nodes, their attributes, and containment of nested nodes). This nested node structure allows you to intertwine Javascript and HTML within <script /> tags. Javascript allows for Event Driven Programming (adding event listeners: clicks, hovers, keyboard presses, etc)
Doubly Linked List: advantage, disadvantage
Advantage: quick insert to beginning, quick removal from end Disadvantage: slow search, not great for indexing
Explain finding things in trees. Name the two approaches, the data structures they use. Give an example of a tree.
Approaches: Breadth First Search & Depth First Search BFS: Queues (find the highest ranking- think like a family tree, find the first "Mary"); Will use pop(0) DFS: Stacks (find all possible combinations with one particular kind of coin first) Will use pop() method to check each node. File systems could be an example of a tree.
Explain how an AJAX request is used, how does it work and how does it handle a-synchronicity?
Asynchronous JavaScript and XML AJAX is a technology for sending requests and receiving responses from a server without having to reload the browser page. Perks: - Don't need to reload the entire page if just 1 thing is changing - Great for Interactive web sites - Fewer "round-trips" to server - Your JS can talk to other servers directly - Less load on your server (since you're not reloading the whole page)
Explain Breadth First Search (data structure, how searching works, runtime, and an example of when you'd use it)
BFS uses queues to search through nodes starting at the top of the tree (closest to the root). When you eliminate a node, you pop from the front of the list and append to the end. Runtime is O(log n) EX: searching for the first family member in your genealogy named "Mary"
Explain how the Internet works:
Background: The internet refers to an *inter*connected *net*work of computers. Some computers are web servers (they contain and serve content from websites) and some are client devices (laptops, tablets, mobile phones). Web servers are connected to each other via fiberoptic cables which transmit data to each other. Each web server has a unique *ip address* Answer: Client device uses a browser to create a web request by typing in a URL (uniform resource locator). Browser uses a DNS (domain name service) to match a URL to an IP address. Browser tries to open an socket connection with that IP. If fails, 404 error. If works, web request from browser is broken up into packets of data and transmitted via routers to the server's IP address. Once there, it's assembled and server generates the response. In compliance with HTTP protocol, response is again broken into packets of data and returned to the browser via routers. The browser then assembles the HTML, CSS, JavaScript, and img files that the user sees.
Explain Binary Search (give an example of when to use it)
Binary search only works when items in an array are sorted. To use it, find the min and max bounds to find the mid point: min = list[0] max = list[-1] midpoint = round((max + min) / 2)
CSS Animations
CSS- make animations between a set of starting property values and a final rather than between two states. Two components: style describing the CSS animation and a set of key frames that indicate the start and end states of the animation's style.
Explain-This: What is a server? What is a client? How do they interact?
Client: the browser that's viewing a website. (Google Chrome) Server: the host of the website. (AHYO- AWS) In a web request, the client makes a request via a browser to a server. The server will then send back data via the browser to the client. OR Website scripts can run in one of two places. Client side: Front-end; Javascript; It runs scripts on your computer AFTER you've loaded a webpage. Ideal for websites with lots of user interaction; ex: simple game. Server side: Back-end; Scripts are run not on your computer, but on the server which hosts the website and sends down the HTML code. Ideal for websites with dynamic data to be loaded; ex: notifications to tell a user they're logged in. Most websites will require a mix of both.
Goals of coding conventions (3 goals)
Consistency Readability Maintainability camelCase Indentation
Data Modeling: Terminology: Primary Key
Creates referential integrity. Every entry in a database must have a primary key.
Data Modeling: Terminology: Foreign Key
Creates referential integrity. You can't add something else to the table if it doesn't first exist in the table with the primary key. (EX: every home price had to have a corresponding city/state primary key)
Explain Depth First Search (data structure, how searching works, runtime, and an example of when you'd use it)
DFS uses stacks to search through nodes starting at the top of the tree (closest to the root). When you eliminate a node, you pop from the end of the list and append to the end. You use up all options before moving to the next. Runtime is O(n) (JBS TO CONFIRM) EX: searching for all possible combinations of coins that could make change for $0.99.
What is "Hoisted" in Javascript
Declaring a variable without assigning it value. Declaration is hoisted, but the value is undefined ex: var currentJob;
ES 5 vs ES 6
ES6 introduced: -Default Parameters -Rest and Spread Parameters -Template Literals -Multi-line Strings -Destructuring Assignment -Enhanced Object Literals -Arrow Functions -Promises -Block-Scoped Constructs: Let and Const -Classes -Modules -For...Of Comprehensions
Data Structures: Discuss characteristics of Recursion
Enables developers to develop straightforward and simple solutions to difficult problems by writing functions that call themselves until they reach a stopping point. Will always need a base case and a recursive case
Data Structures: Discuss characteristics of a Queue Give an example of when you would use this data structure
Enqueueing: Items are only added to the end Dequeuing: Items are only removed from the front *FIFO* Example of when you would use this data structure: Deli line _well build queues are not storable_
Data Modeling: Describe relationships: 1-to-many Give an example
Example: Shipping address to User email, credit card numbers associated with a SSN
Data Modeling: Describe relationships: 1-to-1 Give an example
Example: UserID to email address, Phone number to account (think Scoot)
Why is looking up, adding, and removing elements from a dictionary or hash map an O(1) operation?
Hash maps are built upon arrays: keys entered into a dictionary/hash map are hashed first to find where the key/value pair should be stored. This position is unique and can be used for fast lookups, as well as insertions and deletions. When searching in a regular list, Python iterates over the list to see if a given value is in the list -- this is an O(n) operation. When looking to see if a value is in a hash table, Python hashes the value that's sought and can go immediately to that position in the array to see if there is a value there. That process of hashing and indexing is an O(1) operation. Similarly, as every item in a hash map has a unique position, adding or inserting items does not require that eery other item shift index position; an items' position is not dependent on other items in the array.
Data Modeling: Describe relationships: many-to-many Give an example
High school: many teachers have many students, those students have many teachers
Data Structures: Discuss characteristics of a Classes, Class Inheritance
In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods)
Indexing into a database
Indexing is a way to optimize the performance of a database by minimizing the number of disk accesses required when a query is processed. It is a data structure technique which is used to quickly locate and access the data in a database Will use a search key and a data reference (point in memory)
Name 3 O(1) operations on Lists
Indexing, Appending (to the end), Removing(from the end)/ popping
Debugging in Javascript
Inspect the browser use console.log() use document.write() try...catch- implements error handling
Explain Arrow functions
Introduced in ES 6 In Arrow Functions, the "this" keyword represents the object that owns the function, no matter who calls the function. *Before: * hello = function() { return "Hello World!"; } *After:* hello = () => { return "Hello World!"; } *Optimized: if there is only one arg passed in:* hello = () => "Hello World!"; *With an arg:* hello = (val) => "Hello " + val;
Data Structures: Discuss characteristics of a Stack Give an example of when you would use this data structure
Items added to end (pushing) Items are only removed from the end (popping) *LIFO* (last in, first out) Example of when you would use this data structure: "undo" button, Error Tracebacks show call stacks (think pancakes)
Top 3 characteristics of Lists
Iterable, Ordered, Mutable (can be modified)
Explain Jasmine tests (give an example of when to use it)
JavaScript Unit Tests
Discuss Javascript Features (7)
Javascript Features: - Interpreted - Object oriented (it supports inheritance through prototyping) - High level Dynamic - weakly typed - prototype-based and multi-paradigm(paradigm is a model). - Is a client side language, giving the user more control over the browser : - Does not allow the reading or writing of files
Memory in Javascript
Javascript is a high level language, so it uses an automatic process to release memory called Garbage collection. What determines if something is garbage collected or not is the references to it. If for example you have a variable that is never referenced, or not referenced anymore, it will be garbage collected.
Explain Selenium (give an example of when to use it)
Like a player piano for your web site. "End-to-End" Testing Drives a real web browser through your app Not a simulation! Good for proving that your UI functions(!) eg, does this jQuery binding work?
Data Structures: Discuss characteristics of a Singly Linked List
Linked Lists: can have only 0 or 1 child; acyclic and directed
Compare Linked Lists, Trees, and Graphs. Specifically, discuss cycles, direction, and children
Linked Lists: can have only 0 or 1 child; acyclic and directed Trees: 0+ children; acyclic and directed; only one designated root node Graphs: 0+ connections; cyclic or acyclic; directed or undirected; disconnected or connected; optional weights
What's the runtime for Selection Sort?
O (n^2) (very bad)
What's the runtime for Heap Sort?
O(n log n) (okay)
What's the runtime for Merge Sort?
O(n log n) (okay) particularly good when number of items being sorted increases
What's the runtime for Shell Sort?
O(n log n) (okay);
What's the runtime for Tree Sort?
O(n log n) (okay);
What's the runtime for Quick Sort?
O(n log n) (okay); worst case O(n^2)
What's the runtime for Cube Sort?
O(n)
What's the runtime for TimSort?
O(n) (fair); worst case O(n log n) (okay)
What's the runtime for Bubble Sort?
O(n^2) (very bad); best case O(n)
What's the runtime for Insertion Sort?
O(n^2) (very bad); best case O(n). Its good when the number of items being sorted is small, but as N grows, runtime slows dramatically.
Explain why removing elements from or adding elements to an arbitrary location in a Python list are O(n) operations.
Python lists are contiguous in memory. When an item is removed or added to the middle of a list, all the subsequent items in the list must be shifted either up or down by one position
Explain Functional Tests (give an example of when to use it)
Python: Good for testing "flow" of server-side code eg, can a user login to site and see their content?
Explain Unit Tests (give an example of when to use it)
Python: Good for testing individual code units eg, a function, method, or class instance Javascript: Good for testing components of JS eg, you have lots of JS broken into pieces
Explain Merge Sort (give an example of when to use it)
Runtime: O(n log n) - Start with two sorted lists/ if not possible, break each list into a single item. - Initialize new, empty list for results - Compare first element of each sorted list - Figure out which element is lower and add it to the results list - Continue comparing 1st elements of each list until you finish one list - Append the remaining items from the other, unfinished list to results list EX: working on the same project from computers A and B. Want the total error log for the entire project, would need to merge error messages from both computers based on timestamp.
Explain Quick Sort (give an example of when to use it)
Runtime: O(n log n) Operates on the idea of a partition. That is: there is a 'pivot' and we can move all the numbers less than the pivot number to the beginning of the list and move all the numbers greater than the pivot to the right of the pivot number. Get the high and low to get the pivot return quicksort(lo) + eq + quicksort(hi) EX:
4 Slower than O(1) operations on Lists
Searching, Adding (anywhere except the end) Removing (anywhere except the end) Printing each item in a list
What is "this" in Javascript?
Several meanings depending on where it is used. - Method: -> owner object -Alone: -> global object - In a function in strict mode:-> undefined - For methods like call(), apply() -> any object
What does __repr__ do?
Should return a printable representation of the object, most likely one of the ways possible to create this object. Useful for developers, not end users. This function makes an attempt to return a string that would yield an object with the same value when passed to eval()
How to store secrets in code:
Store secrets in an env (stripe_api_key = os.environ["STRIPE_API_KEY"]) There are some services that provide additional security- Postman: create temporary passwords automatically based on a permanent password Docker: secret file, creates a raft of encrypted data that is kept separately from other code.
What does function.apply() do?
The apply() method calls a function with a given this value, and arguments provided as an array (or an array-like object). EX: var numbers = [5, 6, 2, 3, 7]; var max = Math.max.apply(null, numbers); console.log(max); // expected output: 7 var min = Math.min.apply(null, numbers); console.log(min); // expected output: 2
What does function.bind() do?
The bind() method creates a new function that, when called, has its *this* keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
What does function.call() do?
The call() method calls a function with a given this value and arguments provided individually. EX: function Product(name, price) { this.name = name; this.price = price; } function Food(name, price) { *Product.call(this, name, price);* this.category = 'food'; }
What does the __init__ function do?
This function runs as soon as an object of a class is instantiated.
Data Structures: Discuss characteristics of a Trees
Trees: 0+ children; acyclic and directed; only one designated root node
Explain Graphs (give an example of when to use it). Be sure to explain the terms: Node, Edge, Adjacent, and Adjacency List, Weight
Use when the relationship between nodes is cyclical (like friend groups). These relationships can be directed or undirected. (think food chains) Node: a basic unit of a graph (or tree) Edge: connects two nodes Adjacent: two nodes are adjacent if they share an edge Adjacency List: All nodes connected to a single node. Weight: optional measure- think for different airline routes when one route might cost more than another.
Data Structures: Discuss characteristics of a Dictionary
Use when: order is unimportant, frequently adding and removing items, frequently looking up items
Explain-This: What is DNS resolution? What is a DNS and how is it used?
When a browser is using a URL to connect to a website, it must take the given URL to a DNS provider, look up (think like a telephone book) the corresponding IP address, and route to that web server.
What is the difference between function.call() and function.apply()?
While the syntax of this function is almost identical to that of apply(), the fundamental difference is that call() accepts an argument list, while apply() accepts a single array of arguments. EX: *Product.call(this, name, price);* EX: var numbers = [5, 6, 2, 3, 7]; var max = Math.max.apply(null, numbers);
Data Modeling: Terminology: What's the difference between a permutation and a combination?
With Combinations, you're looking for all possible outcomes given a variety of elements. Order doesn't matter. With Permutations, you're looking for all possible combinations, but with additional constraints of ordering.
(Might require pen/paper) Using the Python implementation of Quick Sort from the instructions: Given the list [8, 4, 1, 6, 5, 2, 7, 3]: When this function is initially called, what is the value of low?
[ 4, 1, 2, 3 ]
(Might require pen/paper) Using the Python implementation of Quick Sort from the instructions: Given the list [8, 4, 1, 6, 5, 2, 7, 3]: When this function is initially called, what is the value of list?
[8, 4, 1, 6, 5, 2, 7, 3]
(Might require pen/paper) Using the Python implementation of Quick Sort from the instructions: Given the list [8, 4, 1, 6, 5, 2, 7, 3]: When this function is initially called, what is the value of high?
[8, 6, 7]
What is a closure function?
a closure gives you access to an outer function's scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time. To use a closure, define a function inside another function and expose it. To expose a function, return it or pass it to another function. A function that refers to its parent's scope. Gives functions memory.
What is a javascript promise?
an object representing the eventual completion or failure of an asynchronous operation. Essentially, a promise is a returned object to which you attach callbacks, instead of passing callbacks into a function.
Javascript String Methods (10)
indexOf() - returns index of FIRST occurrence lastIndexOf() - returns LAST index of occurrence search() - finds first occurrence slice(start,stop) - slices a string (don't forget to use n+1) substring(start, stop)- like slice, but can't take negative indexes substr(start, length)-- NOTE: takes the length of extracted part replace() - can replace a substring. NOTE: this makes a new string. Will only replace the first instance of the specified substring toUpperCase() toLowerCase() concat()
What does array.map() do?
map() method creates a new array with the results of calling a provided function on every element in the calling array.
Pros/Cons: CSS animations vs. JS animations
performance is almost the same (in Firefox) Some JS libraries clim to achieve better performance than CSS animations. CSS animations for simpler "one-shot" transitions, like toggling UI element states. (self contained states for UI elements) JavaScript animations when you want to have advanced effects like bouncing, stop, pause, rewind, or slow down. (Use this when you want a lot of control over elements)
What does **kwargs do?
represents all the keyword arguments. Keyword args can be variable-length argument lists.
What's the runtime for Bucket Sort?
Ω(n+k) (very good; close to O(log n) or O(1)
What's the runtime for Counting Sort?
Ω(n+k) (very good; close to O(log n) or O(1)
What's the runtime for Radix Sort?
Ω(n+k) (very good; close to O(log n) or O(1)