Data Structures and Algorithms

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is a trie?

- A tree, but for strings. - it can outperform many types of data structures - useful for autocompletion

what are pros of binary heaps?

- better than O(n) - priority - flexible size - fast insert

what is a binary heap?

- two children to a node - each parent is higher than it's children nodes (max) or lower (min) - left to right insertion

What are graphs made up of?

1. Nodes or vertices 2. Edges

What constitutes 'good' code?

1. Readable 2. Scalable

Sacalability depends on:

1. Speed (Time Complexity) 2. Memory (Space Complexity)

What causes space complexity?

1. Variables 2. Data Structures 3. Function calls 4. Allocations

What are the 4 big O Simplifying rules?

1. Worst Case 2. Remove Constants 3. Different terms for inputs 4. Drop Non Dominants

what are binary trees?

A binary tree is one type of data structure that has two nodes, a left node, and a right node. They have either zero, one of two nodes. and each child can only have one parent. In programming, binary trees are an extension of the linked list structures.

What is a hash function?

A function which maps data of arbitrary size to data of a fixed size

What are queues?

A linear data structure that is FIFO. Can think of them as an entrance to a roller-coaster.

What are stacks?

A linear data structure that is LIFO Can think of them like stacked plates.

What is a Linked List?

A list of nodes or elements of a data connected by pointers

what is a priority queue?

A special type of queue where the highest priority items are at the front of the queue and the lowest priority items at the back.

What are some ways of building graphs?

An edge list -- the edges describe the structure An adjacent list -- the nodes next to each other describe the structure An adjacent matrix -- a waited matrix which describes which nodes are adjescent

What are the Data Structures to know for coding interviews?

Arrays Stacks Queues Linked Lists Trees Tries Graphs Hash Tables

How do you think of Strings in interviews?

As arrays

What is the biggest weakness of hash tables?

Collisions (Sometimes turns lookups to O(n) via Linked Lists)

What does O(1) mean?

Constant time - no loops

What are the important categories of graphs?

Directed graphs (with arrows - one-way) Undirected graphs (no arrows - not one-way ) Weighted - graphs with data in the edges Unweighted - graphs with no data in the edges Cyclic - there are ways to get back to specific nodes Acyclic - no ways to get back to specific nodes

what is the heap in memory?

Dynamic memory which is allocated at run-time. This is not organized according to execution etc. It's just what fits where. (continuous bits still stored together) It is where we store variables.

What is the best way to implement a stack?

Either arrays of Linked Lists are fine, but arrays can be slightly faster because they are cashed together in memory.

What does O(2^n) mean?

Exponential - recursive algorithms that solves a problem of size N

What does O(n!) mean?

Factorial - you are adding a loop for every element. oh nooooo!

What are the benefits of arrays?

Fast Lookup Fast Push/Pop Ordered

What are the main differences between stacks and arrays?

How items get removed.

What does idempotent mean?

In an idempotent function, when given an input, always gives the same output.

what are some of the operations we do on data structures?

Insertion deletion traversal searching sorting access

What is the stack in memory?

Is space in RAM provided by the OS to store data for functions. It is where we keep track of function calls.

What does O(n) mean?

Linear time - for loops, while loops through n items

What is the best way to implement a queue?

Linked lists. Arrays require shifting of indexes, so are not ideal.

What does O(n log(n)) mean?

Log Linear - usually sorting operations

What does O(log N) mean?

Logarithmic time - usually searching algorithms have log n if they are sorted (Binary Search)

What kind of Hash Tables in JavaScript maintain order?

Maps

What is the time complexity of JavaScript unshift (adding a value at the beginning of an array) or splice (adding a value in the middle of an array)?

O(n)

What are the time complexities in a Linked List?

O(n) for general traversal (inserts, deletion, etc) O(1) for operations at head or tail

What are hash tables in JavaScript?

Objects (Key - value pairs)

What does O(n^2)

Quadratic - every element in a collection needs to be compared to ever other element. Two nested loops

What are the types of objects in JS?

Reference Type (as versus primitive type)

What are pointers?

References to another place in memory.

What are graphs useful for?

Representing things related to other things. (FB, Amazon recommendations?)

What are the downsides of graphs?

Scaling is very hard. Need a whole company to manage.

What kind of Hash Tables in JavaScript have keys but no values?

Set

What are the weaknesses of arrays?

Slow Inserts Slow Deletes Fixed Size (for static arrays)

What are the Algorithms to know for coding interviews

Sorting Dynamic Programming BFS and DFS (Searching) Recursion

What are the two types of arrays?

Static Arrays Dynamic Arrays

What is the head in a linked list?

The first node. The last node is the tail.

What is garbage collection?

This means that memory is cleaned up automatically.

How are graphs and trees related?

Trees are a type of graph?

In JavaScript how do we save a Hash Table with a function or an array as a key?

Use a Map

What are algorithms?

Ways of using data to create programs.

What are data structures?

Ways to store data.

What does bigO mean?

When inputs increase, how do outputs increase (how does it scale)?

When are graphs most useful?

When we have complex relationships.

what is the connection between a linked list and a tree?

a linked list is a singular, linear type of tree

what is an avl or a red/black tree?

a self-balancing binary search tree that goes back if unbalanced to balance the tree

What is a binary search tree?

all child nodes in the tree on the right, must be greater than the root node a node can only have two children it's good because it preserves relationships

what is a perfect binary tree?

all the nodes are filled in. this is different from a full binary tree, which has gaps.

What data structure has the smallest footprint?

arrays

why are unbalanced binary search trees problems?

because they can become linked lists, and have only O(n) complexity.

what are the pros of binary search trees (assuming balanced)?

better than O(n) ordered flexible size

why use a binary heap?

comparative search functions

What is the time complexity of a queue?

enqueue O(1) - add a person to end of line dequeue O(1) - remove first person in line peek O(1) lookup O(n) - don't usually want to do this

What are hash tables good for?

insert O(1) lookup O(1) delete O(1) search O(1)

In big O, a loop alone is...

linear time O(n)

what is the equation that defines the level in a perfect binary tree?

log N = number of levels

what is the time complexity of a binary tree?

lookup - O(log N) insert - O(log N) delete - O(log N)

what is the time complexity of a binary heap?

lookup -O(n) - less ordered than a binary search tree insert - O(log N) delete - O(log N)

Arrays are best for

lookup O(1) push O(1) pop O(1)

what are cons of binary search trees

no O(1) operations not really the fastest for anything

What does the tail in a Linked List point to?

null

What is the time complexity of a stack?

pop O(1) push O(1) peek O(1) lookup O(n) - don't usually want to do this

In big O, a nested loop is...

quadratic time O(n^2)

what are cons of binary heaps?

slow lookup

In a coding interview it is important to check ...

the inputs

In JavaScript how are the keys in objects save?

the key is stringified

what do the binary tree objects consist of.

this.value this.left this.right


संबंधित स्टडी सेट्स

introduction, scientific method, history, sleep, drugs, brain, bio

View Set

Chapter 9 - Nail Structure and Growth

View Set

Geology Lesson 9b: Absolute and Geologic Time

View Set