Data Structures Algorithms Flashcards

1
Q

How do we measure algorithms ?

A

In computer science and programming the efficiency of an algorithm is measured using Big O notation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why should developers care about data structures and algorithms ?

A

There are numerous data structures that can be chosen for a given problem, example should one use an array to store phone numbers or use a dictionary to map the names to phone numbers and so on. The more data structures one is exposed to the better the decision making process can be in choosing the right structure. As per algorithms, those are the steps in solving a given problem, some pre-defined algorithms exist such as binary search and shortest path, but everyday developers solve software development challenges and have to come up with steps and test cases for their given solution, so as with data structures, exposure and knowing how to measure efficiency of algorithms using Big O is vital to the success of a software engineer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which sorting algorithm uses a pivot and partitioning ?

A

Quick sort uses partitioning to return a pivot as it continues to sort a collection using divide and conquer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the properties of a doubly linked node ?

A

A value (the data type of the Node), a next pointer and a previous pointer property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Name three built-in data structures in Swift ?

A

Arrays, Set and Dictionary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name the types of depth-first traversals and explain how each works ?

A

In order, pre order and post order traversal.

In-order traversal visits the left nodes then the root node then the right nodes.

Pre-order traversal visits the root node first, then the left sub tree, then the right subtree.

Post-order traversal visits the left subtree, then the right, then visits the root node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the runtime of contains on an array ?

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s the runtime of contains on a set ?

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s the requirements of a recursive function ?

A

Any recursion function must have a base case and the recursive call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Name a few sorting algorithms and their runtimes ?

A

Bubble sort, O(n ^ 2)
Insertion sort, O(n ^ 2)
Merge sort, O(n log n)
Quick sort, O(n log n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is divide and conquer and give an algorithm example ?

A

Divide and conquer is the process of taking a larger problem and breaking it down into smaller parts and solving sub parts until a solution is met. Examples of divide and conquer algorithms are merge sort, quick sort and binary search.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly