Data Structures & Collections Flashcards

1
Q

What are the different types of data structures?

A
Linear
-Arrays
-Linked-Lists
-Stack
-Queue
Hierarchal
-Trees
-Graph
-Heaps
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are Data Structures?

A

A data organization, management, and storage format that enables efficient access and modification through convenient operations.

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

What are basic data structure operations?

A

Inserting, Deleting, Searching, Iterating, Sorting, Merging

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

What is an Array?

A

Basic Data Structure, often used in the implementation of other data structures

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

What is a Linked Lists?

A

A sequence of data structures are called nodes in which one nodes reference points to the next. The first node is called the head, the last is called the tail.

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

What are the different types of Linked Lists?

A
  • Simple Linked List - Each node only has one reference to the next ( Goes from head to tail ) the tail points to null.
  • Doubly Linked List - Each node has a reference forward to the nest node and backwards to the previous node (except the head and tail) the head and tail points to null.
  • Circular Linked List - The tail has reference to the head node.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Linked List vs. Arrays

A

Linked List are better at insertion and deletion than arrays.

One disadvantage of a linked list against an array is that it does not allow direct access to the individual elements. If you want to access a particular item then you have to start at the head and follow the references until you get to that item.

Another disadvantage is that a linked list uses more memory compared with an array - we extra 4 bytes (on 32-bit CPU) to store a reference to the next node.

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

What is a Stack?

A

A Linear data structure and a type of list that operations to the element follows LIFO (Last In First Out) aka operations only occur on the top element.

Like a stack of plates.
Removing the top element is called popping.

To obtain the value at the top but not removing it is called peaking.

Placing an object on the top is called pushing.

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

What is a Queue?

A

An interface within the Collections API that it’s implementations are much like lines for a rollercoaster or lines at the grocery store, operates under FIFO(First In First Out). Both ends are open for operations.
Adding elements is enqueuing (only to the backend)
Removing elements is dequeuing(only to the front end).

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

What is a Deque?

A

A interface apart of the Collections API that extends from Queue and is a double ended Queue that can add and remove from both ends, FIFO and LIFO

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

What is a Tree?

A

A very common heirarchical data structure, Much like an OS file system structure or an In memory representation of an HTML document. Each element is represented by a node.
Root node is the first node
Parent nodes have references to child nodes.
Sibling nodes have the same parent
Leaf nodes are nodes that have no child
A branch is a complete line (path) from the leaf to the root

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

collections vs Collection vs Collections

A

collection - a collection of entities, or an aggregate Data Structure i.e. Arrays and Maps

Collection - Interface within the Collections API

Collections - Utility Class that has static, convenient methods that operate on Data Structures in the Collections API or return them.

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

Collections API

A
Starts from the Iterable Class
then Colllections class inherits the Iterable class.
Under the Collections class you have these interfaces
-List
    1.) ArrayList
    2.) LinkedList
    3.) Stack
    4.) Vector
-Set
    1.)HashSet
    2.)TreeSet
    3.)(maybe) LinkedHashSet
-Queue
    1.) PriorityQueue
    2.)ArrayQueue
    3.)LinkedList
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a List

A

Lists are an interface that have positional access i.e. indexing, allows duplicates, and is always sequentially ordered. Real world example is like a train, each train car resembles a node, linked to the other.

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

What is an ArrayList?

A

Implemented using arrays
Increases size by 50% each time it needs to increase size Default size is 10
Can only hold objects

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

ArrayList vs LinkedList

A

It’s elements can be accessed directly by using the get and set methods, since ArrayList is essentially an array. LinkedList is implemented as a double linked list. Its performance on add and remove is better than Arraylist, but worse on get and set methods.

17
Q

What is a Vector?

A

Vectors are similar to ArrayLists in which they can be accessed by get and set methods and size dynamically. The only major differences is Vectors are thread-safe as opposed to ArrayLists. Which are not. Addittionally while an ArrayList increases its size by 50% each time it needs to. A Vector increases its size by 100%

18
Q

What is a set?

A

an interface apart of Collections API No Positional access i.e. indexing, does no allow duplicates, not always sequentially ordered Real world example is data tables that are normalized, unique entries, identifying keys like social security, driver licence number. Examples:
Hashset, treeset, hashtable

19
Q

What is a map?

A

A part of the aggregate data Structures
Keys stored as a set, values as a List
Interface that uses key-value pairs
The key values are linked to a memory address in the heap As fast accessing time O(1)
map
Maps are not iterable, but the set of their keys are iterable.

20
Q

HashMap vs TreeMap vs HashTable

A

•HashMap:
May have a null key Many null values

•TreeMap:
No null Keys
Many null values

•HashTable:
No null keys
No null values Thread safe Deprecated