Half Term 2 Flashcards

1
Q

Bubble Sort

How does a bubble sort work?

A
  • Compare first set of numbers
  • If second number is less than first, swap them
  • Compare next set of numbers
  • Repeat to end of list
  • Start again from the first pair in the list
  • Repeat until no pairs need to be swapped
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Bubble Sort

How many times does a list have to be scanned?

A

The maximum number of times a list has to be scanned through the length of the list -1

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

Bubble Sort

What is the basic bubble sort algorithm?

A

repeat [number of items - ] times
for each adjacent pair of items in the list
if first of pair is greater than second of pair
swap

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

Bubble Sort

When should a bubble sort be used?

A

A bubble sort is good for sorting small lists of data

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

Object Oriented Programming

What is Object Oriented Programming?

A

A programming paradigm based on the concept of ‘objects’ which contain attributes and methods

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

Object Oriented Programming

What is a class?

A

A class is like a template to ensure that all objects of a certain category have the same kinds of attributes and methods

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

Object Oriented Programming

What are the components of a class?

A

Classes are made up of the class name, its attributes and its methods

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

Object Oriented Programming

What are the benefits of OOP?

A

Once a class is defined, it is very easy to create hundreds of objects using it

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

Object Oriented Programming

What is instantiation?

A

Instantiation is the process of creating an object from a class template

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

Object Oriented Programming

What is a constructor?

A

A constructor is a special method which runs when an object is created from the class. It contains “new”. Objects are instantiated by calling the class’ constructor

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

Object Oriented Programming

What is the syntax for instantiation?

A

objectName = new ClassName(“attribute1”, “attribute2”)

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

Object Oriented Programming

What is encapsulation?

A

All of the object’s attributes are contained and hidden in the object by giving them the private access modifier. They are accessed through public getter and setter methods

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

Object Oriented Programming

What is the benefit of encapsulation?

A

Data cannot be changed accidently so reducing the chance of errors, ensures changes to attributes are only made in the way that is intended

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

Object Oriented Programming

What is an object/instance?

A

Objects or instances are the things created using a class’ template

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

Object Oriented Programming

How do you define class functions/methods?

A

When defining class functions, the keyword “this” must be used to declare class variables (not “let” or “var”) e.g.
constructor() {
this.x = 200;
this.y = 150;

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

Object Oriented Programming

What is the pseudocode for passing arguments into class constructors

A

constructor (x,y) {
this.x = x;
this.y = y;
}

object = new class(100,200)

17
Q

Object Oriented Programming

What is inheritance?

A

A mechanism that allows an instance of a class to inherit attributes and methods from another class (the superclass/parent class). It can also have methods/attributes of its own

18
Q

Object Oriented Programming

What is polymorphism?

A

The ability of an entity such as a variable, operator, method or object to have more than one form

19
Q

Object Oriented Programming

What is overriding?

A

When an inherited method is superseded by a method defined in the subclass (an example of polymorphism)

20
Q

Object Oriented Programming

What is overloading?

A

When methods have the same name but different signatures. The signature can differ by the number of parameters or type of parameters or both (an example of polymorphism)

21
Q

Object Oriented Programming

What is an access modifier?

A

For example public and private which can be applied to attributes and methods in the class. Private means the attribute or method can not be accessed by code in another class while public means it can

22
Q

Object Oriented Programming

What is an attribute?

A

A specific piece of data representing a particular characteristic of an object

23
Q

Object Oriented Programming

What is a method?

A

For example getters and setters and other subroutines that define the behaviour of the object

24
Q

Logic Gates & Truth Tables

NOT gate symbols and truth table

A

¬ ~ ! -
0 → 1
1 → 0

25
Q

Logic Gates & Truth Tables

AND gate symbols and truth table

A

^ * &
0 0 → 0
0 1 → 0
1 0 → 0
1 1 → 1

26
Q

Logic Gates & Truth Tables

OR gate symbols and truth table

A

v + ||
0 0 → 0
1 0 → 1
0 1 → 1
1 1 → 1

27
Q

Logic Gates & Truth Tables

XOR gate symbols and truth table

A

⊻ ⊕
0 0 → 0
1 0 → 1
0 1 → 1
1 1 → 0

28
Q

Logic Gates & Truth Tables

How do you create a truth table from a logic diagram?

A
  • Create a column for each input
  • List combinations
  • Create columns for interim outputs
  • Find outputs
29
Q

Stacks & Queues

What is a stack?

A

A stack is an essential data structure. Items are pushed to the top of the stack when added and popped off the top when deleted. It’s possible to peek at the top item without deleting. It’s a LIFO structure

30
Q

Stacks & Queues

What is a LIFO structure?

A

Last In First Out - The last item to be pushed onto the stack must also be the first to be popped off

31
Q

Stacks & Queues

What is a stack pointer?

A

A stack pointer points to the node at the top

32
Q

Stacks & Queues

What are stack underflow/overflows?

A

Stack overflow is an attempt to push an item onto a full stack. Underflow is an attempt to pop an item off of an empty stack

33
Q

Stacks & Queues

How are the stacks implemented?

A

Stacks are often implemented with an array but could use object-oriented techniques instead

34
Q

Stacks & Queues

How are stacks used?

A
  • Stacks are used by processor to track the flow of programs. When a subroutine is called, it changes the value of the program counterto the first instruction of the subroutine. When the subroutine ends, the PC must return to its previous value. Stacks allow subroutine calls to be nested
  • Local variables are held on stacks - their values are lost when a subroutine ends because they are popped off the stack. Interrupts can also be handled with a stack
  • Performing depth-first searches on graph structures
  • Keeping track of user inputs
  • Undo operations
  • Backtracking algorithms
  • Evaluating mathematical expressions without brackets
35
Q

Stacks & Queues

What is a queue?

A

A queue is a linear data structure. Items are enqueued at the back of the queue and dequeued from the front of the queue. You can peek at the front item. In special situations, new items can join at the front. It’s a FIFO structure

36
Q

Stacks & Queues

What is a FIFO structure?

A

First In First Out - back/tail pointer points to last item, front/head pointer points at first item

37
Q

Stacks & Queues

What is the problem with creating a queue with an array?

A

In an array, since the back and front