SDD Flashcards
What is the difference between a singly and a doubly linked list?
A singly linked list stores each piece of data with a pointer to the next item (so can only be traversed in one direction), a doubly linked list also stores the pointer to the previous item (so it can be traversed in both directions)
What are the advantages of a linked list over an array?
- More dynamic (easier to add and remove items, length not fixed)
- To insert or delete items only pointers need to be changed
What are the disadvantages of a linked list over an array?
- List needs to be traversed to reach a required item (can’t be indexed)
- Takes up more memory to store pointers
What is the definition of an object?
An instance of a class with instance variables and methods
What is the definition of properties and methods?
Class variables and procedures/functions respectively
What is the definition of a class?
A template to create an object with class attributes and methods
What is the definition of a sub-class?
A class that inherits its attributes and methods from its super-class
What is the definition of encapsulation?
When information is hidden from some objects to allow for public and private variables
What is the definition of inheritance?
When a sub-class derives its variables and methods from its super-class
What is the definition of instantiation?
Creating an instance of the class
What is the definition of polymorphism?
When a sub-class redefines an inherited attribute or method
What are the steps for a binary search?
- Set the minimum to the first index (0) and the maximum to the last (length of array - 1)
- Start a conditional loop that runs while min <= max
- Set the middle index to (min + max) / 2
- If the item at the middle index is greater than the target then set max to mid - 1
- If the item at the middle index is smaller than the target then set min to mid + 1
- Otherwise, return the middle index (or the item at the middle index)
What are the requirements for a binary search?
All data must be sorted
What are the steps for an insertion sort?
- Start an unconditional loop from index 1 to the index of the last list item
- Store the value of the currently indexed item
- Store a temporary copy of the current index (so that it can be modified)
- Start a conditional loop that runs while the temporary index is greater than 0 and the item at the temporary index is greater than the current item
- Set the item at the temporary index to the item at the index before
- Subtract one from the temporary index
- Outside of the conditional loop, set the item at the temporary index to the current item
What are the steps for a bubble sort?
-Declare a variable n to be the length of the array
-Declare a Boolean swapped variable to be true
-Start a conditional loop while swapped is true and n >= 0
-Set swapped to false
-Start an unconditional loop from 0 to n-2
- If the item at the current index is greater than the item at the next index then
- Set a temporary variable to the currently indexed item
- Set the currently indexed item to the value at the next index
- Set the item at the next index to the temporary variable
-Set swapped to true
-Outside of the unconditional loop, deincrement n