Data Structures Flashcards

Week 2.10, 2.11 (26 cards)

1
Q

describe arrays

A
  • stored contiguously in computer memory
  • same data type
  • insertion at the end of the array = O(1)
  • insertion at a new element of index i = O(n)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

describe linked lists

A
  • node = data + one or more links to other nodes
  • last node - next field set to null
  • memory NOT allocated contiguously
  • size of data field for nodes can be different
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

big O to locate an item in a linked list

A

n

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

big O to insert an item in a linked list

A

1

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

big O to delete an item in a linked list

A

1

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

big O to insert an item into an array

A

last element - 1
element at i - 1

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

big O to delete an item into an array

A

last element - 1
element at i - 1

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

big O to locate an item into an array

A

unsorted - n
sorted - log n

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

describe ADT stack

A
  • LIFO
  • push = insert
  • pop = delete
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

uses of stacks

A
  • reversing data
  • parsing
  • backtracking
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

describe ADT queue

A
  • front & rear
  • FIFO
  • enqueue = inset
  • dequeue = delete
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

uses of queues

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

define priority queues

A
  • as an item enters the queue it is given a priority
  • this determines the order in which the queue is output/read
  • higher priorities processed before lower ones even if the entered the queue after them
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

array implementation of stacks

A

limited size

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

linked list implementation of stacks

A

‘unlimited’ size
- but extra-memory references

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

applications of priority queues

A
  1. a subroutine in more complex algorithms
  2. heapsort algorithms
17
Q

describe heap implementation

A
  • uses a partially ordered binary tree
  • allows insertion & deletion with O(log n)
  • if operations repeated it is more efficient than linked lists and arrays
18
Q

describe trees

A

each node in a tree, except the root, has one parent
- parent-child relationship
- nodes without child-nodes = leaves

19
Q

2 conditions of a complete binary tree

A
  1. all internal nodes have 2 children
  2. all leaves have the same depth
20
Q

define heap

A

a complete binary tree down to a depth of d - 1 and the nodes with depth d are as far left as possible

21
Q

2 properties of heaps

A
  1. the root of the heap always contains the largest element
  2. depth of heap with n elements is lower bound(log2n)
22
Q

describe a heap as its array implementation

A

illustration - ordered binary tree
programs - array
- root node = A[0]
- parent node = A[i]
- 2 child nodes = A[2i + 1] and A[2i + 2]

23
Q

heap insert

A
  • attach new node with key K after last leaf
  • sift k UP to appropriate place in heap
  • O(log n)
24
Q

heap delete

A
  • exchange root’s key with the last K of the heap
  • decrease heap size by 1
  • sift K down to its appropriate place in the heap
  • O(log n)
25
describe a heap sort
- given an array A of n elements, start with initially empty heap and add n elements into heap, one by one - extract the elements from the heap in non-increasing order, putting them back into array A in order
26