Complex Structures Nested Structures Self referential structures A structure may have Data variables Internal structures/unions Pointer links Function.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Chapter 6 Structures By C. Shing ITEC Dept Radford University.
Trees Types and Operations
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
Tree Data Structures &Binary Search Tree 1. Trees Data Structures Tree  Nodes  Each node can have 0 or more children  A node can have at most one parent.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
DictionaryADT and Trees. Overview What is the DictionaryADT? What are trees? Implementing DictionaryADT with binary trees Balanced trees DictionaryADT.
1 Chapter 6 Priority Queues (Heaps) General ideas of priority queues (Insert & DeleteMin) Efficient implementation of priority queue Uses of priority queues.
Department of Computer Science University of Maryland, College Park
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
COMP 110 Introduction to Programming Mr. Joshua Stough.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
Binary Trees – Part I CS 367 – Introduction to Data Structures.
Complex Structures Nested Structures Self referential structures A structure may have Data variables Internal structures/unions Pointer links Function.
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
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.
Binary Search Tree For a node: The left subtree contains nodes with keys less than the node's key. The right subtree contains nodes with keys greater than.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Information and Computer Sciences University of Hawaii, Manoa
Binary Trees Chapter Definition And Application Of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two.
BINARY SEARCH TREE. Binary Trees A binary tree is a tree in which no node can have more than two children. In this case we can keep direct links to the.
Trees Dr. Andrew Wallace PhD BEng(hons) EurIng
 Trees Data Structures Trees Data Structures  Trees Trees  Binary Search Trees Binary Search Trees  Binary Tree Implementation Binary Tree Implementation.
Lec 15 Oct 18 Binary Search Trees (Chapter 5 of text)
Lecture1 introductions and Tree Data Structures 11/12/20151.
Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use at Midwestern State University Chapter.
Programming Practice 3 - Dynamic Data Structure
Chapter 19: Binary Search Trees or How I Learned to Love AVL Trees and Balance The Tree Group 6: Tim Munn.
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.
CISC 235 Topic 3 General Trees, Binary Trees, Binary Search Trees.
1/14/20161 BST Operations Data Structures Ananda Gunawardena.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
Doubly Linked List Exercises Sometimes it is useful to have a linked list with pointers to both the next and previous nodes. This is called a doubly linked.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
CS6045: Advanced Algorithms Data Structures. Dynamic Sets Next few lectures will focus on data structures rather than straight algorithms In particular,
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
BSTs, AVL Trees and Heaps Ezgi Shenqi Bran. What to know about Trees? Height of a tree Length of the longest path from root to a leaf Height of an empty.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
CSCE 3110 Data Structures & Algorithm Analysis
CSCE 3110 Data Structures & Algorithm Analysis
5.13 Recursion Recursive functions Functions that call themselves
Lectures linked lists Chapter 6 of textbook
12 C Data Structures.
12 C Data Structures.
Binary search tree. Removing a node
Data Structures for Databases
Lecture 22 Binary Search Trees Chapter 10 of textbook
Tree data structure.
Chapter 20: Binary Trees.
Chapter 21: Binary Trees.
Lec 12 March 9, 11 Mid-term # 1 (March 21?)
Tree data structure.
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Search Sorted Array: Binary Search Linked List: Linear Search
Review & Lab assignments
CS6045: Advanced Algorithms
Binary Trees, Binary Search Trees
Chapter 20: Binary Trees.
Search Sorted Array: Binary Search Linked List: Linear Search
BY PROF. IRSHAD AHMAD LONE.
Linked Lists.
Presentation transcript:

Complex Structures Nested Structures Self referential structures A structure may have Data variables Internal structures/unions Pointer links Function pointers struct course { int course_num; struct student[20]; struct course *next; int (*average)(int []); };

Dynamic Structures Link Lists A type of data structure that have its elements linked together Generic on-demand dynamic structure Easy manipulation, but may not be efficient Trees A type of data structures in which elements are connected in a tree form Complex data structures More efficient, use only if the number of elements are large

Link Lists Single Link Lists head Double Link lists head struct slink { int data; struct slink *next; }; struct dlink { int data; struct dlink *next; struct dlink *prev; };

Other Link Lists Hash link lists bin[size] Other variants: queues and stacks Queue: a link list grown at one end, shrink at another, i.e. FIFO Stack: a LIFO link list

Trees – binary trees root struct node { int data; struct node *left; struct node *right; }; rightleft leaf height

More Trees Tertiary Trees Each node has three children K-ary Trees Each node has K children B (Balanced)- Trees A tree that maintains a balanced height as it grows/shrinks …

Sample Usage Important functions insert delete search … Maintain a dynamic structure of sorted numbers using any of the previous structures

Double link list void insert (struct dlink *head, struct dlink *entry) { struct dlink *tmp; for (tmp = head->next; tmp!= head && tmp- >data data; tmp = tmp->next); tmp->prev->next = entry; entry->prev= tmp->prev; tmp->prev = entry; entry->next = tmp; }; void delete (struct dlink *entry) { entry>next->prev = entry->prev; entry>prev->next = entry->next; entry->next = entry->prev = NULL; }; struct dlink * search (struct dlink *head, int val) { struct dlink * tmp; for (tmp = head->next; tmp!= head && tmp->data != val; tmp = tmp->next); return (tmp==head)? NULL : tmp; } int main() { struct dlink num[10] = { … }; struct dlink head={0, NULL, NULL}; for (int i=0; i<10; i++) insert (&head, &num[i]); … return 0; }

Binary Search Tree void insert (struct node *root, struct node *entry) { /* where to insert is really algorithm dependent. A generic case only: entry is to replace the left node of head */ if (head->left) { entry->left = head->left->left; entry->right = head->left->right; } head->left = entry; }; void delete ( struct node *root, struct node *entry) { /* The key is to find a node that has an entry as a child */ }; struct node * search (struct node *root, int val) { if (!root) return NULL; else if (root->data != val) tmp = search(root->left, val); if (!tmp) tmp = search(root->right, val); return tmp; } int main() { struct node num[10] = { … }; struct node root = {0, NULL, NULL}; for (int i=0; i<10; i++) { insert (&root, &num[i]); } … return 0; }