Algorithm Flashcards
Stability
A stable sorting algorithm ensures that elements with identical sorting properties still maintain their original order.
Space
An in-place algorithm does not need to initialise a new array to store the elements in sorted order. All sorting happens within the original array.
An out-of-place algorithm initialises a new array for storing sorted elements. The new array is returned, and the original array discarded.
Time complexity
time complexity describes how time taken increases as input size grows
Does not include actual time taken
time complexity of algorithms
Bubble/Insertion SortO(n2)
Merge Sort O(n log n)
Quick Sort Worst case O(n2) O(n log n)
Abstraction
Abstraction means that the details of implementation are hidden; the end-user only has to know what input is required, and what output to expect.
Encapsulation
Encapsulation means that data and methods that act on the data are bundled into objects
Advantages of encapsulation 4
makes the data and methods more easier to import into other programs
associates attribute names with objects, allowing the same names to be reused in other objects/in the global space (minimises name collision)
organises the code into logical units (objects), making the code easier to understand
Prevents inadvertent data modification of private variables from public program codes
Inheritance
A way of reusing code of existing objects and to establish a subtype from an existing object
Advantages of iheritance
superclass used to define/establish features that are required by all subclasses
allows existing code to be reused instead of reimplementing for each class,saving time and memory space
Polymorphism
Two classes that exhibit polymorphism behave the same way by having the same interface, allowing them to be used interchangeably, even if their implementation is different.
Advantages of polymorphism
This allows the main program to support multiple client instances with the same method names/with the same code, minimises duplication of code
Class
a blueprint or template that describes the data/attributes and methods to create an object
Object
An instance of a class with a particular set of associated variables and functions
Static and class methods
A method that does not have access to its instance inside the method
A method that does not have access to its instance but has access to the class inside the method
Variable
Variable is a label in the program pointing to a data object