Dynamic Data Structures. John Ross Wallrabenstein

Size: px
Start display at page:

Download "Dynamic Data Structures. John Ross Wallrabenstein"

Transcription

1 Dynamic Data Structures John Ross Wallrabenstein

2 Recursion Review In the previous lecture, I asked you to find a recursive definition for the following problem: Given: A base10 number X Assume X has N digits Output: X printed vertically

3 Print Vertically Did anyone come up with a solution?

4 Print Vertically

5 Print Vertically What is our base case?

6 Print Vertically What is our base case? When X is a single digit: print X

7 Print Vertically What is our base case? When X is a single digit: print X What is our recursive call?

8 Print Vertically What is our base case? When X is a single digit: print X What is our recursive call? When X has more than one digit:

9 Print Vertically What is our base case? When X is a single digit: print X What is our recursive call? When X has more than one digit: Print the N-1 most significant digits

10 Print Vertically What is our base case? When X is a single digit: print X What is our recursive call? When X has more than one digit: Print the N-1 most significant digits Print the least significant digit

11 Print Vertically public class PrintVertically { public static void main(string[] args) { } int x = 1234; System.out.println("writeVertical(" + x + "):"); writevertical(x); public static void writevertical(int x){ //If X is a single digit if(x < 10){ System.out.println(x); } //If X has more than a single digit else{ //Print the most significant digits vertically writevertical(x/10); } } } //Print the least significant digit vertically System.out.println(x%10);

12 Asymptotic Notation When analyzing an algorithm, it is convenient to have a simple way to express the efficiency of the algorithm This allows us to compare the efficiency of two different algorithms

13 Big-Oh Notation Assumption: Our algorithm is defined in terms of functions whose domains are the set of natural numbers N={0,1,2,...}

14 Big-Oh Notation We would like to bound the running time of our algorithm by a measure of the number of atomic (constant time) operations it performs

15 Big-Oh Notation We say that a function f(n) is O(g(n)) iff: Not a typo! there exists some constant c and n0 such that:

16 Big-Oh Notation Formally:

17 Big-Oh Notation

18 Big-Oh Notation Example: This program runs in O(n) time for(int i = 0; i < n; ++i){ //Atomic Operations }

19 Big-Oh Notation Example: This program runs in O(n 2 ) time for(int i = 0; i < n; ++i){ //Atomic Operations for(int j = 0; j < n; ++j){ //Atomic Operations } }

20 Asymptotic Analysis The smaller the asymptotic bound, the faster the algorithm e.g. O(n) is preferable to O(n 2 )

21 Data Structures

22 Data Structures What are they?

23 Data Structures What are they? A data structure is an abstraction used to model a set of related data

24 Data Structures What are they? A data structure is an abstraction used to model a set of related data What data structures are you familiar with?

25 Data Structures What are they? A data structure is an abstraction used to model a set of related data What data structures are you familiar with? Most Common Example: Arrays

26 Data Structures What are they? A data structure is an abstraction used to model a set of related data What data structures are you familiar with? Most Common Example: Arrays Food for Thought: File Systems

27 Static Data Structures Static Data Structures Data Structures that do not change* over the lifetime of their use *This usually refers to the size of the structure

28 Static Data Structures Benefits: Fast Access to Individual Elements Drawbacks: Expensive to update e.g. Insertion, Deletion Finite size known at compile time e.g. Arrays

29 Dynamic Data Structures Dynamic Data Structures Data Structures that change over their lifetime, allowing for efficient updates

30 Dynamic Data Structures Benefits: Fast Updates (Insertion, Deletion) Flexible Size Drawbacks: Slow access to individual elements

31 Arrays Recall that the size of an array must be declared at compile time How does this affect insertion/deletion?

32 Array Deletion When we delete an element from an array, we usually waste memory If we want to reclaim this memory, we have to create a new array (of size n-1) and copy all n-1 elements This is inefficient!

33 Array Insertion Case: Insert an element between existing elements We have to copy the entire array to a new location, leaving space for the new element This is inefficient!

34 Array Insertion Case: Insert (push) an element onto the end of a full array We have to: Allocate space for an array of size n+1 Copy n elements into the new array Add new element to the end Deallocate memory for old array (For C Programmers)

35 Array Insertion Can we do better than O(n) time? How?

36 Array Insertion Improving Insertion Efficiency Rule: When the array is full and a new element is to be added, proceed by: Allocating space for an array of size 2n Copy original n elements Add new element

37 Array Insertion How does this help? In the amortized case, we now have that insertion takes O(1)! Amortized analysis involves taking the cost of an operation over the number of times the operation is invoked In this case: A single push is effectively O(1)

38 ArrayLists You have probably seen ArrayLists An ArrayList is a hybrid between a static data structure (arrays) and a fully dynamic structure ArrayLists use the previous optimization when inserting elements into a full array

39 Linked Lists A linked list is a dynamic data structure composed of nodes Each node contains: Data Pointer to next node in list* *In the case of a singly linked list

40 Linked Lists How is the order of the elements in an array determined? By the index of the element How is the order of the elements in a linked list determined? By the next pointer in each node

41 Linked Lists What are the benefits of this structure? Insertion: Point the current node s next to predecessor s next Point predecessor s next to the current node No resizing!

42 Linked Lists What are the benefits of this structure? Deletion: Point the previous node s (predecessor) next to the current node s next (successor) No inefficient use of memory!

43 Linked Lists What are the drawbacks of this structure? Representation on disk may be fragmented Why? Linked Lists do not need contiguous blocks of memory Thus, nodes can be stored anywhere

44 Dynamic Sets When building algorithms, sets of data must be able to change over time* We must be able to: Insert Delete Test Membership *Have we seen this phrase before?...

45 Dynamic Sets What dynamic sets have you seen before? Stacks Queues Linked Lists Etc... Let s look at a particular application of sets

46 Disjoint Sets Two sets A and B are said to be disjoint if their intersection is null Many times, it is useful to partition a larger set into smaller, disjoint sets How can we keep track (Find) of the elements and combine (Union) the smaller sets into larger sets efficiently? Dynamic Data Structures to the rescue!

47 Disjoint Sets A disjoint-set data structure maintains a collection S={S1,S2,...,Sk} of disjoint dynamic sets Each set is identified by a representative

48 Disjoint Set Operations We require the following operations to be supported: Make-Set(x) - create a new set whose only member is x Union(x,y) - unites the dynamic sets that contain elements x and y Find-Set(x) - return a pointer to the representative of the set containing x

49 Why We Care Before proceeding, why should we worry about how to use dynamic data structures to handle dynamic disjoint sets? Common Application: Determining the Connected Components of a Graph See Board

50 Union / Find We will focus on constructing a dynamic data structure that computes Union and Find efficiently

51 Union / Find To support the operations Union and Find on disjoint sets, we will use a disjoint set forest of trees Setup: Each member points only to its parent The root is the representative of the set (and also its own parent)

52 Union / Find

53 Find To implement Find(x) and return its representative element: Follow parent pointers until the root is reached Return the root (representative)

54 Union To implement Union(x,y) Set the parent of one of the set s representatives to the root of the other set

55 Union / Find Consider the following scenario: We have x1,x2,...,xn objects We make each xi a set with Make-Set(x) We Union each xi into one large set See Board Does order matter?

56 Union / Find Consider the running time of Find if we only use the tools we have seen so far: To Find element X in a set, if we have a linear chain of n nodes takes O(n) time If we have n calls to Find our running time is then: Can we do better?

57 Union / Find What is the source of inefficiency? We are appending a larger set onto a smaller set (xi) How can we fix this? Maintain the size of each set (easy) Always append the smaller set onto the larger set Use path compression to reduce tree height

58 Union By Rank To always append the smaller set to the larger set, we maintain a rank for each set The rank is an upper bound on the height of the set tree The root with the smaller rank points to the root of the larger set

59 Union By Rank See Board for Example Performance Analysis: Where we perform m operations on n elements The proof of this bound is beyond the scope of this course

60 Path Compression To lower the number of parent nodes we have to pass through to reach the root in a Find(x) operation: Run Find(x) once to retrieve the root Run Find(x) again, pointing each node along the way to root See Board Running time:

61 Combining Both When both Union By Rank and Path Compression are used: Running Time: Here, alpha represents the Ackermann Function, which is effectively constant

62 Questions

COP 4531 Complexity & Analysis of Data Structures & Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 8 Data Structures for Disjoint Sets Thanks to the text authors who contributed to these slides Data Structures for Disjoint Sets Also

More information

CSE373: Data Structures & Algorithms Lecture 11: Implementing Union-Find. Lauren Milne Spring 2015

CSE373: Data Structures & Algorithms Lecture 11: Implementing Union-Find. Lauren Milne Spring 2015 CSE: Data Structures & Algorithms Lecture : Implementing Union-Find Lauren Milne Spring 05 Announcements Homework due in ONE week Wednesday April 9 th! TA sessions Catie will be back on Monday. The plan

More information

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

More information

Union-Find Disjoint Set

Union-Find Disjoint Set Union-Find Disjoint Set An ADT(Abstract Data Type) used to manage disjoint sets of elements. Operations supported Union: Given3 2 elements, if they belong to different sets, merge the 2 1 3 1 Union(1,

More information

CS301 - Data Structures Glossary By

CS301 - 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 information

Types II. Hwansoo Han

Types II. Hwansoo Han Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Disjoin Sets and Union-Find Structures CLRS 21.121.4 University of Manitoba 1 / 32 Disjoint Sets Disjoint set is an abstract data type

More information

Fibonacci Heaps Priority Queues. John Ross Wallrabenstein

Fibonacci Heaps Priority Queues. John Ross Wallrabenstein Fibonacci Heaps Priority Queues John Ross Wallrabenstein Updates Project 4 Grades Released Project 5 Questions? Review *This usually refers to the size of the structure Review What is a static data structure?

More information

Amortized Analysis and Union-Find , Inge Li Gørtz

Amortized Analysis and Union-Find , Inge Li Gørtz Amortized Analysis and Union-Find 02283, Inge Li Gørtz 1 Today Amortized analysis 3 different methods 2 examples Union-Find data structures Worst-case complexity Amortized complexity 2 Amortized Analysis

More information

CS F-14 Disjoint Sets 1

CS F-14 Disjoint Sets 1 CS673-2016F-14 Disjoint Sets 1 14-0: Disjoint Sets Maintain a collection of sets Operations: Determine which set an element is in Union (merge) two sets Initially, each element is in its own set # of sets

More information

Maintaining Disjoint Sets

Maintaining Disjoint Sets Maintaining Disjoint Sets Ref: Chapter 21 of text. (Proofs in Section 21.4 omitted.) Given: A collection S 1, S 2,..., S k of pairwise disjoint sets. Each set has a name, its representative, which is an

More information

CS S-14 Disjoint Sets 1

CS S-14 Disjoint Sets 1 CS245-2015S-14 Disjoint Sets 1 14-0: Disjoint Sets Maintain a collection of sets Operations: Determine which set an element is in Union (merge) two sets Initially, each element is in its own set # of sets

More information

Disjoint Sets and the Union/Find Problem

Disjoint Sets and the Union/Find Problem Disjoint Sets and the Union/Find Problem Equivalence Relations A binary relation R on a set S is a subset of the Cartesian product S S. If (a, b) R we write arb and say a relates to b. Relations can have

More information

Nested Loops. A loop can be nested inside another loop.

Nested Loops. A loop can be nested inside another loop. Nested Loops A loop can be nested inside another loop. Nested loops consist of an outer loop and one or more inner loops. Each time the outer loop is repeated, the inner loops are reentered, and started

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures PD Dr. rer. nat. habil. Ralf Peter Mundani Computation in Engineering / BGU Scientific Computing in Computer Science / INF Summer Term 2018 Part 2: Data Structures PD Dr.

More information

CMSC 341 Lecture 20 Disjointed Sets

CMSC 341 Lecture 20 Disjointed Sets CMSC 341 Lecture 20 Disjointed Sets Prof. John Park Based on slides from previous iterations of this course Introduction to Disjointed Sets Disjoint Sets A data structure that keeps track of a set of elements

More information

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging. Priority Queue, Heap and Heap Sort In this time, we will study Priority queue, heap and heap sort. Heap is a data structure, which permits one to insert elements into a set and also to find the largest

More information

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination University of Illinois at Urbana-Champaign Department of Computer Science Final Examination CS 225 Data Structures and Software Principles Spring 2010 7-10p, Wednesday, May 12 Name: NetID: Lab Section

More information

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Cpt S 223 Fall Cpt S 223. School of EECS, WSU Course Review Cpt S 223 Fall 2012 1 Final Exam When: Monday (December 10) 8 10 AM Where: in class (Sloan 150) Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes

More information

UNIT-1. Chapter 1(Introduction and overview) 1. Asymptotic Notations 2. One Dimensional array 3. Multi Dimensional array 4. Pointer arrays.

UNIT-1. Chapter 1(Introduction and overview) 1. Asymptotic Notations 2. One Dimensional array 3. Multi Dimensional array 4. Pointer arrays. UNIT-1 Chapter 1(Introduction and overview) 1. Asymptotic Notations 2. One Dimensional array 3. Multi Dimensional array 4. Pointer arrays. Chapter 2 (Linked lists) 1. Definition 2. Single linked list 3.

More information

CMSC 341 Lecture 20 Disjointed Sets

CMSC 341 Lecture 20 Disjointed Sets CMSC 341 Lecture 20 Disjointed Sets Prof. John Park Based on slides from previous iterations of this course Introduction to Disjointed Sets Disjoint Sets A data structure that keeps track of a set of elements

More information

Disjoint Sets 3/22/2010

Disjoint Sets 3/22/2010 Disjoint Sets A disjoint-set is a collection C={S 1, S 2,, S k } of distinct dynamic sets. Each set is identified by a member of the set, called representative. Disjoint set operations: MAKE-SET(x): create

More information

CMSC 341 Lecture 20 Disjointed Sets

CMSC 341 Lecture 20 Disjointed Sets CMSC 341 Lecture 20 Disjointed Sets Prof. John Park Based on slides from previous iterations of this course Introduction to Disjointed Sets Disjoint Sets A data structure that keeps track of a set of elements

More information

Lecture Summary CSC 263H. August 5, 2016

Lecture Summary CSC 263H. August 5, 2016 Lecture Summary CSC 263H August 5, 2016 This document is a very brief overview of what we did in each lecture, it is by no means a replacement for attending lecture or doing the readings. 1. Week 1 2.

More information

CSE 373 MAY 10 TH SPANNING TREES AND UNION FIND

CSE 373 MAY 10 TH SPANNING TREES AND UNION FIND CSE 373 MAY 0 TH SPANNING TREES AND UNION FIND COURSE LOGISTICS HW4 due tonight, if you want feedback by the weekend COURSE LOGISTICS HW4 due tonight, if you want feedback by the weekend HW5 out tomorrow

More information

Outline. Disjoint set data structure Applications Implementation

Outline. Disjoint set data structure Applications Implementation Disjoint Data Sets Outline Disjoint set data structure Applications Implementation Data Structures for Disjoint Sets A disjoint-set data structure is a collection of sets S = {S 1 S k }, such that S i

More information

ECE250: Algorithms and Data Structures Midterm Review

ECE250: Algorithms and Data Structures Midterm Review ECE250: Algorithms and Data Structures Midterm Review Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University of Waterloo

More information

CS 161: Design and Analysis of Algorithms

CS 161: Design and Analysis of Algorithms CS 161: Design and Analysis of Algorithms Greedy Algorithms 2: Minimum Spanning Trees Definition The cut property Prim s Algorithm Kruskal s Algorithm Disjoint Sets Tree A tree is a connected graph with

More information

Disjoint set (Union-Find)

Disjoint set (Union-Find) CS124 Lecture 6 Spring 2011 Disjoint set (Union-Find) For Kruskal s algorithm for the minimum spanning tree problem, we found that we needed a data structure for maintaining a collection of disjoint sets.

More information

An Introduction to Trees

An Introduction to Trees An Introduction to Trees Alice E. Fischer Spring 2017 Alice E. Fischer An Introduction to Trees... 1/34 Spring 2017 1 / 34 Outline 1 Trees the Abstraction Definitions 2 Expression Trees 3 Binary Search

More information

Advanced Set Representation Methods

Advanced Set Representation Methods Advanced Set Representation Methods AVL trees. 2-3(-4) Trees. Union-Find Set ADT DSA - lecture 4 - T.U.Cluj-Napoca - M. Joldos 1 Advanced Set Representation. AVL Trees Problem with BSTs: worst case operation

More information

CSE 373 Spring Midterm. Friday April 21st

CSE 373 Spring Midterm. Friday April 21st CSE 373 Spring 2006 Data Structures and Algorithms Midterm Friday April 21st NAME : Do all your work on these pages. Do not add any pages. Use back pages if necessary. Show your work to get partial credit.

More information

! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?

! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How? A Binding Question! Variables are bound (dynamically) to values Subprogram Activation! Those values must be stored somewhere! Therefore, variables must somehow be bound to memory locations! How? Function

More information

Lecture 4: Elementary Data Structures Steven Skiena

Lecture 4: Elementary Data Structures Steven Skiena Lecture 4: Elementary Data Structures Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Find two

More information

Course Review. Cpt S 223 Fall 2010

Course Review. Cpt S 223 Fall 2010 Course Review Cpt S 223 Fall 2010 1 Final Exam When: Thursday (12/16) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program

More information

COMP26120: Linked List in C (2018/19) Lucas Cordeiro

COMP26120: Linked List in C (2018/19) Lucas Cordeiro COMP26120: Linked List in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Linked List Lucas Cordeiro (Formal Methods Group) lucas.cordeiro@manchester.ac.uk Office: 2.28 Office hours: 10-11 Tuesday,

More information

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 CS 314, LS,BR,LTM: Scope and Memory 1 Review Functions as first-class objects What can you do with an integer?

More information

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE Chapter 1 : What is an application of linear linked list data structures? - Quora A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements

More information

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination University of Illinois at Urbana-Champaign Department of Computer Science Final Examination CS 225 Data Structures and Software Principles Fall 2009 7-10p, Tuesday, December 15 Name: NetID: Lab Section

More information

Data Structures for Disjoint Sets

Data Structures for Disjoint Sets Data Structures for Disjoint Sets Manolis Koubarakis 1 Dynamic Sets Sets are fundamental for mathematics but also for computer science. In computer science, we usually study dynamic sets i.e., sets that

More information

Course Review. Cpt S 223 Fall 2009

Course Review. Cpt S 223 Fall 2009 Course Review Cpt S 223 Fall 2009 1 Final Exam When: Tuesday (12/15) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program

More information

CS 302 ALGORITHMS AND DATA STRUCTURES

CS 302 ALGORITHMS AND DATA STRUCTURES CS 302 ALGORITHMS AND DATA STRUCTURES A famous quote: Program = Algorithm + Data Structure General Problem You have some data to be manipulated by an algorithm E.g., list of students in a school Each student

More information

Section 05: Midterm Review

Section 05: Midterm Review Section 05: Midterm Review 1. Asymptotic Analysis (a) Applying definitions For each of the following, choose a c and n 0 which show f(n) O(g(n)). Explain why your values of c and n 0 work. (i) f(n) = 5000n

More information

Section 05: Solutions

Section 05: Solutions Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access

More information

Requirements, Partitioning, paging, and segmentation

Requirements, Partitioning, paging, and segmentation Requirements, Partitioning, paging, and segmentation Main Memory: The Big Picture kernel memory proc struct kernel stack/u area Stack kernel stack/u area Stack kernel stack/u area Stack Data Text (shared)

More information

RUNNING TIME ANALYSIS. Problem Solving with Computers-II

RUNNING TIME ANALYSIS. Problem Solving with Computers-II RUNNING TIME ANALYSIS Problem Solving with Computers-II Performance questions 4 How efficient is a particular algorithm? CPU time usage (Running time complexity) Memory usage Disk usage Network usage Why

More information

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs Representations of Weighted Graphs (as Matrices) A B Algorithms and Data Structures: Minimum Spanning Trees 9.0 F 1.0 6.0 5.0 6.0 G 5.0 I H 3.0 1.0 C 5.0 E 1.0 D 28th Oct, 1st & 4th Nov, 2011 ADS: lects

More information

Union-Find: A Data Structure for Disjoint Set Operations

Union-Find: A Data Structure for Disjoint Set Operations Union-Find: A Data Structure for Disjoint Set Operations 1 The Union-Find Data Structure Purpose: Great for disjoint sets Operations: Union ( S 1, S 2 ) Find ( x ) Performs a union of two disjoint sets

More information

Today s Outline. Motivation. Disjoint Sets. Disjoint Sets and Dynamic Equivalence Relations. Announcements. Today s Topics:

Today s Outline. Motivation. Disjoint Sets. Disjoint Sets and Dynamic Equivalence Relations. Announcements. Today s Topics: Today s Outline Disjoint Sets and Dynamic Equivalence Relations Announcements Assignment # due Thurs 0/ at pm Today s Topics: Disjoint Sets & Dynamic Equivalence CSE Data Structures and Algorithms 0//0

More information

The time and space are the two measure for efficiency of an algorithm.

The time and space are the two measure for efficiency of an algorithm. There are basically six operations: 5. Sorting: Arranging the elements of list in an order (either ascending or descending). 6. Merging: combining the two list into one list. Algorithm: The time and space

More information

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3 Programming in C main Level 2 Level 2 Level 2 Level 3 Level 3 1 Programmer-Defined Functions Modularize with building blocks of programs Divide and Conquer Construct a program from smaller pieces or components

More information

"apple" "grape" "grape" "grape" "apple"

apple grape grape grape apple Test 1: CPS 100 Owen Astrachan and Dee Ramm February 21, 1997 Name: Honor code acknowledgment (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Problem 6 TOTAL: value 10 pts. 9 pts. 21 pts.

More information

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.! True object-oriented programming: Dynamic Objects Reference Variables D0010E Object-Oriented Programming and Design Lecture 3 Static Object-Oriented Programming UML" knows-about Eckel: 30-31, 41-46, 107-111,

More information

EECS 477: Introduction to algorithms. Lecture 10

EECS 477: Introduction to algorithms. Lecture 10 EECS 477: Introduction to algorithms. Lecture 10 Prof. Igor Guskov guskov@eecs.umich.edu October 8, 2002 1 Lecture outline: data structures (chapter 5) Heaps, binomial heaps Disjoint subsets (union-find)

More information

Data Structures Question Bank Multiple Choice

Data Structures Question Bank Multiple Choice Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution

More information

Introduction to Linked List: Review. Source:

Introduction to Linked List: Review. Source: Introduction to Linked List: Review Source: http://www.geeksforgeeks.org/data-structures/linked-list/ Linked List Fundamental data structures in C Like arrays, linked list is a linear data structure Unlike

More information

Disjoint Sets. Andreas Klappenecker [using notes by R. Sekar]

Disjoint Sets. Andreas Klappenecker [using notes by R. Sekar] Disjoint Sets Andreas Klappenecker [using notes by R. Sekar] Equivalence Classes Frequently, we declare an equivalence relation on a set S. So the elements of the set S are partitioned into equivalence

More information

Chapter 10. Implementing Subprograms

Chapter 10. Implementing Subprograms Chapter 10 Implementing Subprograms Chapter 10 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms

More information

Disjoint Sets. The obvious data structure for disjoint sets looks like this.

Disjoint Sets. The obvious data structure for disjoint sets looks like this. CS61B Summer 2006 Instructor: Erin Korber Lecture 30: 15 Aug. Disjoint Sets Given a set of elements, it is often useful to break them up or partition them into a number of separate, nonoverlapping groups.

More information

Contents. 8-1 Copyright (c) N. Afshartous

Contents. 8-1 Copyright (c) N. Afshartous Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10 Introduction to Object-Oriented

More information

Reading. Disjoint Union / Find. Union. Disjoint Union - Find. Cute Application. Find. Reading. CSE 326 Data Structures Lecture 14

Reading. Disjoint Union / Find. Union. Disjoint Union - Find. Cute Application. Find. Reading. CSE 326 Data Structures Lecture 14 Reading Disjoint Union / Find Reading Chapter 8 CE Data tructures Lecture Disjoint Union/Find - Lecture Disjoint Union - Find Maintain a set of pairwise disjoint sets {,,, {,,8, {9, {, Each set has a unique

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS UNIT 1 - LINEAR DATASTRUCTURES 1. Write down the definition of data structures? A data structure is a mathematical or logical way of organizing data in the memory that consider

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation Lecture 15 COP 3014 Fall 2017 November 6, 2017 Allocating memory There are two ways that memory gets allocated for data storage: 1. Compile Time (or static) Allocation Memory

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes

More information

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial Week 7 General remarks Arrays, lists, pointers and 1 2 3 We conclude elementary data structures by discussing and implementing arrays, lists, and trees. Background information on pointers is provided (for

More information

Summer Final Exam Review Session August 5, 2009

Summer Final Exam Review Session August 5, 2009 15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #6: Memory Management CS 61C L06 Memory Management (1) 2006-07-05 Andy Carle Memory Management (1/2) Variable declaration allocates

More information

Union-Find Structures. Application: Connected Components in a Social Network

Union-Find Structures. Application: Connected Components in a Social Network Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 01 Union-Find Structures Union-Find 1 Application: Connected Components in a Social

More information

Basic Data Structures (Version 7) Name:

Basic Data Structures (Version 7) Name: Prerequisite Concepts for Analysis of Algorithms Basic Data Structures (Version 7) Name: Email: Concept: mathematics notation 1. log 2 n is: Code: 21481 (A) o(log 10 n) (B) ω(log 10 n) (C) Θ(log 10 n)

More information

22c:31 Algorithms. Kruskal s Algorithm for MST Union-Find for Disjoint Sets

22c:31 Algorithms. Kruskal s Algorithm for MST Union-Find for Disjoint Sets 22c:1 Algorithms Kruskal s Algorithm for MST Union-Find for Disjoint Sets 1 Kruskal s Algorithm for MST Work with edges, rather than nodes Two steps: Sort edges by increasing edge weight Select the first

More information

CSCS-200 Data Structure and Algorithms. Lecture

CSCS-200 Data Structure and Algorithms. Lecture CSCS-200 Data Structure and Algorithms Lecture-13-14-15 Recursion What is recursion? Sometimes, the best way to solve a problem is by solving a smaller version of the exact same problem first Recursion

More information

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print) Computer Science 62 Bruce/Mawhorter Fall 16 Midterm Examination October 5, 2016 Question Points Score 1 15 2 10 3 10 4 8 5 9 TOTAL 52 SOLUTIONS Your name (Please print) 1. Suppose you are given a singly-linked

More information

1. Attempt any three of the following: 15

1. Attempt any three of the following: 15 (Time: 2½ hours) Total Marks: 75 N. B.: (1) All questions are compulsory. (2) Make suitable assumptions wherever necessary and state the assumptions made. (3) Answers to the same question must be written

More information

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

CSci 231 Final Review

CSci 231 Final Review CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.

More information

Review of course COMP-251B winter 2010

Review of course COMP-251B winter 2010 Review of course COMP-251B winter 2010 Lecture 1. Book Section 15.2 : Chained matrix product Matrix product is associative Computing all possible ways of parenthesizing Recursive solution Worst-case running-time

More information

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Introduction and Overview

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Introduction and Overview Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Introduction and Overview Welcome to Analysis of Algorithms! What is an Algorithm? A possible definition: a step-by-step

More information

CSE373: Data Structures & Algorithms Lecture 12: Amortized Analysis and Memory Locality. Linda Shapiro Winter 2015

CSE373: Data Structures & Algorithms Lecture 12: Amortized Analysis and Memory Locality. Linda Shapiro Winter 2015 CSE373: Data Structures & Algorithms Lecture 12: Amortized Analysis and Memory Locality Linda Shapiro Winter 2015 Announcements Winter 2015 CSE 373 Data structures and Algorithms 2 Amortized Analysis In

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level

More information

Requirements, Partitioning, paging, and segmentation

Requirements, Partitioning, paging, and segmentation Requirements, Partitioning, paging, and segmentation Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as many processes into memory

More information

LECTURE 11 TREE TRAVERSALS

LECTURE 11 TREE TRAVERSALS DATA STRUCTURES AND ALGORITHMS LECTURE 11 TREE TRAVERSALS IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD BACKGROUND All the objects stored in an array or linked list can be accessed sequentially

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

Course Review for Finals. Cpt S 223 Fall 2008

Course Review for Finals. Cpt S 223 Fall 2008 Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,

More information

CS:3330 (22c:31) Algorithms

CS:3330 (22c:31) Algorithms What s an Algorithm? CS:3330 (22c:31) Algorithms Introduction Computer Science is about problem solving using computers. Software is a solution to some problems. Algorithm is a design inside a software.

More information

Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java)

Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java) COMP 412 FALL 2017 Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java) Copyright 2017, Keith D. Cooper & Zoran Budimlić, all rights reserved. Students enrolled in Comp 412 at Rice

More information

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return Outline Implementing Subprograms In Text: Chapter 10 General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested

More information

Data Structure. IBPS SO (IT- Officer) Exam 2017

Data 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 information

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 10: Asymptotic Complexity and

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 10: Asymptotic Complexity and CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims Lecture 10: Asymptotic Complexity and What Makes a Good Algorithm? Suppose you have two possible algorithms or

More information

Implementing Subroutines. Outline [1]

Implementing Subroutines. Outline [1] Implementing Subroutines In Text: Chapter 9 Outline [1] General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested

More information

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls. Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:

More information

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

CSCI-1200 Data Structures Spring 2018 Lecture 8 Templated Classes & Vector Implementation

CSCI-1200 Data Structures Spring 2018 Lecture 8 Templated Classes & Vector Implementation CSCI-1200 Data Structures Spring 2018 Lecture 8 Templated Classes & Vector Implementation Review from Lectures 7 Algorithm Analysis, Formal Definition of Order Notation Simple recursion, Visualization

More information

Principles of Programming Pointers, Dynamic Memory Allocation, Character Arrays, and Buffer Overruns

Principles of Programming Pointers, Dynamic Memory Allocation, Character Arrays, and Buffer Overruns Pointers, Dynamic Memory Allocation, Character Arrays, and Buffer Overruns What is an array? Pointers Memory issues The name of the array is actually a memory address. You can prove this by trying to print

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 7a Andrew Tolmach Portland State University 1994-2016 Values and Types We divide the universe of values according to types A type is a set of values and a

More information

Trees. A tree is a directed graph with the property

Trees. A tree is a directed graph with the property 2: Trees Trees A tree is a directed graph with the property There is one node (the root) from which all other nodes can be reached by exactly one path. Seen lots of examples. Parse Trees Decision Trees

More information

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24 Prepared By ASCOL CSIT 2070 Batch Institute of Science and Technology 2065 Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass

More information

Run-Time Data Structures

Run-Time Data Structures Run-Time Data Structures Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers, it is used for:

More information

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls. Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:

More information

Lecture 3. Lecture

Lecture 3. Lecture True Object-Oriented programming: Dynamic Objects Static Object-Oriented Programming Reference Variables Eckel: 30-31, 41-46, 107-111, 114-115 Riley: 5.1, 5.2 D0010E Object-Oriented Programming and Design

More information

cs Java: lecture #6

cs Java: lecture #6 cs3101-003 Java: lecture #6 news: homework #5 due today little quiz today it s the last class! please return any textbooks you borrowed from me today s topics: interfaces recursion data structures threads

More information