week 2 Flashcards
what is a data structure
A systematic way of organising, accessing and updating data
Algorithm
A step by step procedure of how to do a task
How do data structures use algorithms
use algorithms to update and retrieve data
ADT (Abstract data type)
model of a data structure (eg a stack) that specifices what operations can be performed on it ( eg like push , peek , pop on a stack) and what these operations do
Also tells you the data type stored and the parameters of operations eg ( the value you want to put at top of stack when using push)
ADT can be expressed by an … in java
interface
A linked list is a sequence of …
nodes
In a linked list nodes store
. the element
. the link to the next node
Difference in speed between arraylist and linked list
Array list - Random access - takes same amount of time to get the first element as the 5000th element
Linked list - sequential access
when is a linked list better than an array list
when removing or adding elements
Lets say I wanted to put an element in 1st index
All i would need to do is change the connections of the 2 originally collected elements
the next of the first element (0th index) would now be connected to the new node. The previous of the old second element (old 1st index) is now connected to the new node
the previous of new node goes to first element and the next goes to the old second element
In an array list a whole different array of new size would need to be created
when to use array list and when to use linked list
. if you want to retrieve certain elements array list is better and faster
.if you want to add or delete linked list is faster
what is encapsulation
bundling data and methods into classes
we use methods to set and get variables so that in external classes we dont need direct access to variables (variables are usually private anyways so external classes cant use them which is why we use get and set …)