Half Term 2 Flashcards
(39 cards)
Bubble Sort
How does a bubble sort work?
- 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
Bubble Sort
How many times does a list have to be scanned?
The maximum number of times a list has to be scanned through the length of the list -1
Bubble Sort
What is the basic bubble sort algorithm?
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
Bubble Sort
When should a bubble sort be used?
A bubble sort is good for sorting small lists of data
Object Oriented Programming
What is Object Oriented Programming?
A programming paradigm based on the concept of ‘objects’ which contain attributes and methods
Object Oriented Programming
What is a class?
A class is like a template to ensure that all objects of a certain category have the same kinds of attributes and methods
Object Oriented Programming
What are the components of a class?
Classes are made up of the class name, its attributes and its methods
Object Oriented Programming
What are the benefits of OOP?
Once a class is defined, it is very easy to create hundreds of objects using it
Object Oriented Programming
What is instantiation?
Instantiation is the process of creating an object from a class template
Object Oriented Programming
What is a constructor?
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
Object Oriented Programming
What is the syntax for instantiation?
objectName = new ClassName(“attribute1”, “attribute2”)
Object Oriented Programming
What is encapsulation?
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
Object Oriented Programming
What is the benefit of encapsulation?
Data cannot be changed accidently so reducing the chance of errors, ensures changes to attributes are only made in the way that is intended
Object Oriented Programming
What is an object/instance?
Objects or instances are the things created using a class’ template
Object Oriented Programming
How do you define class functions/methods?
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;
Object Oriented Programming
What is the pseudocode for passing arguments into class constructors
constructor (x,y) {
this.x = x;
this.y = y;
}
object = new class(100,200)
Object Oriented Programming
What is inheritance?
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
Object Oriented Programming
What is polymorphism?
The ability of an entity such as a variable, operator, method or object to have more than one form
Object Oriented Programming
What is overriding?
When an inherited method is superseded by a method defined in the subclass (an example of polymorphism)
Object Oriented Programming
What is overloading?
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)
Object Oriented Programming
What is an access modifier?
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
Object Oriented Programming
What is an attribute?
A specific piece of data representing a particular characteristic of an object
Object Oriented Programming
What is a method?
For example getters and setters and other subroutines that define the behaviour of the object
Logic Gates & Truth Tables
NOT gate symbols and truth table
¬ ~ ! -
0 → 1
1 → 0