Data Structures and Abstract Data Types Flashcards

1
Q

What is the time complexity for hash table lookup?

A

O(1)

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

Name 2 collision resolution methods

A

closed addressing (linked list at location), open addressing (new location)

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

What is the time complexity for linked list insertion and deletion? (Assuming the index for insertion/deletion is already known)

A

O(1)

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

What is the time complexity for linked list search?

A

O(n)

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

State three features of a good hashing algorithm

A
  1. The hash function uses all the input data
  2. The hash function uniformly distributes the data across the entire set of possible hash values
  3. The hash function generates very different hash values for similar (but non-identical) strings
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name 2 Abstract Data Types.

A

Stack and Queue

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

How does a stack work?

A

Elements are pushed onto the stack, or popped from the stack.
The first element pushed onto the stack is the last element popped from the stack (FILO)

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

How does a queue work?

A

Elements are enqueued into the queue, or dequeued from the queue.
The first element enqueued is also the first element dequeued (FIFO)

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

What methods are required for a Queue ADT?

A

Enqueue: add an element to the queue
Dequeue: get the next element from the queue

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

What methods are required for a Stack ADT?

A

Push: add an element to the stack
Pop: get the next element from the stack

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

What are the key features of a Circular Queue?

A

Circular queues have a fixed capacity.
The last location in the array wraps around to the first location.

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

What does a hash function do in a hash table?

A

Hash function takes an input key and returns a location/index of fixed size. Each unique key hashes to the same location/index.

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

static vs dynamic memory allocation

A

Static allocation pre allocates fixed amount of memory upfront … / has constant access time …
1. predetermined data format (element size is calculated)
2. constant access
3. fixed size

while dynamic allocation requests memory on an ad-hoc basis / only when needed / requires traversal to reach further nodes
1. flexible data format
2. no constant time access
3. dynamic size

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

BST vs Hash table (5 criteria)

A
  1. sorting: In order traversal of BST allows us to display items in incremental order
  2. searching for closest value: BST allows us to search for the key that has the closest value to target
  3. memory efficient: BST requires the exact amount of memory for its nodes
  4. time complexity of searching : hash table O(1), BST: O(logn)
  5. worse time complexity of searching:
    - hash table (collision O(n)) -> choose appropriate size table
    - BST (unbalanced O(n)) -> self balancing BST every time there is a change made
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

state the differences between circular queue and linear queue

A
  1. space utilisation
    circular queue efficiently utilises available space by reusing positions that become free whereas a linear queue may leave unused spaces at the beginning as elements are dequeued
    (linear= less efficient use of memory)
  2. wrapping
    in a circular queue, the last position is connected back to the first position, forming a loop
    in a linear queue elements only move in a straight line from front to back
How well did you know this?
1
Not at all
2
3
4
5
Perfectly