Topc 5 ADT Flashcards

1
Q

ADT

A

Abstract Data types

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

What are ADT’s? (Examples)

A

2D Arrays Linked List Stacks Queues Trees

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

Characteristics of stacks (3)

A

Vertical Last in; first out (LIFO) Collections (Unknown size; don’t know if it’s sorted)

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

Adding an element to a stack

A

.push()

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

Removing an element from a stack

A

.pop()

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

Reverse collection pseudocode

A

// declare an empty stack int count = 0 loop while collection.hasNext() stack.push(collection.getNext() ) count ++; end loop loop i from 0 to count-1 newarray[i] = stack.pop() end loop

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

Characteristics of a Queue

A

Horizontal First in; first out (FIFO)

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

Array to Stack pseudocode

A

loop i from 0 to array.length-1 S.push(array[i]) end loop (same can be done with queues; except enqueue)

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

Printing out a stack pseudocode

A

loop while not stack.isEmpty() output( stack.pop() ) end loop

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

Adding an item to a Queue

A

.enqueue()

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

Removing an item from a Queue

A

.dequeue()

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

Real world examples of a Queue

A

Printer Queues Supermarket Queues

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

Static (3)

A

Size determined at creation Not good use of memory space For loops

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

Dynamic (4)

A

Changes size Nodes and pointers Good use of memory space While loops

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

Accessing element in 2D arrays

A

array[row][column]

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

Declaring 2D array example

A

int [ ] num = new int [row][col]

17
Q

Finding the number of rows

A

array.length

18
Q

Averaging an array pseudocode

A

int count = 0; int average = 0; int total = 0; loop i from 0 to array.length-1; count = count + array[i]; total ++; end loop average = count / total;

19
Q

Finding the number of columns

A

array[0].length

20
Q

Recursion

A

A method that calls itself in a program; which becomes more simple and stops calling itself at some stage

21
Q

Constructing a binary search tree

A
  1. Initial value 2. Second value greater than initial = right 3. Second value less than initial = left
22
Q

Root pointer

A

Top most element in the tree

23
Q

Subtrees

A

Point either left or right

24
Q

Null pointer

A

Points to no elements

25
Q

Types of linked lists

A

Singly; Singly circular and Doubly linked list

26
Q

Parent

A

Node that has children

27
Q

Leaf

A

Node with no children

28
Q

Full binary tree

A

Each node has 0 or 2 children

29
Q

Preorder

A

Left

30
Q

Inorder

A

Bottom

31
Q

Postorder

A

Right

32
Q

Best use of stack

A

Implementing function calls

33
Q

Best uses of queues

A

Computing applications (E.g. CPU) Buffers Playlist Interrupt handling (C; B; P; I)

34
Q

Best uses of linked list (2)

A

Unknown size Want to insert and delete from anywhere

35
Q

Best uses of arrays

A

Random access to elements Speed when iterating

36
Q

Best uses of binary trees

A

Binary Search Tree Heap (Priority Queues) GGM Trees Syntax tree

37
Q

Binary tree vs singly linked list

A

Binary tree - More storage; 2 pointers; Binary search can be used and more efficient Singly linked list - Less storage; 1 pointer; Linear search (slower) and less efficient

38
Q

Stacks and recursion

A

Recursive calls involves use of stacks - storing; popping and pushing

39
Q

Advantages of making a queue dynamic

A

No pre determined/ fixed size Efficient use of memory