Topic 4 (+Searching and sorting pseudocode)

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/57

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

58 Terms

1
New cards

Identify inputs and outputs required in a solution

Cycle: Input, Processing, Output, Feedback

2
New cards

Sequential

Following in logical orders/sequences

3
New cards

Preconditions

Constrains the state of a system before the next sector of code starts

4
New cards

Post conditions

Conditions after code has been executed

5
New cards

What to do if there's an exception?

Inform developer, then crash

6
New cards

What to do if there's an error?

Inform user, but keep running

7
New cards

Concurrent

When two or more processes are using the same resources at the same time

8
New cards

Describe how concurrent processing can be used to solve a problem

Increases: Computation speed, Complexity of programming language and hardware. Reduces: Complexity of array operations within loops, matrix multiplication/ sorting/ merging files.

I(CS, CPL, H) R(CAOL, MM, S, MF)

9
New cards

How do you evaluate the decision to use concurrent processing in solving a problem?

Saved or wasted time?

Saved or spent money?

Physically possible?

Consequence of not doing it?

10
New cards

Advantages of concurrency

Time

Cost

11
New cards

Disadvantages of concurrency

May get in each others way

Harder to supervise

12
New cards

Abstraction

Removing characteristics from something in order to reduce it to a set of essential characteristics. It's a technique for managing complexity.

13
New cards

Why is abstraction required?

Reduces complexity, enables concentration on essential, ignores distracting details and essential to problem solving.

14
New cards

How to distinguish between real and abstract?

DETAILS

15
New cards

IB assumptions about collections are

Unordered lists

Unknown length

16
New cards

Operations (5 PseudoCode operations)

.addItem()

.resetNext()

.hasNext()

.getNext()

.isEmpty()

17
New cards

.addItem()

Adds an item to the collection

18
New cards

.resetNext()

Starts at the beginning of the collection

19
New cards

.hasNext()

To see if it has another item

20
New cards

.getNext()

retrieves next data point from collection

21
New cards

.isEmpty()

Checks whether its empty

22
New cards

Most efficient search algorithm?

Binary, Olog(N) notation, only works on sorted lists

23
New cards

Sequential search

Slower, O(N) notation

24
New cards

Bubble sort

Quits early if no swaps occur, but LOTS of swaps happen. O(N^2)

25
New cards

When bubble sorting on a list

Compares and swaps every two numbers

26
New cards

Selection sort

No quit early, always N passes. O(N^2)

27
New cards

Flow chart shapes (bubble, parallelogram, rectangle and diamond)

Bubble: Terminator

Parallelogram: Input/ Output

Rectangle: Process

Diamond: Decision

28
New cards

What effects run time?

Hardware

Abstract data types

Compiler Efficiency

Programmers skills

Complexity

Size of input

(H, ADT, CE, PS, C, IS)

29
New cards

Worse case scenario

Max run time

Number of times the principal activity of the algorithm is performed

30
New cards

Best case scenario

Specific instances of input size N

31
New cards

Average case scenario

Most useful

General case

32
New cards

Fundamental operations of a computer

Add, Compare, Retrieve, Store.

33
New cards

Complex operation example

Finding the biggest number in an array

34
New cards

Low level language

Closer to binary, Machine code or Assembly

35
New cards

High level language

Java, C++, HTML

36
New cards

Natural language

Varying vocab

Ambiguous

Grammar & Syntax inconsistent

37
New cards

Computer language

Fixed vocab

Unambiguous meaning

Grammar & Syntax consistent

38
New cards

Why grammar and syntax is important

Easy to learn and use

Less compilation and logical errors

39
New cards

Need for High Level languages

Similar to human language

Needs for computer systems have expanded

Time constraints - too long to write machine code

(HL, NCS, T)

40
New cards

Need for Low Level languages

Close to binary code that's used to process instructions

41
New cards

Compiler

Translates from a high level language to a low level (in batches)

42
New cards

Interpreter

High level to intermediate, then executed by CPU

43
New cards

Why you need compliers and interpreters?

High level to low level langauge

Translated into machine code for CPU to execute

44
New cards

Why do you need BOTH?

Interpreter is faster and warns about syntax errors, easier when debugging

Compiler needed when there's a need to produce executable version of program

45
New cards

Assembler

Assembly to machine code (mnemonics -> binary)

46
New cards

Variables

Storage locations, naming memory locations with a name and data type that can't be changed.

47
New cards

Constant

Identifier with associated value that doesn't change.

48
New cards

Operator

Set of characters that represents an action (CRA)

49
New cards

Object

Instance of a class

50
New cards

Advantages of modular design

Code reusability, Eases program organization and makes future maintenance easier (CR, EPO, ME)

51
New cards

Need for sub programmes

Breaks down tasks into more manageable sections

Distributes development

Code Reusability

Program readability

(BM, DD, CR, PR)

52
New cards

Bubble sort algorithm

int temp;

loop i from 0 to array.length-1

loop j from 0 to array.length-1

if array[i] > array[i+1] then

temp = array[i]

array[i] = array[i+1]

array[i+1] = temp

end if

end loop

end loop

53
New cards

Selection sort algorithm

int temp;

loop i from 0 to array.length-1

loop j from i+1 to array.length

if array[i] > array[j] then

temp = array[i]

array[i] = array[j]

array[j] = temp

end if

end loop

end loop

54
New cards

Sequential search algorithm

loop for i from 0 to array.length

if searchkey == array[i] then

ouput searchkey, "has been found!"

break;

end loop

55
New cards

Finding the minimum and maximum in an array

int min = array[0]

int max = array[0]

loop i from 0 to array.length

if min > array[i] then

min = array[i]

end if

else if max < array[i] then

max = array[i]

end else if

end loop

output "min =", min, "max =", max

56
New cards

Binary Search Algorithm

input key

low = 0

high = array.length-1

found = -1

loop i while found == -1 && low <= high

mid = (low + high) div 2

if array[mid] == key then

found = mid

else if key < array[mid] then

high = mid - 1

else

low = mid + 1

end if

end while

if found >= 0 then

output key, " was found!"

else

output key, " was not found!"

end if

57
New cards

Hours given minutes

Div 60

58
New cards

Minutes remaining

Mod 60 (This was a past paper question!)