19 - computational thinking Flashcards

1
Q

binary search

A

method of searching an ordered list by testing the middle value of the list and rejecting the half that doesn’t contain the value

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

conditions for binary search

A

data has to be sorted

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

how performance of binary search varies with no. data items

A

as you double your data size, you’ll have to do twice as many checks to find an item

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

insertion sort

A

method of sorting data in an array into alphabetical or numerical order by
placing each item in turn in the correct position in the sorted list
+ good for incremental sorting - elements are added one at a time over a long period while keeping the list sorted

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

binary tree

A

a hierarchical data structure in which each parent node can have a maximum of
two child nodes.

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

graph

A

a non-linear data structure consisting of nodes and edges.
used to implement directed and undirected graphs
consists of a set of edges that join a pair of node - if the edges have a direction is a directed graph
edge can have a weight eg the distance between bus stops

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

path and cycle in a graph

A

is the list of nodes connected by edges between two given nodes
a cycle is a list of nodes that return to the same node

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

graph uses in real life networks

A
  • bus routes, where the nodes are bus stops and the edges connect two stops next to each other
  • websites, where each web page is a node and the edges show the links between each web page
  • social media networks, where each node contains information about a person and the edges connect people who are friends
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

dictionary

A

an abstract data type that consists of pairs, a key and a value, in which the key is used to find the value
- each key appears once - values can appear more than once
- keys are unordered
- a value is retrieved by specifying its key
-

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

big O notation

A

a mathematical notation used to describe the performance or complexity of
an algorithm - in relation to the time take or memory used
- describes worst case scenario eg the max no. comparisons to find a value in a list using a search algorithm

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

linear search code

A

found <- FALSE
i <- 0
upperbound <- LEN(array)
WHILE not found AND index<upperbound
IF item = array[i]
found <- TRUE
i = i + 1
IF found
OUTPUT ‘found’
ELSE
OUTPUT ‘ not found’

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

binary search code

A

found <- FALSE
UB <- LEN(array)
LB <- 0
WHILE not found AND LB != UB
i = (UB + LB)/2
IF item = array[i]
found<- TRUE
IF item> array[i]
LB <- i+1
IF item < array[i]
UB <- i-1

IF found
OUTPUT ‘found’
ELSE
OUTPUT ‘ not found’

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

bubble sort

A

sorting data in an array into alphabetical or numerical order by comparing adjacent items and swapping them if they are in the wrong order

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

bubble sort code

A

UB <- LEN(array)
LB <- 0
swap <- TRUE
WHILE swap AND UB != 0
FOR i = LB TO UB-1
swap <- FALSE
IF array[i]>array[i+1]
temp <- array[i]
array[i] <- array[i+1]
array[i+1] <- temp
swap <- TRUE
UB <- UB -1

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

insertion sort code

A

UB <- LEN(list)
LB <- 0
FOR i <- LB +1 TO UB
item <- list[i]
place<- i-1
IF list[place] > item
WHILE place >= LB AND list[place] >item
temp <- list[place+1]
list[place+1] <- list[place]
list[place] <- temp
place <- place -1
list[place+1] <- item

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

what affects the performance of a sorting routine

A

the initial order of the data and the number of data items

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

ADT

A

collection of data and a set of operations on that data
- find an item thats stored
- adding a new item
- deleting an item

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

stack data structure code

A

stack = [0]*10
basePointer = 0
topPointer = -1
maxLen = 10

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

stack pop code

A

if topPointer == basePointer -1:
print(‘stack empty’)
else:
item = stack[topPointer]
topPointer = topPointer -1

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

stack push code

A

if topPointer < maxLen -1:
topPointer = topPointer +1
stack[topPointer] = item
else:
print(‘stack full’)

21
Q

queue data structure code

A

queue = [0]*10
frontPointer = 0
rearPointer = -1
length = 0
maxLen = 10

22
Q

enqueue code

A

if length < maxLen:
if rearPointer < length -1
rearPointer = rearPointer +1
else
rearPointer = 0
length = length + 1
queue[rearPointer] = item
else:
print(‘full’)

23
Q

dequeue code

A

if length == 0:
print(‘empty’)
else:
item = queue[frontPointer]
if frontPointer == length -1
frontPointer = 0
else:
frontPointer = frontPointer -1

24
Q

linked list code

A

list <- []11
listpointers <- []
11
pointerStartPointer <- 0
startPointer <- -1
FOR i (0,11)
listpointer[i]<- i+1
listpointers[11] <- -1

25
search linked list code
found <- FALSE itemPointer <- StartPointer WHILE (itemPointer<> nullPointer) AND NOT found IF list[itemPointer] = itee found<- TRUE ELSE itemPointer<- listpointers[itemPointer] prin(itemPointer)
26
inserting items into linked list code
IF pointerStartPointer = -1 OUPUT 'list full' ELSE tempPointer <- startPointer startPointer<- pointerStartPointer pointerStartPointer <- pointerlist[pointerStartPointer] list[startPointer] <- item listPointer[startPointer] <- tempPointer
27
removing items linked list code
IF startPointer = nullPointer OUTPUT 'list empty' ELSE index <- startPointer WHILE list[i] <> item AND item <> nullPointer oldIndex <- i i <- listpointers[i] IF i = nullPointer OUTPUT 'not found ELSE tempPointer <- listpointers[i] listpointers[[i]<- startPointer startPointer <- i listpointers[oldindex] <- tempPointer
28
binary trees - how they store data
hierarchical data structure - each parent node can have a max of 2 child nodes uses - syntax analysis, compression algorithms, 3D video games root pointer points to first node - left and right pointers show what node is below on the left or right
29
finding item in binary tree code
rootPointer <- 0 itemPointer <- rootPointer WHILE tree[itemPointer].item <> itemSearch AND itemPointer <> nullPointer IF tree[itemPointer].item > itemSearch itemPointer <- tree[itemPointer].leftPointer ELSE itemPointer <- tree[itemPointer].rightPointer
30
inserting items in binary tree
needs free nodes code in textbook
31
how to implement ADTS using another ADT
eg linked list - integers for pointers and string for item
32
dictionary implements
using a linked list - key is a linked list - value is an array of strings
33
bug O order of time complexity
O(1) O(N) O(N²) O(2^N) O(LogN)
34
O(1) - time
describes an algorithm that always takes the same time to perform the task eg deciding if a no is even or odd
35
O(N) - time
describes an algorithm where the time to perform the task will grow linearly in direct proportion to N (the number of items of data the algorithm is using) eg linear search
36
O(N²) - time
describes an algorithm where the time to perform the task will grow linearly in direct proportion to the square of N, the number of items of data the algorithm is using eg bubble sort, insertion sort
37
O(2^N) - time
describes an algorithm where the time to perform the task doubles every time the algorithm uses an extra item of data eg calc of fibonacci numbers using recursion
38
O(LogN) - time
describes an algorithm where the time to perform the task goes up linearly as the number of items goes up exponentially eg binary search
39
big O order of space complexity
O(1) O(N)
40
O(1) - space
describes an algorithm that always uses the same space to perform the task eg algorithm that just uses variables
41
O(N) - space
describes an algorithm where the space to perform the task will grow linearly in direct proportion to N, (the number of items of data the algorithm is using) eg any algorithm that uses arrays eg a loop to calc the total of value in an array of N elements
42
recursion
a process using a function or procedure that is defined in terms of itself and calls itself - defined using a base case - terminating solution thats not recursive - and a general case - solution that is recurisvely defined
43
base case
a terminating solution to a process that is not recursive
44
general case
a solution to a process that is recursively defined
45
winding
the statements after the recursive call arent executed until the base case is reached
46
unwinding
after the base cased is reached and can be used in the recursive process the function is unwinding
47
benefits of recursion + negative
+ contain fewer statements than iterative + can solve complex problems in a simpler way - if recursive calls are repetitive, there is very heavy use of the stack which can lead to stack overflow eg 100 factorial needs 100 function calls on the stack
48
how compiler implements recursion
a compiler must produce object code that pushes return addresses and values of local variables onto the stack with each recursive call, winding the object code then pops the return addresses and values of local variables off the stack, unwinding
49