Skip to content

Commit ca93a10

Browse files
authored
Java Data Structures you must know
1 parent 356fa45 commit ca93a10

File tree

5 files changed

+115
-32
lines changed

5 files changed

+115
-32
lines changed

Commandsndvariables.java

-9
This file was deleted.

HelloWorld.java

-8
This file was deleted.

Javaprogramarchitecture.java

-8
This file was deleted.

Maps/HashTable/HashTable.java

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.*;
2+
3+
public class HashTable {
4+
static void log(Object o)
5+
{
6+
System.out.print(o);
7+
}
8+
9+
static void logln(Object o)
10+
{
11+
System.out.println(o);
12+
}
13+
14+
public static void main(String[] args) {
15+
Hashtable<String, String> licenplates = new Hashtable<>();
16+
Enumeration people;
17+
String output;
18+
19+
licenplates.put("David", new String("6543ML"));
20+
licenplates.put("Tracy", new String("6UN274"));
21+
licenplates.put("Bob", new String("37KU42"));
22+
23+
//Retrieve All License Plates
24+
people = licenplates.keys();
25+
26+
while(people.hasMoreElements()) {
27+
output = (String) people.nextElement();
28+
System.out.println(output + ": " + licenplates.get(output));
29+
}
30+
31+
32+
//Outputs the number of elements within the hashtable
33+
logln(licenplates.size());
34+
}
35+
}

MustKnow/README.md

+80-7
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,35 @@
44

55
#### DS You Must Know
66

7-
##### ★★★Most Popular Data Structures★★★
7+
##### ★★★★★Most Popular Data Structures★★★★★
8+
89
- Array
910
- Linked List
1011
- Stack
1112
- Queue
13+
- Binary Tree
14+
- Binary Search Tree
15+
16+
##### ★★★★Operation You Can Perform On A Data Structure★★★★
17+
18+
19+
- Delete: Remove an item from the data structure
20+
- Insert: Add an item to the data structure at any location
21+
- Merge: Combining the items within data structure A and data structure B into a single one(i.e. call it C)
22+
- Search: Look up an item's location within the data structure
23+
- Sort: Arrange items within the data structure in a specific order
24+
- Traverse: Visit each item in the data structure to perform some operation(e.g. search/sort)
25+
26+
27+
##### Big O, Big Omega, Big Theta
28+
29+
- O(n): A Measure of the longest amount of time for an algorithm to complete(...e.g. <=)
30+
- Used in the worst case
31+
- Ω(n): A Measure of the shortest amount of time for an algorithm to complete(...e.g. >=)
32+
- Used in the Best Case
33+
- Θ(n): A Measure of the average amount of time for an algorithm to complete(...e.g. ==)
34+
- Used in the Average Case
35+
1236

1337
##### DS Operations
1438

@@ -22,54 +46,103 @@
2246

2347

2448
1. Stack
49+
2550
- Linear
2651
- LIFO/FILO
2752
- Dinner Plates
2853
- When items are pushed they are placed on the top
2954

3055
2. Linked List
56+
3157
- Sequential Order
3258
- No Random Access
3359
- Better alternative to Sets because they are dynamic
3460
- Chain of nodes. Every node contains data and a pointer to the subsequent node
3561
- Each unit is called a node
3662
- A Node is composed of data and a pointer
3763
- Last node has a null pointer i.e. the pointer is used but doesn't point to anything
64+
- Folders on your computer(i.e. last folder is null because it has no folder within it)
3865

3966
3. Array
67+
4068
- Indexed
4169
- When Size increases performance decreases
4270
- All the elements in the DS must be of the same type
71+
- Muffin/Egg Tray
72+
- Rectangular in shape
4373

4474
4. Queues
75+
4576
- Movie Theatre
4677
- FIFO
4778
- aka people waiting in line
79+
- Ordered Collection
80+
- Operations: add(), remove()
81+
82+
4883

4984
5. Hash Table
50-
- Contains an index and its corresponding Hash_Value
5185

5286

87+
- Contains an index and its corresponding Hash_Value
88+
- All items within it are unique
89+
- Cannot store null as a key nor as a value
90+
- First parameter within your Hash Table declaration is the data type of the key
91+
- Second parameter within your Hash Table declaration is the data type of the value
92+
5393
6. Trees
54-
- hierarchical Structure where data is org in a hierarchy and everything is linked together
94+
95+
- Hierarchical Structure where data is org in a hierarchy and everything is linked together
5596
- Not the same as linked list because LL is linear
5697
- Trees are faster to access than a LL because they are non-linear
5798
- Node: person who holds our data
99+
- Child Node: person who has a parent
100+
- Leaf Node: person who has no children
58101
- Edge: person who connects two nodes
59102
- Root: Person who is the topmost node
60103
- Node Height: # of edges from the node to the deepest leaf node
61104
- Node Depth: # of edges from the root to the node
62105
- Tree Height: Depth of the deepest node
63106
- Degree of A Node: Total # of branches of that node
64-
65-
66-
7. Heaps
107+
- Leaves: Person who has no children
108+
- Use when you want to store items in a hierarchial fashion
109+
- Quicker to access/search than a LL but slower than an Array
110+
- Binary Tree
111+
- Can Have 0,1,2 nodes
112+
- Binary Search Tree:
113+
- Used for sorting, getting and searching data
114+
- Non-linear
115+
- Arranged in some order
116+
- no duplicate vals
117+
- val on the left most subtree of the node is always smaller than the val on its immediate right
118+
- Node on the left is always less than the node on the right
119+
120+
121+
7. Heap
122+
123+
- Special Tree Based DS
67124
- Binary Tree
125+
- Patients Being Admitted to the Hospital
126+
- Patients with life-threatning situation get taken care of first
127+
- Patients that don't have threatening situation wait in line
68128
- Parent node makes a comparison with its child nodes and are arranged accordingly
129+
- Two Scenarios:
130+
- Key present at the root node is the greatest among all of its children and successors
131+
- Key present at the root node is the smallest among all of its children and successors
69132

70133
8. Graphs
134+
71135
- Finite set of vertices, nodes and edges. The edges are what connect one vertex with another
72136
- Graphs are connected in a network form
137+
- Non-linear
138+
- Nodes are the vertices(i.e. endpoints)
139+
- Edges are the lines/arcs that connect one node with another node
140+
- Two Types:
141+
- Directed
142+
- Undirected
143+
- Simple Graph: Each edge connects to two different vertices whereby no two edges connect to the same group of vertices
144+
- Multigraph: An edge can connect to the same pair of vertices
145+
-
73146

74147

75148

@@ -137,7 +210,7 @@ But actually the runtime is O(n) because when we calculate runtime we drop the c
137210

138211
1. Logarithmic growth slows down as the input size growth i.e d/dx[ln(x)] = 1/x whereas d/dx[2^n]= 2^nln(2)
139212

140-
2. exponential growth as you can see increases at an increasing rate whereas logarithmic growth increases at a decreasing rate
213+
2. Exponential growth as you can see increases at an increasing rate whereas logarithmic growth increases at a decreasing rate
141214

142215
3. However, exponential growth becomes slow sooner than logarithmic growth
143216

0 commit comments

Comments
 (0)