Professional Documents
Culture Documents
head_ptr -> 4.0 -> 3.0 -> 2.0 -> 1.0 -> NULL
o Node* head_ptr = new node(1.0, NULL);
o head_ptr = new node(2.0, head_ptr);
o head_ptr = new node(3.0, head_ptr);
o Graph Traversal
Inorder: traverse left subtree, visit root, right
subtree
Preorder: visit root, left subtree, right subtree
Postorder: traverse left subtree, right subtree, root
Search
o DFS: Depth first search; Uses Stack
Go as deeply as possible, if terminal node, go up to
closest node
o BFS: Breadth first search; Uses Queue
From each vertex, visit all adjacent to it and then
repeat for all vertices (visit all nodes of same level
first)
o Sequential search
Worst case O(n) comparisons needed
Checks every element, from first to last, until the
desired element is found
o Binary search
Best Case: O(log n)
Worst Case: O(n)
Precondition: array should be sorted in ascending
order
Compares desired value to the center of the
sorted array then adjusts left or right limit
depending on whether or not it is too big or too
small
Hashing: take a data type and assign an integer value to it
(sorting it into array and can then be accessed based on that
integer value)
o Collision: 2 nonidentical data types are hashed into same
address
Ways around collision:
Propping: simply add it to the next open index
Chaining: adding data type to a linked list at
that index
Sort
o Insertion sort: O(n2)
Data Structure:
Starts at beginning then makes comparison (>, < ,
=) until it is failed (2 for loops, one to go through all
items needed to be sorted and the other to actually
do the sorting process)
o Selection sort:
Data Structure: Array