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
Q

search linked list code

A

found <- FALSE
itemPointer <- StartPointer
WHILE (itemPointer<> nullPointer) AND NOT found
IF list[itemPointer] = itee
found<- TRUE
ELSE
itemPointer<- listpointers[itemPointer]
prin(itemPointer)

26
Q

inserting items into linked list code

A

IF pointerStartPointer = -1
OUPUT ‘list full’
ELSE
tempPointer <- startPointer
startPointer<- pointerStartPointer
pointerStartPointer <- pointerlist[pointerStartPointer]
list[startPointer] <- item
listPointer[startPointer] <- tempPointer

27
Q

removing items linked list code

A

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
Q

binary trees - how they store data

A

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
Q

finding item in binary tree code

A

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
Q

inserting items in binary tree

A

needs free nodes
code in textbook

31
Q

how to implement ADTS using another ADT

A

eg linked list - integers for pointers and string for item

32
Q

dictionary implements

A

using a linked list
- key is a linked list
- value is an array of strings

33
Q

bug O order of time complexity

A

O(1)
O(N)
O(N²)
O(2^N)
O(LogN)

34
Q

O(1) - time

A

describes an algorithm that always takes the same time to perform the task
eg deciding if a no is even or odd

35
Q

O(N) - time

A

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
Q

O(N²) - time

A

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
Q

O(2^N) - time

A

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
Q

O(LogN) - time

A

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
Q

big O order of space complexity

A

O(1)
O(N)

40
Q

O(1) - space

A

describes an algorithm that always uses the same space to perform the task
eg algorithm that just uses variables

41
Q

O(N) - space

A

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
Q

recursion

A

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
Q

base case

A

a terminating solution to a process that is not recursive

44
Q

general case

A

a solution to a process that is recursively defined

45
Q

winding

A

the statements after the recursive call arent executed until the base case is reached

46
Q

unwinding

A

after the base cased is reached and can be used in the recursive process the function is unwinding

47
Q

benefits of recursion + negative

A

+ 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
Q

how compiler implements recursion

A

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
Q
A