Data structures and algorithsm Flashcards

1
Q

What is a linked list

A

A dynamic data structure where each node consists of data and a pointer. The pointer gives the location of the next node.

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

What is a tree

A

A data structure that consists of nodes and sub nodes. The first node is called the root and lines that join nodes are called branches.

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

What is a binary tree

A

A type of tree where each node has a maximum of two sub nodes. If a child node is less than the parent node, to goes to the left of the parent and if a child node is greater than the parent node is goes to the right of the parent.

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

What is depth-first traversal?

A

Dept-first traversal is an algorithm for searching a graph/tree. It goes to the left child node when it can and if there is no left child it goes to the right child. When there are no child nodes, the algorithm backtracks to the parent node. It uses a stack.

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

What is breadth-first traversal?

A

Breadth-first traversal is an alghorithm for searching a graph/tree. It visits all nodes connected directly to the start node, then visits all nodes directly connected to each of those nodes directly connected to each of those nodes and so on. it uses a queue.

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

What are the advantages of depth-first traversal in comparison to breath-fiorst traversal

A

Depth-first traversal require less memory than breath-first tranversal. It is also quicker if you are looking at deep parts of the tree.

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

What are the disadvantages of depth-first traversal in comparison to breadth-first traversal.

A

Depth-first isn’t guarateed to find the quickest solution and possibly many never find the solution if we don’t take precautions not to revisit previously visited state.s

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

What is a Stack.

A

A data structure that operates on a first in last out basis.

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

What is a queue.

A

A data structure that oerates on a first in first out basis,.

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

What is a hash table?

A

A data structure that maps keys to values. It uses a hash function to generate the key.

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

What is the difference between an Array and a linked list.

A

An array is static yet a linked list is dynamic

Elements in arrays can be accessed directly but has to be traversed ina linked list.

Contents of array are stored contiguously in memory nit a linked list might not be.

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

What is meant by a graph structure?

A

A collection of data (nodes) and connections (edges) are made between nodes. Edges can directional, bi-directional directed or undirected.

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

Define Big O notiation

A

The Big O notation describes the complexity of an algorithm, It evalutates the worst-case scenario for an algorithm and shows how time/ memory increase as data size increases.

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

What is meant by logarithmic growth in terms the complexity of an algorithm

A

As the size of an array increases, the rate at which the algorithm runs increases more slowly. This is the inverse of exponential growth, the rate of increase is a logarithmic function of the size of an array.

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

When might a linear search perform better than a binary search?

A

If the data set is small or if the item being search for is close to the start of the array.

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

What’s the best case for binary search?

A

If the element you are search for is the first element to be compared to (the midpoint).

17
Q

What’s the best case for linear search?

A

If the element you are searching or is the first element to be compared to ( the first element in the list).

18
Q

Whats’ the best case for bubble sor?

A

O(n)

19
Q

What’s the best case for insertion sort?

A

O(n)

20
Q

What’s the best case for merge sort?

A

O(n log n)

21
Q

Whats the best case for quick sort?

A

O( n log n)

22
Q

name an algorithm that has a big O notation of O(1)

A

Hash function

23
Q

Name an algorithm that has a Big O notation of O(n)

A

e.g Linear search

24
Q

Name an algoriuthm that has a big O notation of O(n^2)

A

e.g Bubble sort.

25
Q

Name an algorithm that has a Big O notaƟon

of O(2n)

A

E.g. Fibonacci sequence

26
Q

Name an algorithm that has a Big O notaƟon

of O(log2n)

A

E.g. Binary search

27
Q

Name an algorithm that has a Big O notaƟon

of O(n log2n)

A

E.g. Merge sort

28
Q

How does the linear search algorithm work?

A

Linear search works by:
Going through each element in the list.
Comparing each element to the target value.
Returning the index of the target value once

found.

29
Q

How does the binary search algorithm work?

A

Binary search works by: Finding the midpoint of a list.
Comparing the midpoint to the target value.
Returning the midpoint if it is equal to the target
value. Creating a sub‐list from the left if the midpoint
is greater than the target value. Creating a sub‐list
from the right if the midpoint is less than the target
value. Repeating this process until the midpoint is

equal to the target value.

30
Q

How does the bubble sort algorithm work?

A

Bubble sort works by:

Looking at the first two elements of the list.
Comparing their values. Swapping them if the
second element is smaller than the first
element. Repeating this until no further
changes need to be made.

31
Q

How does the insertion sort algorithm work?

A

Intersion sort works by:

going through each element of the list.
Comparing its value to each element on the left of the element. Inserting the item in the correct position in the list.

32
Q

how does the merge sort algorithm work?

A

Merge sort works by:

splitting the list of size n into n number of lists. Comparing values in these lists merging them into temporaty lists.

33
Q

How does the qucik sort algorithm work?

A

Quick sort works by:

choosing an item as a pivot. Creating two sub-lists, one bigger than the pivot, one smaller.
Comparing each item to the pivot and sorting them accordingly.

34
Q

Name the two path finding algorithms?

A

Dijkstr’s algorithm and A* algorithm

35
Q

What are the differences between dikstra’s and the A* algorithm

A

The A* algorithm uses a heuristic value, so finds a path in a faster time. Does not consider all possible paths. Dijkstra’s uses a weightinh value and considers all paths before finding a solution, so may take longer but may find shorter route.