CSE205 Review Session SAMUEL & JESSA. Recursion WHAT IS RECURSION?  Recursion is a tool a programmer can use to invoke a function call on itself. 

Slides:



Advertisements
Similar presentations
Trees Types and Operations
Advertisements

CS 171: Introduction to Computer Science II
Data Structures, Search and Sort Algorithms Kar-Hai Chu
Trees Chapter 8.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ETC - 1 What comes next? Recursion (Chapter 15) Recursive Data Structures.
Fall 2007CS 2251 Iterators and Tree Traversals. Fall 2007CS 2252 Binary Trees In a binary tree, each node has at most two subtrees A set of nodes T is.
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L12 (Chapter 20) Lists, Stacks,
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Source: Muangsin / Weiss1 Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Chapter 18 - basic definitions - binary trees - tree traversals Intro. to Trees 1CSCI 3333 Data Structures.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Trees, Binary Search Trees, Recursion, Project 2 Bryce Boe 2013/08/01 CS24, Summer 2013 C.
F453 Computing Searches. Binary Trees Not this kind of tree!
Recursion Bryce Boe 2013/11/18 CS24, Fall Outline Wednesday Recap Lab 7 Iterative Solution Recursion Binary Tree Traversals Lab 7 Recursive Solution.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Chapter 15: Advanced Topics: Introducing Data Structures and Recursion Visual Basic.NET Programming: From Problem Analysis to Program Design.
Information and Computer Sciences University of Hawaii, Manoa
Midterm Review CSE 2011 Winter October 2015.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
9-1 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified independently of any particular implementation.
ACM/JETT Workshop - August 4-5, 2005 Using Visualization Tools To Teach Data Structures and Algorithms Java applets by Dr. R. Mukundan, University of Canterbury,
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
Outline Binary Trees Binary Search Tree Treaps. Binary Trees The empty set (null) is a binary tree A single node is a binary tree A node has a left child.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Grammars and Parsing  Recursive Definitions of Properties.
Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.
Final Exam Review CS Total Points – 60 Points Writing Programs – 50 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Priority Queues and Heaps. October 2004John Edgar2  A queue should implement at least the first two of these operations:  insert – insert item at the.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
CS223 Advanced Data Structures and Algorithms 1 Priority Queue and Binary Heap Neil Tang 02/09/2010.
CSS446 Spring 2014 Nan Wang.  to study trees and binary trees  to understand how binary search trees can implement sets  to learn how red-black trees.
Heaps and basic data structures David Kauchak cs161 Summer 2009.
Foundation of Computing Systems Lecture 4 Trees: Part I.
More Binary Search Trees, Project 2 Bryce Boe 2013/08/06 CS24, Summer 2013 C.
Final Exam Review CS Total Points – 20 Points Writing Programs – 65 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Data Structures -3 rd exam- 授課教授:李錫智. 1.[10] Suppose we want to implement a queue by using the following List operations: getLength(); remove(position);
Course: Programming II - Abstract Data Types HeapsSlide Number 1 The ADT Heap So far we have seen the following sorting types : 1) Linked List sort by.
CS6045: Advanced Algorithms Data Structures. Dynamic Sets Next few lectures will focus on data structures rather than straight algorithms In particular,
ISOM MIS 215 Module 5 – Binary Trees. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
CPS120: Introduction to Computer Science Sorting.
Final Exam Review CS 3358.
Data Structures and Algorithms
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
Trees Chapter 15.
12 C Data Structures.
Tree.
March 31 – Priority Queues and the heap
Binary Search Tree In order Pre order Post order Search Insertion
Data Structures and Algorithms
Chapter 17 Object-Oriented Data Structures
ITEC 2620M Introduction to Data Structures
Lesson 6. Types Equality and Identity. Collections.
Binary Tree Traversals
CS6045: Advanced Algorithms
DATA STRUCTURE.
EE 312 Final Exam Review.
Non-Linear data structures
Presentation transcript:

CSE205 Review Session SAMUEL & JESSA

Recursion

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

*Factorial: Iterative vs Recursion

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

*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

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

*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.

Insertion in Linked Lists

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

*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)

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

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

In-order: A, B, C, D, E, F, G, H, I

Post-order: A, C, E, D, B, H, I, G, F

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.

Questions?