Download presentation
Presentation is loading. Please wait.
Published byBeverly Phelps Modified over 9 years ago
1
CSE205 Review Session SAMUEL & JESSA
2
Recursion
3
WHAT IS RECURSION? Recursion is a tool a programmer can use to invoke a function call on itself. Recursive methods contain a base case, and a function call, calling itself. Common recursion problems involve the Fibonacci sequence, or solving factorials. Transform iterative methods to become recursive methods. BASE CASE DON’T FORGET YOUR BASE CASE
4
*Factorial: Iterative vs Recursion
5
Recursive method walk through Given n = 5, when we call this function recursively we will get a value of 5*4*3*2*1*1; Note that there are 2 1’s. This comes from the base case
6
*Merge Sort 3 steps to merge sort Cut the array in half Recursively Sort each half Merge the two halves together Benefits: Dramatically faster than other sorting methods like insertion sort, quicksort
7
Quick Sort Quick Sort uses the divide and conquer strategy. Step 1: Partition the set/range Step 2: Sort each following partition To partition, we can select a pivot point. Here we can select the first element given an array
8
*Linked Lists A linked list is a data structure which consists of a group of nodes, when grouped together represent a sequence. Each node is composed of some form of data, and a reference(link/pointer). Benefits of Linked Lists: Linked lists can represent a dynamic set. Linked lists are not static, therefore can be changed in size. This helps with insertion and deletion within a sequence.
9
Insertion in Linked Lists
10
Deletion in Linked List To remove something from a linked list, we take the previous node, and set its “next”, to the node we are going to deletes “next”. This removes the link to the unwanted node. Java handles the rest
11
*Stacks/Queues Stacks: Last in first out (LIFO) *Push (Adds to top of stack) *Pop (Removes top of stack) *Peek (Shows top of stack) Queues: First in first out (FIFO) *Enqueue (Adds to queue) *Dequeue (Removes from queue)
12
Binary Search Tree Traversal Confused on how to traverse a tree through Pre order, in order and post order traversal? Use this trick: For pre order: Place a dot on the left of each node in a binary tree For in order: Place a don’t on the bottom of each node in a binary tree For post order: Place a don’t on the right of each node in a binary tree
13
Tree traversal continued Start from the top of the node, and traverse through the binary tree going counter clockwise. Whenever you encounter the dot you just placed, write down that node to your list accordingly. Pre-Order: F, B, A, D, C, E, G, I, H
14
In-order: A, B, C, D, E, F, G, H, I
15
Post-order: A, C, E, D, B, H, I, G, F
16
Heaps Heaps are a binary tree but with two distinct properties 1. It is nearly complete, with the exception of the lowest level, filling in left from right 2. Heaps fulfill the heap property, each parent node is smaller than both of its child nodes.
17
Questions?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.