Unit 7 - Data Structures Flashcards

(51 cards)

1
Q

What is an elementary data type?

A

The basic types of data that serve as the building blocks for data manipulation.

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

What is a composite data type?

A

Data types which are collections of elementary data types.

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

What is an abstract data type?

A

An abstract data type (ADT) is a logical description of how we view the data and possible operations. We are concerned only with what the data is representing and not how it is constructed.

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

What is a queue?

A

A queue is a abstract data structure which operates on a first-in, first-out principle, meaning the element that has been in the queue the longest is the next to be removed.
- Some queues use pointers to store where in the data the queue begins and ends,
- Some queues are circular and can reuse spaces dequeued from the front,
- Some queue have a priority system and items with a higher priority will be placed before those with lower ones.

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

What are the 4 distinct operations of a queue?

A
  • enQueue(item): add an item to the rear,
  • deQueue(): remove and return an item from the front,
  • isEmpty(): indicates if the queue is empty,
  • isFull(): indicates if the queue is full.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between static and dynamic data structures?

A

Static data structures are fixed in size, they cannot grow, shrink, or be freed during execution.

Dynamic data structures can grow and shrink. They allocate and deallocate memory from the heap (an area of memory especially used for this purpose), excessive allocation of memory, without deallocation, may cause overflow.

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

What is a list?

A

A list is a collection of items that are finite in number and in a particular order.
- A dynamic data structure such as list is useful for implementing other ADTs such as queues, stacks and trees.

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

What are the distinct operations of a list?

A
  • isEmpty(): Test for empty list,
  • append(item): Add a new item to the end of a list,
  • remove(item): Remove first occurrence of an item from list,
  • count(item): Return the number of occurrences of item in list,
  • len(item): Return the number of items in the list,
  • index(item): Return the position of item,
  • insert(pos,item): Add a new item at position pos,
  • pop(): Remove and return the last item in the list,
  • pop(pos): Remove and return the item at position pos.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a stack?

A

A stack is a abstract data structure which operates on a last-in, first-out principle, meaning the element that has been in the queue the shortest is the next to be removed.

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

What are the 4 distinct operations of a stack?

A
  • push(item) – adds item to the top of the stack,
  • pop() – removes and returns the item on the top of the stack,
  • isEmpty(): indicates if the queue is empty,
  • isFull(): indicates if the queue is full.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the call stack?

A

The call stack is a system level data structure which provides the mechanism for passing parameters and return addresses to subroutines.

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

How are calls to subroutines executed?

A
  1. The parameters are saved onto the stack,
  2. Local variables are saved onto the stack,
  3. The address to which execution returns after the end of the subroutine is reached is saved onto the stack,
  4. Execution is transferred to the subroutine code.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How are subroutines executed?

A
  1. Stack space is allocated for local variables,
  2. The subroutine code executes,
  3. The return address is retrieved,
  4. The parameters are popped,
  5. Execution is transferred back to the return address.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a stack frame?

A

A stack frame contains all the parameters, the return address and the local variables for a single call to a subroutine which has not yet completed.

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

What is a hash table?

A

A hash table is an abstract data type used to store the unique addresses (calculated from the data itself through a specific algorithm) of data items rom a large data set in order to give us the ability to find any record very quickly.

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

What is a collision in the context of hashing?

A

A collision happens when an algorithm generates the same address for different primary keys.

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

How do hash tables deal with collisons?

A

One method is to put the item in the next free slot in the table. Another is to skip to a slot which is a specific amount (the skip factor) of slots away and attempting to store it there, repeating this if it can’t.

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

What is the load factor of a hash table?

A

The load factor is the ratio of the number of stored elements (n) to the number of available buckets (b). It is calculated as:

load_factor = n / b

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

What is the ideal hash table size?

A

The table size needs to be large enough so that the load factor is not more than about 50%-70% of table size.
Additionally, it is beneficial if the table is a prime number so that all slots can be filled no matter the skip factor.

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

How does the mid-square hashing algorithm work?

A
  • First square the item (assume it is numeric),
  • Extract some portion of the resulting digits,
  • Perform the mod (remainder) step to get an address,
  • Example: Assume a table size of 11, and a number 56 to be stored:
    562 = 3136
    Middle 2 digits = 13
    Address = 13 mod 11 = 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How does the folding hashing algorithm work?

A
  • Divide the item into equal-size pieces (the last piece may not be of equal size)
    Add the pieces together
    Perform the mod (remainder) step to get an address
    Example: Assume a table size of 11, and a number 34721062 to be stored
    34 + 72 + 10 + 62 = 178
    Address = 178 mod 11 = 2
22
Q

How can you hash alphanumeric data?

A

Alphanumeric data may be converted to numeric data by using the ASCII code for each character, then applying a hashing algorithm to the resulting series of digits.

23
Q

How do hash tables deal with deletions?

A

Items to be deleted must be replaced with a dummy item or marker, for example the word “Deleted”. When searching for an item which hashes to that spot, if it is not found, the search will continue until it is found or a free space located.If a new item is to be added, it will replace the deleted item.

24
Q

What is a dictionary?

A
  • A dictionary is an abstract data type made up of associated pairs,
  • Each pair has a key and a value,
  • The value is accessed via the key.
  • Multiple items with the same key are not allowed, but the value associated with a key could be a list, dictionary or other data structure which can store multiple values
25
What is a graph?
A graph is an abstract data structure representing complex relationships which consists of a set of vertices or nodes connected by edges or arcs.
26
What are the types of graph?
- Undirected: there are no arrows on the edges (lines) indicating direction, thus all lines are bidirectional, - Directed: there are arrows on the edges indicating direction, - Unweighted: It has no weights associated with the edges, - Weighted: It has weights associated with the edges, which may indicate a cost of traversal.
27
What are the two was to represent graphs?
- Adjacency matrix: a table where each row and column represent a node and the presence of a value indicates a connection and a weight (if weighted), - Adjacency list: a list of nodes is created, and each node points to a list of adjacent nodes. (A weighted graph can be represented as a dictionary of dictionaries, with each key in the dictionary being the node, and the value being a dictionary of adjacent nodes and edge weights.)
28
What is an advantage and a disadvantage of using an adjacency matrix?
Advantage: an adjacency matrix is convenient to work with, and adding an edge is simple, Disadvantage: a sparse graph with not many connections (edges) will leave most of the cells empty, wasting a lot of memory space.
29
Why use an adjacency list?
- It only uses storage for the connections that exist, so it is more space-efficient - It is a good way of representing a large, sparsely connected graph
30
What are some potential uses of graphs?
- Computer networks, with nodes representing computers and weighted edges representing bandwidth between them, - States in a finite state machine, - Social networks, - Web pages and links, - Chemistry, with nodes as atoms, edges as connections, - Project management, with nodes as tasks, edges representing sequence and weights, time or cost, - Maps, with nodes representing cities or landmarks, edges representing routes.
31
What is a tree?
A tree is a connected, undirected graph with no cycles (i.e. there is a unique path from each node to any other node).
32
What is a rooted tree?
In a rooted tree, one node is identified as the root, every node except the root has one unique parent.
33
What is a binary tree?
A binary tree is a rooted tree in which each node has a maximum of two children.
34
What are the three ways of traversing a binary tree?
- Pre-order: Visit the root, then traverse the left sub-tree, then the right sub-tree, - In-order: Traverse the left sub-tree, then visit the root, then traverse the right sub-tree, - Post-order: traverse the left sub-tree, then traverse the right sub-tree, then visit the root.
35
What is Pre-order traversal?
Visit the root, then traverse the left sub-tree, then the right sub-tree.
36
What is In-order traversal?
Traverse the left sub-tree, then visit the root, then traverse the right sub-tree.
37
What is Post-order traversal?
Traverse the left sub-tree, then traverse the right sub-tree, then visit the root.
38
What is a binary search tree?
A binary search tree holds items in such a way that the tree can be searched quickly and easily for a particular item .
39
How do you build a binary search tree?
1) Nodes are added in the order given, with the first item at the root, 2) Starting at the root each time, if the next item is less than the root, it is added to the left of the root, otherwise, to the right, 3) Apply the same rule at the root of each sub-tree.
40
What is a balanced binary tree?
A balanced tree is one where the nodes are distributed in such a way that the height is kept to a minimum. This allows more efficient searching.
41
When implementing a binary tree, what does each node consist of?
Each node consists of 3 parts: - The data (which may be a primitive or more complex object). - A left pointer to a child. - A right pointer to a child.
42
How might a binary tree be represented in a computer program?
A binary tree may be represented as an array of records, or a two-dimensional list.
43
What is a scalar?
A mathematical quantity has which has magnitude only.
44
What is a vector?
A mathematical quantity has which has both magnitude (length) and direction.
45
Why use vectors?
In Vector graphics and 3D graphics: - Images are defined as paths, not distinct bit patterns, - Rules of mathematics allow scaling without distortion, In Computer games / simulations: - The combination of moving forces, represented by vectors, can be resolved into a single path by using the same mathematical rules. - Can represent 2, 3, or more dimensions
46
How does vector addition work?
The vector sum (a + b) is found by relocating b so that head touches tail (translation), add vectors by adding the x- and y-parts separately. In effect, addition is translation because of the shifting of the vector.
47
How does vector multiplication by a scalar work?
Multiplying a vector by a scalar value changes the magnitude of the vector. Multiply both x and y parts by the scalar value. In effect, multiplying a vector by a scalar is scaling because it affects the size.
48
What is a convex combination of vectors?
The convex combination of two vectors is the space bounded by the vectors u, v, and the red line. It is an expression of the form: w = αu + βv where α, β >= 0 and α + β = 1 w will always fall inside the vector space defined by u and v
49
What is convex combination of vectors used in?
- 3D modelling: calculating the volume of polyhedra, - Drawing images in perspective (one behind another, hidden line removal).
50
What is the dot product method?
- A method for multiplying 2 vectors, - Written by using a dot (u * v), - Multiply corresponding components of each vector, - u * v = u[1]v[1] + u[2]v[2] + u[3]v[3] + … u[n]v[n] Usage: - One vector contains unit prices, another vector contains numbers sold, then dot product gives amount of money taken, - Finding the angle between two vectors.
51
How do you find the angle between 2 vectors?
The formula for finding the angle Ɵ between u and v is: cos Ɵ = u * v (ǁuǁ * ǁvǁ)