Java - data structures Flashcards

(50 cards)

1
Q

primitive data types

A

data types from which more advanced data structures are made: include ints, doubles, longs, floats, shorts, booleans, and chars

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

Int

A

whole number (32 bits) - most commonly used

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

Float

A

decimal (32 bits)

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

Short

A

whole number (16 bits)

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

Long

A

whole number (64 bits)

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

Double

A

decimal (32 bits) - most commonly used

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

reference types

A

more complex data types

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

String

A

sequence of chars

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

array

A

a list that has both an index (number in the list) and data for what’s at that index

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

multidimensional array

A

an array of arrays – the data at the first index has an array, so the index therefore has two points (0,0). 0 for the first slot in the array, and then the next 0 represents the slot in the array for that data

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

jagged array

A

a multidimensional array where the number of columns is not fixed. some index positions might have an array of 5, the next an array of 20, the next just 1

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

resizable array

A

an array whose length you can change as needed

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

how do you search an array

A

for loop

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

Big O Notation

A

Describe the performance or complexity of an algorithm

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

O(1) time

A

consistent duration of algorithm execution in same time (or space) regardless of the size of the input. Also called constant time.

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

O(n) time

A

if the size of the input increases, the computation time directly increases in proportion to the input’s increase. Sample tasks would be for loops that have to look through everything.

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

common operations you might do with lists

A

access, update, insert, search, and delete

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

linked list

A

Like an array, but not necessarily contiguous. Uses pointers to refer to other list items. Doesn’t have to use contiguous locations in memory but can link to any memory slot. Just need a memory address, or rather the next pointer. You just indicate what is next and use that to sort your list.

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

Array class in Java

A

ArrayList class

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

Linked list class in Java

A

LinkedList class

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

Stack

A

An ordered series of objects. You can only add or remove items from the top. You push objects onto a stack and pop objects off of it. Think of a stack of pancakes. You remove from the top. You add a pancake by placing it on top of the stack. Stacks follow a last in, first out (LIFO) policy. The first item pushed onto the stack will be the last item popped off.

22
Q

Pop

A

Removing an item is called popping the item off. To get an item further down the stack, you have to pop off the upper items.

23
Q

When to use stacks

A

great for reversing actions. also for keeping track of state.

24
Q

Queue

A

A list with front and back. Designed to have a front and back. Queues follow a first in, first out policy (FIFO)

25
Enque
the process of adding an item to the queue.
26
Dequeue
the process of removing an item from the queue
27
What are queues good for
Queues are good for storing the order of things that need to happen. often used to share system resources. For example, everyone sending a job to the printer. They keep track of waiting which tasks need to be performed.
28
Shift
moves all elements down by one
29
LIFO
last in, first out (refers to stacks)
30
FIFO
first in, first out (refers to queues)
31
difference between stacks and queues
In one word, the difference between Stack and Queue comes in how they consume elements, In Stack, we remove the most recently added element, while in Queue we remove least recently added element.
32
Poll
removing the top element (first item) in a queue
33
Priority queue
Items with higher priority can be moved to the top of the list.
34
DEQUEK
items can be removed from either end of the queue. But you can’t do anything with items in the middle
35
Peek
see what's at the top of the list
36
are stacks and queues good data structures for pulling information from the middle of the list?
no, if you’re pulling lots of items from the middle of the queue, then they are not the right data structure.
37
associative array
a collection of key-value pairs. example, Sacramento: California. Each key-value pair always stays together. The keys must always be unique in associative arrays.
38
Dictionaries
Python term for hashes. A dictionary is a key-value pair. Internally, this is stored as an array with a hash function on the keys.
39
Hashing
taking raw data and taking it together to create some simplified form. Like making hashbrowns. Different ingredients combined to form some final. The raw data goes through a hashing function (cooking) to arrive at the final value. Basically, you start with some text, and the hash algorithm creates some scrambled form of that original.
40
differences between hashing and encryption
Hash functions are not reversible. One way. You can’t feed the function into some reverse algorithm to get the original values. Just like you can’t get the original ingredients to the hash browns. encryption, on the other hand, is reversible
41
Collision
when two keys have same hash value.
42
Purpose of hashing
let you store a value at a certain location in a secure way.
43
Hash table
A hash table is a way to implement an associative array. A “bucket” is each place for a key-value pair to be stored in the hash table. Key will go through hash function, and then an integer will pop out.
44
hashCode
hashes the value you pass it
45
Set
A collection of unique items. Order doesn’t matter, but none of the elements are duplicated. Grouped with a common property. No key, no index to look up value. You only care about the set as a whole. You’re testing to see if the test has a given number, character, or string.
46
Tree data structure
Unlike with linked lists that just have links to next items, the tree data structure can link to multiple different nodes. In a tree structure, there’s a root node. You can have parent and child nodes down the tree. A node can be a parent and child at the same time. Child nodes with the same parent are siblings.
47
Binary tree
A special type of tree. Each node has two child nodes (left and right nodes). The left child node and right child node could be null, both have values. BST = Binary Search Tree. In the BST, you keep track of order to keep track of left, right, etc. this data structure naturally stays sorted. Binary search trees often store key-value pairs. If you get a match, you remove any need to keep going down the tree. A recursive data structure where each node can have 2 children at most. a common type of binary tree is a binary search tree, in which every node has a value that is greater than or equal to the node values in the left sub-tree, and less than or equal to the node values in the right sub-tree The basic idea is that by sorting the values, when you want to retrieve a particular value, it’s a lot easier to do so because you can eliminate whole branches of the tree.
48
TreeMap
Java class for binary trees
49
Heap
two meanings. area of memory where you allocate objects. in reference to data structures, a heap is a data structure implemented as a binary tree. A heap is a collection of objects. As you add items to the heap, they are always added top to bottom, left to right. We care about min and max values. The heap swap nodes to keep itself organized. Nodes get swapped around so that the parent nodes are smaller than child nodes. Every child must be less than its parent, so you always bubble up the larger values to the top. The max value will always be on top. Order doesn’t matter. Instead, it’s more like a size sorting. Used for priority queues and certain sorting algorithms.
50
when to use a binary tree
One reason to use trees might be because you want to store information that naturally forms a hierarchy. For example, the file system on a computer: