Computer Science Notes

Notes From CS Undergrad Courses FSU

This project is maintained by awa03

Why We Need To Know

We need to know which data structure to utilize within certain use cases so that we may optimize our program's functionality as well as usability. We need to know when to use these structures and how to implement them.

Time Complexity Of Data Structures

Operation Vector Linked List Deque Tree (Unordered) Hashtable (Unordered)
Insert front O(n) O(1) O(1) O(log(n)) NA
Insert Back O(1) O(1) O(1) O(log(n)) NA
Insert Middle O(n) O(1) O(N) O(log(n)) O(1)*
Remove Front O(n) O(1) O(1) O(log(n)) NA
Remove back O(1) O(1) O(1) O(log(n)) NA
Remove Middle O(n) O(1) O(n) O(log(n)) O(1)*
Random Access O(1) O(n) O(1) O(log(n)) NA
Search O(n) O(n) O(n) O(log(n)) O(1)*

Theory and Terminology

Tree

- The tree is a connected graph with no cycles (no circles) - Consequences: - Between any two vertices, there is exactly one unique path

Rooted Tree

- A rooted tree - is connected - has no cycles - has exactly one vertex called the root of the tree - Consequences - Can be arranged so that the root is at the top - parent vs. child nodes and edges - sibling nodes - Nodes of the same parent nodes - leaf nodes - Nodes without children nodes

![[rooted_tree 1 1.jpeg]]

![[aBbeM 1.jpg]]

Rooted Tree: Recursive Definition

// Tree Node 
struct TreeNode{
	Object element;
	TreeNode *firstChild;
	TreeNode *nextSibling;
}

Tree Traversal

Step Description
1 Go to the root
2 Visit child subtrees

Postorder Transversal

Inorder Transversal

Preorder Transversal

![[Screenshot Capture - 2023-10-04 - 16-10-55 1.png]]

Binary Tree

![[bvst 1.png]]

A complete binary tree with n vertices and h height satisfies