Lists and Trees (continued) CS-2301, B-Term 20091 Lists and Trees (continued) CS-2301, System Programming for Non-Majors (Slides include materials from.

Slides:



Advertisements
Similar presentations
Linked Lists in C and C++ CS-2303, C-Term Linked Lists in C and C++ CS-2303 System Programming Concepts (Slides include materials from The C Programming.
Advertisements

1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
Trees 2 and Doubly Linked Lists As you arrive: Please snarf today’s code.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
Advanced Data Structures
Binary TreesCS-2303, C-Term Binary Trees (and Big “O” notation) CS-2303 System Programming Concepts (Slides include materials from The C Programming.
Linked Lists in C and C++ CS-2303, C-Term Linked Lists in C and C++ CS-2303 System Programming Concepts (Slides include materials from The C Programming.
More on Dynamic Memory Allocation Seokhee Jeon Department of Computer Engineering Kyung Hee University 1 Illustrations, examples, and text in the lecture.
Linked Lists in C and C++ By Ravi Prakash PGT(CS).
CS 171: Introduction to Computer Science II
Trees Chapter 8.
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Lists and TreesCS-2301 D-term Data Structures — Lists and Trees CS-2301 System Programming D-term 2009 (Slides include materials from The C Programming.
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.
More on Data Structures in C CS-2301 B-term More on Lists and Trees Introduction to Hash Tables CS-2301, System Programming for Non-majors (Slides.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Hash TablesCS-2301, B-Term Hash Tables and Constant Access Time CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming.
BST Data Structure A BST node contains: A BST contains
More on Data Structures in C CS-2301 D-term More on Data Structures in C CS-2301 System Programming D-term 2009 (Slides include materials from The.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
Data Structures, Lists, and Trees CS-2301 B-term Data Structures — Lists and Trees CS-2301, System Programming for Non-majors (Slides include materials.
Data Structures — Lists and Trees CS-2301, B-Term Data Structures — Lists and Trees CS-2301, System Programming for Non-Majors (Slides include materials.
Binary Search Trees Chapter 7 Objectives
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Trees.
Chapter Tow Search Trees BY HUSSEIN SALIM QASIM WESAM HRBI FADHEEL CS 6310 ADVANCE DATA STRUCTURE AND ALGORITHM DR. ELISE DE DONCKER 1.
Trees. Tree Terminology Chapter 8: Trees 2 A tree consists of a collection of elements or nodes, with each node linked to its successors The node at the.
1 Data Structures Lists and Trees. 2 Real-Life Computational Problems All about organizing data! –What shape the data should have to solve your problem.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Tree.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
S EARCHING AND T REES COMP1927 Computing 15s1 Sedgewick Chapters 5, 12.
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.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
1 Binary Trees Informal defn: each node has 0, 1, or 2 children Informal defn: each node has 0, 1, or 2 children Formal defn: a binary tree is a structure.
Data Structure Chapter# 5 Tree Course Instructor AMEER JAMAL SHAH.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Review for Final Exam – cs411/511 Definitions (5 questions, 2 points each) Algorithm Analysis (3 questions, 3 points each) General Questions (3 questions,
Binary Trees In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left.
1 Chapter 7 Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation of the binary search tree.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Binary Search Trees (BST)
Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 7 Objectives Create and implement binary search trees Understand the operation.
Searching Topics Sequential Search Binary Search.
Trees Ellen Walker CPSC 201 Data Structures Hiram College.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Trees CSIT 402 Data Structures II 1. 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical.
Chapter 12 – Data Structures
Trees Chapter 15.
Data Structure and Algorithms
COMP 53 – Week Fourteen Trees.
Fundamentals of Programming II Introduction to Trees
Sections 8.7 – 8.8 Balancing a Binary Search Tree.
Week 6 - Wednesday CS221.
Binary Search Tree (BST)
Tree.
Section 8.1 Trees.
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
Programming Assignment #4 Binary Trees in C++
Linked Lists in C and C++
Binary Trees (and Big “O” notation)
Binary Search Trees Chapter 7 Objectives
Chapter 20: Binary Trees.
Presentation transcript:

Lists and Trees (continued) CS-2301, B-Term Lists and Trees (continued) CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie and from C: How to Program, 5 th and 6 th editions, by Deitel and Deitel)

Lists and Trees (continued) CS-2301, B-Term Reminder – Definitions Linked List A data structure in which each element is dynamically allocated and in which elements point to each other to define a linear relationship Singly- or doubly-linked Stack, queue, circular list Tree A data structure in which each element is dynamically allocated and in which each element has more than one potential successor Defines a partial order

Lists and Trees (continued) CS-2301, B-Term Definitions (continued) Binary Tree A tree in which each element has two potential successors Subtree The set of nodes that are successors to a specific node, either directly or indirectly Root of a tree The node of the tree that is not the successor to any other node, all other nodes are (directly or indirectly) successors to it

Lists and Trees (continued) CS-2301, B-Term Binary Tree A linked list but with two links per item struct treeItem { type payload; treeItem *left; treeItem *right; }; leftright payload leftright payload leftright payload leftright payload leftright payload leftright payload leftright payload

Lists and Trees (continued) CS-2301, B-Term Binary Trees (continued) Two-dimensional data structure Easy to grow and shrink Easy to add and delete items at leaves More work needed to insert or delete branch nodes Search time is O(log n) If tree is reasonably balanced Degenerates to O(n) in worst case if unbalanced

Lists and Trees (continued) CS-2301, B-Term Order of Traversing Binary Trees In-order Traverse left sub-tree (in-order) Visit node itself Traverse right sub-tree (in-order) Pre-order Visit node first Traverse left sub-tree Traverse right sub-tree Post-order Traverse left sub-tree Traverse right sub-tree Visit node last

Lists and Trees (continued) CS-2301, B-Term Question What order should you traverses the tree for Programming Assignment #5?

Lists and Trees (continued) CS-2301, B-Term Another Example of Binary Tree x = (a.real*b.imag - b.real*a.imag) / sqrt(a.real*b.real – a.imag*b.imag) = x/ sqrt - **.. arealbimag.. brealaimag - …

Lists and Trees (continued) CS-2301, B-Term Question What kind of traversal order is required for this expression? In-order? Pre-order? Post-order?

Lists and Trees (continued) CS-2301, B-Term Binary Trees in Compilers Used to represent the structure of the compiled program Optimizations Common sub-expression detection Code simplification Loop unrolling Parallelization Reductions in strength – e.g., substituting additions for multiplications, etc. Many others

Lists and Trees (continued) CS-2301, B-Term Questions about Trees? or about Programming Assignment 6?

Lists and Trees (continued) CS-2301, B-Term “Big O” notation New Topic

Lists and Trees (continued) CS-2301, B-Term Linked Lists Again Linear data structure Easy to grow and shrink Easy to add and delete items Time to search for an item – O(n) I.e., proportional to n, the number of items in the list

Lists and Trees (continued) CS-2301, B-Term Binary Trees Again Non-linear data structure Easy to grow and shrink Easy to add and delete items Time to search for an item – O(log n) I.e., proportional to log of number of items in the list

Lists and Trees (continued) CS-2301, B-Term Definition — Big-O “Of the order of …” A characterization of the number of operations in an algorithm in terms of a mathematical function of the number of data items involved O(n) means that the number of operations to complete the algorithm is proportional to n E.g., searching a list with n items requires, on average, n/2 comparisons with payloads

Lists and Trees (continued) CS-2301, B-Term Big-O (continued) O(n): proportional to n – i.e., linear O(n 2 ): proportional to n 2 – i.e., quadratic O(k n ) – proportional to k n – i.e., exponential … O(log n) – proportional to log n – i.e., sublinear O(n log n) Worse than O(n), better than O(n 2 ) O(1) – independent of n; i.e., constant

Lists and Trees (continued) CS-2301, B-Term Anecdote & Questions:– In the design of electronic adders, what is the order of the carry-propagation? What is the order of floating point divide? What is the order of floating point square root? What program have we studied in this course that is O(2 n )? i.e., exponential?

Lists and Trees (continued) CS-2301, B-Term Questions on Big-O?