week 2 Flashcards

1
Q

what is a data structure

A

A systematic way of organising, accessing and updating data

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

Algorithm

A

A step by step procedure of how to do a task

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

How do data structures use algorithms

A

use algorithms to update and retrieve data

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

ADT (Abstract data type)

A

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)

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

ADT can be expressed by an … in java

A

interface

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

A linked list is a sequence of …

A

nodes

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

In a linked list nodes store

A

. the element
. the link to the next node

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

Difference in speed between arraylist and linked list

A

Array list - Random access - takes same amount of time to get the first element as the 5000th element

Linked list - sequential access

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

when is a linked list better than an array list

A

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

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

when to use array list and when to use linked list

A

. if you want to retrieve certain elements array list is better and faster
.if you want to add or delete linked list is faster

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

what is encapsulation

A

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 …)

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