abstract data structures Flashcards

(27 cards)

1
Q

what is a linked list

A

linear collection of self referential structures (nodes) connected by pointer links

  • accessed by keeping a pointer to first node of list; called “head”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how to delete a node from binary search tree (3 cases)

A
  1. a leaf
    - set parent to null
  2. node w/ one child
    - make parent skip over deleted node
  3. node w/ two children
    - go once left, then as far right as possible, then replace deleted node w/ this node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

applications of stacks

A
  • undo mechanism
  • recently visited wesbties (history)
  • check for balanced parentheses
  • evaluate expressions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is difference between non-binary and binary tree

A

non-binary: can have any # of children
binary: only can have 2 children (left & right)

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

operations for queues

A

enqueue()
dequeue()

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

variants of queues

A
  • circular: end connected to beginning; after last task finished, first task starts
  • priority: task w/ higher priority executes first
  • double ended queue: can insert/delete from both front and back
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what are the types of tree traversal and how do each of them work?

A
  1. preorder
    - flag attatched to left side
    - traverses each path completely before moving to next path
  2. inorder
    - flag attatched to bottom side
    - traverses left to right
  3. postorder
    - flag attatched to right side
    - traverses children first
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

operations for stacks

A

push()
pop()
isEmpty()
size()

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

what is a binary tree

A

either empty (null pointer), or is made of a single node, where left & right pointers each point recursively to a smaler binary subtree

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

how do stacks work

A

last-in-first-out (LIFO)

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

3 types of linked lists?

A
  1. single
    - 1 head, 1 tail
    - each pointer in 1 direction only
  2. doubly
    - 1 head, 1 tail
    - 2 pointer: one to next node, one to previous node
  3. circular
    - 1 head
    - 1 pointer for each element
    - last elemtent points to head
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what do you use inorder, preorder, and postorder traversal of binary trees for?

A
  • inorder: sorted data (ascending)
  • preorder: recreating tree in exact order
  • postorder: deleting items starting from leaves
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is the max # nodes at a given level of binary tree

A

2^(level-1)

eg. max # nodes at level 2 = 2^1 = 2 nodes

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

what is a binary search tree

A
  • every node in left subtree is less than or equal to its parent node
  • vice versa for right
  • when tree traversed inorder: values of nodes will be in ascending order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

how to insert an item into a binary search tree

A

if value less than
go left
else
go right

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

applications of queues

A
  • tasks scheduled (eg. printing)
  • data transfers
  • traffic signals (?)
17
Q

what are infix, prefix, postfix

A
  • infix: binary operators between operands
  • prefix: binary operators before operands
  • postfix: binary operators after operands
18
Q

how do queues work

A

first-in-first-out (FIFO)

19
Q

features of an abstract data type

A

Its (behaviour) is defined by its operations [1] and the data that the operations are carried
out on [1];
An ADT is a complex data type;
Each ADTs has standardised methods/operations / a specific set of methods/operations
(such as addToEnd. Push etc.);
Implementation details are hidden from the user;
Users only need to know how to use the operations/methods;
Allow ADTs can be allocated memory dynamically;

20
Q

dyanmic vs. static abstract data types?

A

static - fixed size (eg. array)
dynamic - can change size (eg. array list)

21
Q

pros & cons of dynamic adt

A

pros:
- only uses space needed at any time
- makes efficient use of memory (in general)

cons:
- difficult to program
- can be slow to implement searches
- linked list only allows serial search

22
Q

pros & cons of static adt

A

pros:
- easy to program
- easy to check overflow
- array allows random access
- deleting item does not affect index of other items

cons:
- can waste space

23
Q

when to use stacks?

A
  • function calls (methods)
  • replace recursion
24
Q

when to use queues?

A
  • computing applications: serving requests (eg. printing)
  • playlists
  • interrupt handling
25
when to use arrays?
- need random access - known number of elements - need speed when iterating through elements
25
when to use linked list?
- constant time insertions/deletions - unknown number of items - dont need random access - want to be able to insert items in middle
26
when to use binary tree?
- when data is constantly entering / leaving