Chapter 3 Data Structures Flashcards

(36 cards)

1
Q

What is a data structure?

A

A way of bundling data so it has well-defined rules for access, change, and scope.

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

What is an elementary data type?

A

A simple data value like integers, reals, characters, or booleans.

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

Difference between arrays and lists?

A

Arrays are fixed-type, fixed-size; lists can be variable-type and dynamic.

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

What is a record?

A

A fixed collection of variables (attributes) under a common name.(not allowed to gain or lose entries after being created)

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

Why arrays are O(1) access?

A

Because element positions can be computed directly using memory offset.

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

What is a pointer?

A

A variable that stores the memory address of another variable. Pointer can have the value of NIL (pointer to ‘nowhere”

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

Why arrays can’t store different types?

A

Because they use fixed-size memory blocks for each entry.

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

What is a linked list?

A

A data structure of nodes (triplets: previous, key, next) linked together.

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

What is the head of a list?

A

The first node (triplet) in a linked list.

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

What is a doubly linked list?

A

Collection of such (previous,key,next) list-triplets we can traverse by some index like an array.

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

Accessing the i-th item in a list?

A

O(n) since you must traverse from the head to the i-th node.

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

Adding an item to the end of a list?

A

O(1) if you use the tail pointer.

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

What is a queue?

A

A FIFO (first-in-first-out) data structure.This has O(1) cost for allowing elements to be added or removed.

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

What is a stack?

A

A FILO (first-in-last-out) data structure. Has O(1) cost for pushing or popping elements from the top of the stack

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

What is a rooted binary tree?

A

A tree with a starting root node where each node has ≤ 2 children.

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

Structure of a binary tree node?

A

(left, key, right) triplet.

17
Q

What is a graph?

A

A set of vertices and edges representing relationships.

18
Q

What is an adjacency matrix?

A

A 2D array showing vertex connections in a graph.

19
Q

What is an adjacency list?

A

An array of lists storing only adjacent vertices.

20
Q

What is a hash function?

A

A function that maps data (keys) to integer indexes.

21
Q

What is a hash table?

A

A structure using a hash function to store and access data in O(1) time.

22
Q

What is a hash collision?

A

When two keys map to the same hash table index.

23
Q

How to resolve hash collisions?

A

By chaining (linked lists) or open addressing (probing).

24
Q

What is chaining?

A

Storing colliding entries in a linked list at each hash table slot.

25
What is open addressing?
Finding another free slot via probing when a collision occurs.
26
What is merge sort?
Sorting algorithm using a list of time complexity O(nlogn) which uses a divide and conquer approach. The array is recursively split in half and when elements are by themselves and uses comparison of these subproblems to sort them and rebuild the full list.
27
What is an array?
Fixed data structure with elements of the same data type(reason is for memory allocation) . Has O(1) time to access and writing on an index even in multi-dimensional arrays?
28
How should a multi-dimensional array be organised in memory? Is getting to (and writing on) x[i,j] still O(1)
Access is still O(1) because: x[i] is O(1) list indexing x[i][j] is another O(1) indexing on the inner list
29
What is NIL ?(think of pointers)
This is a pointer to nowhere. This is well defined by if attempting to modify it it will cause nan error
30
Explain what a list-triplet is for a doubly-linked list?
Previous : A pointer to some data that immediately precedes r in some ordering Key: Value of interest Next: a pointer ti sine data , that immediately succeeds r in some ordering
31
Can we index a linked-list
No, in a linked list we cannot direct index into the i-th element, we must start at the head and follow the .next pointers one-by-one. Nodes are not stored contiguously in memory (in singly or doubly-linked list.
32
What are the algorithms and there time complexities for a linked-list (list operations
ListAccess. : Return the key of the i-th element of a list of interest O(i) -can technically say O(n) if i=n List Search: return the list-triplet with key value, if it exists, otherwise return NIL, O(n) worst case
33
What are lists?
Data structure which has O(1) cost of adding/removing items. Both stack sand queues have operations similar to this. This data structure can hold different data types and does NOT have a fixed length like an array.
34
Trees vs arrays Discuss how you would implement a rooted binary tree using arrays.
1) Use indexing such that left child of node at index i -> 2i , right child -> 2i+1 , Parent -> lower bound of i/2 Advantages : - fast access of index Space -efficient for complete trees Dis: - wastes space for unbalanced trees - not dynamic
35
Write down two limitations of worst-case asymptotic analysis of algorithmic running time.
ignores typical performance (average or practical cases ) Disregards input distribution
36
Write down two advantages and two disadvantages of linked lists compared to arrays
Advantages : - dynamic size (can grow or shrink without allocating extra memory) - Efficient Insertion / Deletion because of use of pointers as only they need to be updated( elements dont need to be shifted like in arrays) Disadvantages : - Slower data access speeds - Inefficient memory allocation(extra memory usage)