Do you remember what is the most powerful tool for managing complexity?
|
|
- Joshua Turner
- 6 years ago
- Views:
Transcription
1
2 Do you remember what is the most powerful tool for managing complexity? 2
3 Abstractions and more abstractions You are here 3
4 8.1 Three views of data Application or user level Logical or abstract level Implementation level Abstract Data Types (ADTs) are here! Data Structures are here! 4
5 Abstract Data Type (ADT) Abstract data type = A data type whose properties (data and operations) are specified independently of any particular implementation. The terms container and black-box are used to describe ADTs. Python strings and lists have their own methods attached to them, e.g. my_list.sort()! 5
6 8.2 Stacks Stack = An ADT in which accesses are made at only one end LIFO = Last In First Out The insert is called Push and the removal is called Pop Name three everyday structures that are stacks 6
7 Stack example: Towers of Hanoi Tower of Hanoi - Wikipedia, the free encyclopedia 7
8 Stack algorithms Placing elements in the stack: WHILE (more data) Read value push(mystack, value) Removing elements from the stack: 8 WHILE (NOT IsEmpty(myStack)) value = pop(mystack) Write value
9 Example A stack is initially empty. Draw the stack after each of these operations: push(42) push(15) push(10) pop() push(21) pop() pop() 9
10 QUIZ: Stacks A stack contains initially only the number 42. Draw the stack at the end of this sequence operations: push(10) push(11) pop() push(12) pop() push(101) push(102) pop() 10
11 Solution This is the stack at the end: push(10) push(11) pop() push(12) pop() push(101) push(102) pop()
12 8.3 Queues Queue = An ADT in which items are inserted at one end and removed from the other end FIFO = First In First Out No standard queue terminology Enqueue, Enque, Enq, Enter, and Insert are used for the insertion operation Dequeue, Deque, Deq, Delete, and Remove are used for the removal operation. Name three everyday structures that are queues 12
13 Interesting trivia: queueing is one of only two words in the English language that has 5 vowels in a row! E.g. Queueing Theory The other one is miaouing (miaoued?) 4 vowels in a row is more common: queue (!), aqueous, onomatopoeia, sequoia, archaeoastronomy, etc. 13
14 Queue algorithms Placing elements in the queue: WHILE (more data) Read value enque(myqueue, value) Removing elements from the queue: WHILE (NOT IsEmpty(myQueue)) value = deque(myqueue) Write value
15 QUIZ A queue is initially empty. Draw the queue after each of these operations: enque(42) enque(15) enque(10) deque() enque(21) deque() deque() 15
16 ADTs are also called containers. What exactly does the stack container contain? The data stored on that stack The main functions push( ), pop( ) Other functions isfull( ), isempty( ), peek( ),
17 Two implementations for ADTs Array-based implementation Objects in the container are kept in an array, i.e. physically next to each other in memory. Linked-based implementation Objects in the container are not kept physically together, but each item tells you where to go to get the next one in the structure Did you ever play treasure hunt, a game in which each clue tells you where to go to get the next clue? 17
18 Array implementation Memory maps for Linked implementation 18
19 Stacks and Queues in the linked implementation 19
20 Why access elements only at the ends? 20
21 8.4 Lists List are more general ADTs than stacks and queues There is an index for the current item (crt) that can move through the list. Access takes place in position crt 21
22 Operations that can be applied to lists: Insert item New item goes before old crt crt points to new item Delete item New item into list at position crt Remove the crt item from the list Move crt left (except when at tail of list, in which case crt points to the new tail) Get Next item Get the crt item Move crt right (if at end of list set crt = NULL) More items Reset Are there more items at crt? Brings crt back to head of list 22
23 Linked-list implementation crt 23
24 Array implementation of list crt Big problem: insertion and deletion require shifting the tail of the array timeconsuming! Details in CS Data Structures!
25 QUIZ: Show the list and the outputs (if any) after each of the following operations: getnext() getnext() delete() getnext() insert(42) moreitems() getnext() getnext() getnext() reset() 25
26 Algorithm for creating a list and printing its elements WHILE (more data) Read value Insert(myList, value) Reset(myList) Write "Items in the list are " WHILE (moreitems(mylist)) GetNext(myList, nextitem) Write nextitem, ' ' movenext(mylist) Brings crt back to the head of the list Trick question: Which implementation is being used (array or linked)? 26
27 Logical Level The algorithm that uses the list does not need to know how the data in the list is stored (array or linked), or how the various operations (Insert(), Reset(), moreitems()) are implemented! We have written algorithms using a stack, a queue, and a list without ever knowing the internal workings, i.e. the implementation of these containers. 27
28 8.5 Trees Structure such as lists, stacks, and queues are linear in nature; only one relationship is being modeled Other (more or less complex) relationships require different structures 28
29 Binary Tree (BT) Root node Node with two children Node with right child Leaf node Node with left child 29
30 To do for next time: Read Sections 8.1, 8.2, 8.3 End-of-chapter 1 5, 12, 13, 14 EOL 2 30
31 It is possible to implement BTs with arrays, but Binary tree = A linked container with a unique starting node called the root, in which each node can have up to two child nodes A node can have 0, 1, or 2 children A unique path (series of nodes) exists from the root to every other node. There are no loops! 31
32 QUIZ BT Write the (unique) path from the root to the node containing:
33 Operations on lists: Insert item New item goes before old crt crt points to new item Delete item New item into list at position crt Remove the crt item from the list Move crt left (except when at head of list) Get next item Get the crt item Move crt right (if at end of list set crt = NULL) More items Reset Are there more items at crt? Brings crt back to head of list 33
34 QUIZ: Show the list (and crt) at the end of the following sequence: insert(42) delete() moreitems() getnext() getnext( delete() delete() delete() getnext() getnext() 34
35 QUIZ BT 0 children 1 child 2 children List all the nodes having: 35
36 QUIZ: Are these Trees? BTs? 36
37 QUIZ: Are these Binary Trees?
38 QUIZ CONCLUSIONS: Trees Have one (and only one) root Have directed edges There is one path from the root to any other node The path above is unique In addition, Binary Trees have to satisfy: Any node can have only 0, 1, or 2 children
39 Putting a BT to work: Binary Search Tree (BST) Do you notice a pattern in this BT? 39
40 Binary Search Tree = A tree with the following properties: 1. Shape property It is a binary tree 2. Semantic property For every node, the value stored in the node is greater than the value in any node in its left subtree and smaller than the value in any node in its right subtree x <X >X 40
41 QUIZ: Are these Binary Search Trees?
42 Algorithm for searching an item in a BST IsThere(tree, item) IF (tree is null) RETURN FALSE ELSE IF (item equals info(tree)) RETURN TRUE ELSE IF (item < info(tree)) IsThere(left(tree), item) ELSE IsThere(right(tree), item) Recursive! 42
43 QUIZ BST: Search for item 18 IsThere(tree, item) IF (tree is null) RETURN FALSE ELSE IF (item equals info(tree)) RETURN TRUE ELSE IF (item < info(tree)) IsThere(left(tree), item) ELSE IsThere(right(tree), item) 43
44 QUIZ: What s the difference between a BT and a BST? 44
45 Inserting an item in a BST: first we have to search for it! Search for Kyrsten in this tree 45
46 Inserting an item in a BST: first we have to search for it! Search for kyrsten in this tree and insert the item where the search ended! 46
47 Insert(tree, item) IF (tree is null) Put item in a new tree ELSE IF (item < info(tree)) Insert (left(tree), item) ELSE Insert (right(tree), item) Note how similar this algorithm is to the search algorithm! 47
48 QUIZ on BST insertion Problem 47/280: The following elements are inserted in an initially empty BST: 50, 72, 96, 107, 26, 12, 11, 9, 2, 10, 25, 51, 16, 17, 95 Find the final tree. 48
49 Extra-credit QUIZ: 49
50 QUIZ What do the acronyms BT and BST mean in Computer Science? How is a BT similar to a BST? How is a BT different from a BST? 50
51 Binary Search Tree = A tree with the following properties: 1. Shape property It is a binary tree 2. Semantic property For every node, the value stored in the node is greater than the value in any node in its left subtree and smaller than the value in any node in its right subtree x <X >X 51
52 QUIZ on BST insertion The following elements are inserted in an initially empty BST: Hello, world!, COSC 1302, MATH 2412, PHYS 2425, ENGL 1301, ENGL 1302 Show the final tree. 52
53 Printing/traversing a BST Print(tree) If (tree is not null) Print (left(tree)) Write info(tree) Print (right(tree)) Is that all there is to it? Yes! Remember that recursive algorithms can be very powerful 53
54 Printing/traversing a BST Print(tree) If (tree is not null) Print (left(tree)) Write info(tree) Print (right(tree)) This is called in-order traversal 54
55 QUIZ: Printing/traversing a BST Print(tree) If (tree is not null) Print (left(tree)) Write info(tree) Print (right(tree)) Apply the algorithm to this BST. Show all output. 55
56 FYI: Other tree algorithms Finding the depth of a tree: Depth(tree) IF (tree is null) RETURN 0 ELSE RETURN max(depth(left(tree), Depth(right(tree))) Finding the length of a tree: Length(tree) IF (tree is null) RETURN 0 ELSE RETURN 1 + Length(left(tree))+ Length(right(tree))
57 8.6 Graphs Graph = A data structure that consists of a set of nodes (called vertices) and a set of edges that connect nodes to each other. Note: The unique path condition from trees has been removed; graphs are more general than trees! 57
58 Graphs: Unlike trees, there can be cycles and unconnected parts 58
59 QUIZ: Find 5 different cycles in this graph 59
60 QUIZ: In each case, decide if the data structure is a tree or just a graph 60
61 Graphs: directed and undirected 61
62 62 Graphs
63 Representing a Graph: adjacency matrix Our text simply calls it table See Table 8.3/262 63
64 QUIZ: Draw the adjacency matrix for this graph EOL 3 64
65 65 Graph Algorithms
66 Depth-First Searching Algorithm--Given a starting vertex and an ending vertex, we can develop an algorithm that finds a path from startvertex to endvertex This is called a depth-first search because we start at a given vertex, we go to the deepest branch and explore as far down one path before taking alternative choices at earlier branches. 66
67 DFS Stack to the rescue! startvertex endvertex Push the start vertex 67
68 DFS Stack to the rescue! startvertex endvertex Pop the start vertex, then push its children (in alphabetical order) 68
69 DFS Stack to the rescue! startvertex endvertex Unleash recursion! Figure 8.11 Using a stack to store the routes 69
70 DFS Nitty gritty: How to avoid loops? startvertex endvertex Mark each node when we push it. Figure 8.11 Using a stack to store the routes 70
71 DFS Nitty gritty: When to stop? startvertex endvertex A node is considered visited when popped (not when pushed) Figure 8.11 Using a stack to store the routes 71
72 QUIZ DFS: Find a path from Austin to Chicago Show all the steps! 72
73 Depth First Search(startVertex, endvertex) Set found to FALSE Push(myStack, startvertex) WHILE (NOT IsEmpty(myStack) AND NOT found) Pop(myStack, tempvertex) IF (tempvertex equals endvertex) Write endvertex Set found to TRUE ELSE IF (tempvertex not visited) Write tempvertex Push all unvisited vertices adjacent to tempvertex Mark tempvertex as visited IF (found) Write "Path has been printed" ELSE Write "Path does not exist") And mark pushed vertex as visited 73
74 Graph Algorithms Depth-First Search (DFS) algorithm It looks so easy do we really need an algorithm for it? 74
75 Source: 75
76 76 Is this the only path from Austin to Washington?
77 77 Is this the shortest path from Austin to Washington?
78 What if there were a direct path Dallas Washington?
79 Conclusion on DFS: The algorithm is guaranteed to find a path (if at least one exists) between the given vertices Not all paths Not (in general) the shortest path To find all, or the shortest path, we need to use different algorithms 79
80 Other Graph Algorithms Breadth-First Search (BFS) Single-Source Shortest-Path Search (SSPS) Skip them in our text! All-Pairs Shortest Path Search Flow algorithms Etc. etc. etc. 80
81 SKIP 8.7 Subprogram Statements READ and take notes: Ethical issues: Workplace Monitoring 81
82 Chapter Review Questions Distinguish between an array-based implementation and a linked implementation Distinguish between an array and a list Distinguish between and a unsorted list and a sorted list Distinguish between the behavior of a stack and a queue Distinguish between the binary tree and a binary search tree 82
83 Chapter Review Questions Draw the binary search tree that is built from inserting a series of items Understand the difference between a tree and a graph Use the DFS algorithm to find a path between two nodes of a graph. 83
84 Who am I? In the 1940s, the new computer architecture I developed revolutionized the design of computers. Today s computers are referred to as [my last name] machines because the architectural principles I described have proven very successful. 84
85 Do you know? What are some of the economic stimulus scams uncovered by the IRS in 2007? What is the Open Source Hardware Bank (OSHB)? Explain its connection to improving the function and expanding the capabilities of hardware How does graph theory relate to terrorist detection? 85
86 Homework for Ch.8 31, 32, 34, 35, 37, 38, 47, 48, Table means adjacency matrix. 56 Instead of Sandler, let the destination be Fred. The edges are all bidirectional (they go both ways). Remember that we push nodes on the stack in alphabetical order. 86
QUIZ QuickSort (Ch.7)
QUIZ QuickSort (Ch.7) 42 55 23 1-4 100 43 44 8 7 6 5 20 Do you remember what is the most powerful tool for managing complexity? 3 Remember from Ch.7: Three types of abstraction Data abstraction Separation
More informationChapter 9 Abstract Data Types and Algorithms
Chapter Goals Chapter 9 Abstract Data Types and Algorithms Define an abstract data type and discuss its role in algorithm development Distinguish between a data type and a data structure Distinguish between
More informationChapter 9. Priority Queue
Chapter 9 Priority Queues, Heaps, Graphs Spring 2015 1 Priority Queue Priority Queue An ADT in which only the item with the highest priority can be accessed 2Spring 2015 Priority Depends on the Application
More informationName CPTR246 Spring '17 (100 total points) Exam 3
Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 04 / 06 / 2018 Instructor: Michael Eckmann Today s Topics Questions? Comments? Graphs Definition Terminology two ways to represent edges in implementation traversals
More informationCS 1114: Implementing Search. Last time. ! Graph traversal. ! Two types of todo lists: ! Prof. Graeme Bailey.
CS 1114: Implementing Search! Prof. Graeme Bailey http://cs1114.cs.cornell.edu (notes modified from Noah Snavely, Spring 2009) Last time! Graph traversal 1 1 2 10 9 2 3 6 3 5 6 8 5 4 7 9 4 7 8 10! Two
More informationINSTITUTE OF AERONAUTICAL ENGINEERING
INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech
More information12 Abstract Data Types
12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define
More informationGraphs & Digraphs Tuesday, November 06, 2007
Graphs & Digraphs Tuesday, November 06, 2007 10:34 PM 16.1 Directed Graphs (digraphs) like a tree but w/ no root node & no guarantee of paths between nodes consists of: nodes/vertices - a set of elements
More informationTopics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302
Topics VCU, Department of Computer Science CMSC 302 Trees Vojislav Kecman Terminology Trees as Models Some Tree Theorems Applications of Trees Binary Search Tree Decision Tree Tree Traversal Spanning Trees
More informationCS302 Data Structures using C++
CS302 Data Structures using C++ Study Guide for the Final Exam Fall 2018 Revision 1.1 This document serves to help you prepare towards the final exam for the Fall 2018 semester. 1. What topics are to be
More informationR10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May
www.jwjobs.net R10 SET - 1 II B. Tech I Semester, Supplementary Examinations, May - 2012 (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 *******-****** 1. a) Which of the given options provides the
More informationMULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR
STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM
More informationCS24 Week 8 Lecture 1
CS24 Week 8 Lecture 1 Kyle Dewey Overview Tree terminology Tree traversals Implementation (if time) Terminology Node The most basic component of a tree - the squares Edge The connections between nodes
More informationRevision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,
[1] Big-O Analysis AVERAGE(n) 1. sum 0 2. i 0. while i < n 4. number input_number(). sum sum + number 6. i i + 1 7. mean sum / n 8. return mean Revision Statement no. of times executed 1 1 2 1 n+1 4 n
More informationData Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.
Data Structures Outline Introduction Linked Lists Stacks Queues Trees Introduction dynamic data structures - grow and shrink during execution Linked lists - insertions and removals made anywhere Stacks
More informationE.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.
17CA 104DATA STRUCTURES Academic Year : 018-019 Programme : MCA Year / Semester : I / I Question Bank Course Coordinator: Mrs. C.Mallika Course Objectives The student should be able to 1. To understand
More informationStack and Queue. Stack:
Stack and Queue Stack: Abstract Data Type A stack is a container of objects that are inserted and removed according to the last-in first-out (LIFO) principle. In the pushdown stacks only two operations
More informationBinary Trees
Binary Trees 4-7-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? What is a Tree? You are all familiar with what
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Trees
Computer Science 0 Data Structures Siena College Fall 08 Topic Notes: Trees We ve spent a lot of time looking at a variety of structures where there is a natural linear ordering of the elements in arrays,
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 11: Binary Search Trees MOUNA KACEM mouna@cs.wisc.edu Fall 2018 General Overview of Data Structures 2 Introduction to trees 3 Tree: Important non-linear data structure
More informationR13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)
SET - 1 II B. Tech I Semester Supplementary Examinations, May/June - 2016 PART A 1. a) Write a procedure for the Tower of Hanoi problem? b) What you mean by enqueue and dequeue operations in a queue? c)
More informationChapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1
Chapter 14 Graphs 2011 Pearson Addison-Wesley. All rights reserved 14 A-1 Terminology G = {V, E} A graph G consists of two sets A set V of vertices, or nodes A set E of edges A subgraph Consists of a subset
More informationProgramming Abstractions
Programming Abstractions C S 1 0 6 B Cynthia Lee Topics: Priority Queue Linked List implementation Sorted Unsorted Heap structure implementation TODAY S TOPICS NOT ON THE MIDTERM 2 Some priority queue
More informationDATA STRUCTURE AND ALGORITHM USING PYTHON
DATA STRUCTURE AND ALGORITHM USING PYTHON Advanced Data Structure and File Manipulation Peter Lo Linear Structure Queue, Stack, Linked List and Tree 2 Queue A queue is a line of people or things waiting
More informationTree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.
Tree A tree consists of a set of nodes and a set of edges connecting pairs of nodes. A tree has the property that there is exactly one path (no more, no less) between any pair of nodes. A path is a connected
More informationLecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this
Lecture Notes Array Review An array in C++ is a contiguous block of memory. Since a char is 1 byte, then an array of 5 chars is 5 bytes. For example, if you execute the following C++ code you will allocate
More informationData Structure. IBPS SO (IT- Officer) Exam 2017
Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data
More informationAlgorithms and Theory of Computation. Lecture 3: Graph Algorithms
Algorithms and Theory of Computation Lecture 3: Graph Algorithms Xiaohui Bei MAS 714 August 20, 2018 Nanyang Technological University MAS 714 August 20, 2018 1 / 18 Connectivity In a undirected graph G
More informationData Structure Advanced
Data Structure Advanced 1. Is it possible to find a loop in a Linked list? a. Possilbe at O(n) b. Not possible c. Possible at O(n^2) only d. Depends on the position of loop Solution: a. Possible at O(n)
More informationCOSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)
COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 04 / 13 / 2018 Instructor: Michael Eckmann Today s Topics Questions? Comments? Graphs Depth First Search (DFS) Shortest path Shortest weight path (Dijkstra's
More informationFirst Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...
First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms.... Q1) What are some of the applications for the tree data structure? Q2) There are 8, 15, 13, and
More informationCS8391-DATA STRUCTURES QUESTION BANK UNIT I
CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Define data structure. The data structure can be defined as the collection of elements and all the possible operations which are required for those
More informationTREES cs2420 Introduction to Algorithms and Data Structures Spring 2015
TREES cs2420 Introduction to Algorithms and Data Structures Spring 2015 1 administrivia 2 -assignment 7 due Thursday at midnight -asking for regrades through assignment 5 and midterm must be complete by
More informationCS301 - Data Structures Glossary By
CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm
More informationCS 310 Advanced Data Structures and Algorithms
CS 31 Advanced Data Structures and Algorithms Graphs July 18, 17 Tong Wang UMass Boston CS 31 July 18, 17 1 / 4 Graph Definitions Graph a mathematical construction that describes objects and relations
More informationCSE 373 NOVEMBER 20 TH TOPOLOGICAL SORT
CSE 373 NOVEMBER 20 TH TOPOLOGICAL SORT PROJECT 3 500 Internal Error problems Hopefully all resolved (or close to) P3P1 grades are up (but muted) Leave canvas comment Emails tomorrow End of quarter GRAPHS
More informationCSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014
CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up Nicki Dell Spring 2014 Final Exam As also indicated on the web page: Next Tuesday, 2:30-4:20 in this room Cumulative but
More informationCSE 332: Data Abstractions Lecture 15: Topological Sort / Graph Traversals. Ruth Anderson Winter 2013
CSE 332: Data Abstractions Lecture 15: Topological Sort / Graph Traversals Ruth Anderson Winter 2013 Announcements Homework 4 due Friday Feb 15 th at the BEGINNING of lecture Project 2 Phase B due Tues
More informationCS302 - Data Structures using C++
CS302 - Data Structures using C++ Topic: Graphs - Introduction Kostas Alexis Terminology In the context of our course, graphs represent relations among data items G = {V,E} A graph is a set of vertices
More informationThe ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value
The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value 1 Possible implementations Sorted linear implementations o Appropriate if
More informationCS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%
CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40% Name ID Directions: There are 9 questions in this exam. To earn a possible full score, you must solve all questions. Time allowed: 180 minutes Closed
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 3 Data Structures Graphs Traversals Strongly connected components Sofya Raskhodnikova L3.1 Measuring Running Time Focus on scalability: parameterize the running time
More informationCS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type
More informationCS 220: Discrete Structures and their Applications. graphs zybooks chapter 10
CS 220: Discrete Structures and their Applications graphs zybooks chapter 10 directed graphs A collection of vertices and directed edges What can this represent? undirected graphs A collection of vertices
More information3137 Data Structures and Algorithms in C++
3137 Data Structures and Algorithms in C++ Lecture 3 July 12 2006 Shlomo Hershkop 1 Announcements Homework 2 out tonight Please make sure you complete hw1 asap if you have issues, please contact me will
More informationCSE 100: GRAPH ALGORITHMS
CSE 100: GRAPH ALGORITHMS 2 Graphs: Example A directed graph V5 V = { V = E = { E Path: 3 Graphs: Definitions A directed graph V5 V6 A graph G = (V,E) consists of a set of vertices V and a set of edges
More informationLECTURE 17 GRAPH TRAVERSALS
DATA STRUCTURES AND ALGORITHMS LECTURE 17 GRAPH TRAVERSALS IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD STRATEGIES Traversals of graphs are also called searches We can use either breadth-first
More informationFINAL EXAM REVIEW CS 200 RECITATIOIN 14
FINAL EXAM REVIEW CS 200 RECITATIOIN 14 I don t *think* the final is cumulative. Sangmi will say for sure during her review sessions. Either way, keep in mind that this course s material is naturally cumulative
More informationFundamental Algorithms
Fundamental Algorithms Chapter 8: Graphs Jan Křetínský Winter 2017/18 Chapter 8: Graphs, Winter 2017/18 1 Graphs Definition (Graph) A graph G = (V, E) consists of a set V of vertices (nodes) and a set
More informationTrees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006
Trees and Graphs Basic Definitions Tree: Any connected, acyclic graph G = (V,E) E = V -1 n-ary Tree: Tree s/t all vertices of degree n+1 A root has degree n Binary Search Tree: A binary tree such that
More informationDepartment of Computer Science and Technology
UNIT : Stack & Queue Short Questions 1 1 1 1 1 1 1 1 20) 2 What is the difference between Data and Information? Define Data, Information, and Data Structure. List the primitive data structure. List the
More informationcsci 210: Data Structures Stacks and Queues
csci 210: Data Structures Stacks and Queues 1 Summary Topics Stacks and Queues as abstract data types ( ADT) Implementations arrays linked lists Analysis and comparison Applications: searching with stacks
More informationPrepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1
QUESTION BANK ON COURSE: 304: PRELIMINARIES: 1. What is array of pointer, explain with appropriate example? 2 2. Differentiate between call by value and call by reference, give example. 3. Explain pointer
More informationA6-R3: DATA STRUCTURE THROUGH C LANGUAGE
A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF
More informationFINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard
FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures
More informationChapter 4. Uninformed Search Strategies
Chapter 4. Uninformed Search Strategies An uninformed (a.k.a. blind, brute-force) search algorithm generates the search tree without using any domain specific knowledge. The two basic approaches differ
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)
WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in
More informationCS 8391 DATA STRUCTURES
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK CS 8391 DATA STRUCTURES UNIT- I PART A 1. Define: data structure. A data structure is a way of storing and organizing data in the memory for
More informationTrees Algorhyme by Radia Perlman
Algorhyme by Radia Perlman I think that I shall never see A graph more lovely than a tree. A tree whose crucial property Is loop-free connectivity. A tree which must be sure to span. So packets can reach
More informationCPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues
CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 available very
More informationSELF-BALANCING SEARCH TREES. Chapter 11
SELF-BALANCING SEARCH TREES Chapter 11 Tree Balance and Rotation Section 11.1 Algorithm for Rotation BTNode root = left right = data = 10 BTNode = left right = data = 20 BTNode NULL = left right = NULL
More informationBinary Trees, Binary Search Trees
Binary Trees, Binary Search Trees Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete)
More informationCS61BL. Lecture 3: Asymptotic Analysis Trees & Tree Traversals Stacks and Queues Binary Search Trees (and other trees)
CS61BL Lecture 3: Asymptotic Analysis Trees & Tree Traversals Stacks and Queues Binary Search Trees (and other trees) Program Efficiency How much memory a program uses Memory is cheap How much time a
More informationIntroduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis
Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis p. 5 Statement Constructs p. 5 Pseudocode Example p.
More informationOutlines: Graphs Part-2
Elementary Graph Algorithms PART-2 1 Outlines: Graphs Part-2 Graph Search Methods Breadth-First Search (BFS): BFS Algorithm BFS Example BFS Time Complexity Output of BFS: Shortest Path Breath-First Tree
More informationCSC148H Week 3. Sadia Sharmin. May 24, /20
CSC148H Week 3 Sadia Sharmin May 24, 2017 1/20 Client vs. Developer I For the first couple of weeks, we have played the role of class designer I However, you are also often in the opposite role: when a
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 10: Search and Heaps MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Search and Heaps 2 Linear Search Binary Search Introduction to trees Priority Queues Heaps Linear Search
More informationBreadth First Search. cse2011 section 13.3 of textbook
Breadth irst Search cse section. of textbook Graph raversal (.) Application example Given a graph representation and a vertex s in the graph, find all paths from s to the other vertices. wo common graph
More informationTree Structures. A hierarchical data structure whose point of entry is the root node
Binary Trees 1 Tree Structures A tree is A hierarchical data structure whose point of entry is the root node This structure can be partitioned into disjoint subsets These subsets are themselves trees and
More informationUNIT IV -NON-LINEAR DATA STRUCTURES 4.1 Trees TREE: A tree is a finite set of one or more nodes such that there is a specially designated node called the Root, and zero or more non empty sub trees T1,
More informationGraphs: Graph Data Structure:
Graphs: A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links. The interconnected objects are represented by points termed as vertices, and the links
More informationGraphs and Algorithms
Graphs and Algorithms Graphs are a mathematical concept readily adapted into computer programming. Graphs are not just data structures, that is, they are not solutions to simple data storage problems.
More informationUNIT 4 Branch and Bound
UNIT 4 Branch and Bound General method: Branch and Bound is another method to systematically search a solution space. Just like backtracking, we will use bounding functions to avoid generating subtrees
More informationCPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues
CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 is available.
More informationScribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.
Lecture 9 Graphs Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M. Wootters (2017) 1 Graphs A graph is a set of vertices
More informationimplementing the breadth-first search algorithm implementing the depth-first search algorithm
Graph Traversals 1 Graph Traversals representing graphs adjacency matrices and adjacency lists 2 Implementing the Breadth-First and Depth-First Search Algorithms implementing the breadth-first search algorithm
More informationBinary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I
Binary Trees College of Computing & Information Technology King Abdulaziz University CPCS-204 Data Structures I Outline Tree Stuff Trees Binary Trees Implementation of a Binary Tree Tree Traversals Depth
More informationCSE 373 OCTOBER 11 TH TRAVERSALS AND AVL
CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL MINUTIAE Feedback for P1p1 should have gone out before class Grades on canvas tonight Emails went to the student who submitted the assignment If you did not receive
More informationChapter 9 STACK, QUEUE
Chapter 9 STACK, QUEUE 1 LIFO: Last In, First Out. Stacks Restricted form of list: Insert and remove only at front of list. Notation: Insert: PUSH Remove: POP The accessible element is called TOP. Stack
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 07 / 26 / 2016 Instructor: Michael Eckmann Today s Topics Comments/Questions? Stacks and Queues Applications of both Priority Queues Michael Eckmann - Skidmore
More informationTrees. Arash Rafiey. 20 October, 2015
20 October, 2015 Definition Let G = (V, E) be a loop-free undirected graph. G is called a tree if G is connected and contains no cycle. Definition Let G = (V, E) be a loop-free undirected graph. G is called
More informationCourse goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance
Course goals exposure to another language C++ Object-oriented principles knowledge of specific data structures lists, stacks & queues, priority queues, dynamic dictionaries, graphs impact of DS design
More informationGraph. Vertex. edge. Directed Graph. Undirected Graph
Module : Graphs Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS E-mail: natarajan.meghanathan@jsums.edu Graph Graph is a data structure that is a collection
More informationAdvanced Data Structures and Algorithms
dvanced ata Structures and lgorithms ssociate Professor r. Raed Ibraheem amed University of uman evelopment, College of Science and Technology Computer Science epartment 2015 2016 epartment of Computer
More informationECE Spring 2018 Problem Set #0 Due: 1/30/18
ECE 45234 - Spring 2018 Problem Set #0 Due: 1/30/18 The purpose of this first problem set is to remind you of the material you need from 2574 and help get you up-to-speed with python. This course uses
More informationHomework Assignment #3 Graph
CISC 4080 Computer Algorithms Spring, 2019 Homework Assignment #3 Graph Some of the problems are adapted from problems in the book Introduction to Algorithms by Cormen, Leiserson and Rivest, and some are
More informationCS8391-DATA STRUCTURES
ST.JOSEPH COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERI NG CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Explain the term data structure. The data structure can be defined
More informationDATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305
Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n
More information1 Binary trees. 1 Binary search trees. 1 Traversal. 1 Insertion. 1 An empty structure is an empty tree.
Unit 6: Binary Trees Part 1 Engineering 4892: Data Structures Faculty of Engineering & Applied Science Memorial University of Newfoundland July 11, 2011 1 Binary trees 1 Binary search trees Analysis of
More informationCSE 373 APRIL 17 TH TREE BALANCE AND AVL
CSE 373 APRIL 17 TH TREE BALANCE AND AVL ASSORTED MINUTIAE HW3 due Wednesday Double check submissions Use binary search for SADict Midterm text Friday Review in Class on Wednesday Testing Advice Empty
More informationCS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux
CS 231 Data Structures and Algorithms Fall 2018 Recursion and Binary Trees Lecture 21 October 24, 2018 Prof. Zadia Codabux 1 Agenda ArrayQueue.java Recursion Binary Tree Terminologies Traversal 2 Administrative
More informationTree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.
Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except
More informationCS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY
CS 251, LE 2 Fall 2016 MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY W1.) (i) Show one possible valid 2-3 tree containing the nine elements: 1 3 4 5 6 8 9 10 12. (ii) Draw the final binary search
More information! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade
Final Exam Review Final Exam Mon, May 5, 2:00PM to 4:30PM CS 2308 Spring 2014 Jill Seaman Closed book, closed notes, clean desk Comprehensive (covers entire course) 30% of your final grade I recommend
More informationCS102 Binary Search Trees
CS102 Binary Search Trees Prof Tejada 1 To speed up insertion, removal and search, modify the idea of a Binary Tree to create a Binary Search Tree (BST) Binary Search Trees Binary Search Trees have one
More informationCSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees. Ruth Anderson Winter 2019
CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees Ruth Anderson Winter 2019 Today Dictionaries Trees 1/23/2019 2 Where we are Studying the absolutely essential ADTs of
More informationAnnouncements Problem Set 4 is out!
CSC263 Week 8 Announcements Problem Set 4 is out! Due Tuesday (Nov 17) Other Announcements Drop date Nov 8 Final exam schedule is posted CSC263 exam Dec 11, 2-5pm This week s outline Graphs BFS Graph A
More informationCS171 Final Practice Exam
CS171 Final Practice Exam Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 150 minutes to complete this exam. Read each problem carefully, and review your
More information