Lecture 5: Floodfill. Floodfill Overview First assume that there are no walls Give each cell a distance from the goal. The goal has distance 0. Repeat.

Slides:



Advertisements
Similar presentations
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Advertisements

Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Memory management In a multiprogramming system, in order to share the processor, a number of processes must be kept in memory. Memory management is achieved.
Dynamic Memory Management
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
David Notkin Autumn 2009 CSE303 Lecture 13 This space for rent.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Run-time organization  Data representation  Storage organization: –stack –heap –garbage collection Programming Languages 3 © 2012 David A Watt,
DSP Implementation Lecture 3. Anatomy of a DSP Project In VDSP Linker Description File (.LDF) Source Files (.asm,.c,.h,.cpp,.dat) Object Files (.doj)
Hastings Purify: Fast Detection of Memory Leaks and Access Errors.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Memory Management. History Run-time management of dynamic memory is a necessary activity for modern programming languages Lisp of the 1960’s was one of.
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
1 1 Lecture 4 Structure – Array, Records and Alignment Memory- How to allocate memory to speed up operation Structure – Array, Records and Alignment Memory-
Memory Arrangement Memory is arrange in a sequence of addressable units (usually bytes) –sizeof( ) return the number of units it takes to store a type.
Run-Time Storage Organization
Run time vs. Compile time
C and Data Structures Baojian Hua
1 CS 201 Dynamic Data Structures Debzani Deb. 2 Run time memory layout When a program is loaded into memory, it is organized into four areas of memory.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Navigation, Path finding, and Maze Encoding MICROMOUSE ALGORITHMS.
Reference Counters Associate a counter with each heap item Whenever a heap item is created, such as by a new or malloc instruction, initialize the counter.
. Memory Management. Memory Organization u During run time, variables can be stored in one of three “pools”  Stack  Static heap  Dynamic heap.
Memory Layout C and Data Structures Baojian Hua
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Fundamentals of Python: From First Programs Through Data Structures Chapter 14 Linear Collections: Stacks.
Implementing Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
Outline Midterm results Static variables Memory model
Dynamic Memory Allocation Conventional array and other data declarations An incorrect attempt to size memory dynamically Requirement for dynamic allocation.
ITEC 352 Lecture 18 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Exam –Average 76 Methods for functions in assembly.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Storage Bindings Allocation is the process by which the memory cell or collection of memory cells is assigned to a variable. These cells are taken from.
Week 9 Part 1 Kyle Dewey. Overview Dynamic allocation continued Heap versus stack Memory-related bugs Exam #2.
Pointers OVERVIEW.
Object-Oriented Programming in C++
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
C++ REVIEW – POINTERS AND TEST DRIVEN DEVELOPMENT.
For more notes and topics VISIT: IMPLEMENTATION OF STACKS eITnotes.com.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
11/26/2015IT 3271 Memory Management (Ch 14) n Dynamic memory allocation Language systems provide an important hidden player: Runtime memory manager – Activation.
CSCI Rational Purify 1 Rational Purify Overview Michel Izygon - Jim Helm.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Lecture 4: Floodfill. Floodfill Overview First assume that there are no walls Give each cell a distance from the goal. The goal has distance 0. Repeat.
6-1 Embedded Systems C Programming Language Review and Dissection IV Lecture 6.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Today: –Two simple binding examples. –Function Hiding.
Int main( ) { x = a(); } int a() { y = b(); } int b() { z = c(); } int c() { } 1.
CSUN, Prof. Law 16-cells by 16-cells Maze Starting Position Center Squares.
CS 326 Programming Languages, Concepts and Implementation
Dynamic Memory Allocation
User-Defined Functions
This pointer, Dynamic memory allocation, Constructors and Destructor
Depth First Search—Backtracking
CSC 253 Lecture 8.
CSC 253 Lecture 8.
Discussion section #2 HW1 questions?
Dynamic Memory A whole heap of fun….
Dynamic Memory Allocation
Dynamic Memory A whole heap of fun….
Binding Times Binding is an association between two things Examples:
Dynamic Memory A whole heap of fun….
COP 3330 Object-oriented Programming in C++
Run-time environments
Presentation transcript:

Lecture 5: Floodfill

Floodfill Overview First assume that there are no walls Give each cell a distance from the goal. The goal has distance 0. Repeat until we reach the goal: Go to the neighboring cell with the smallest distance to the goal Run the update distances algorithm (see later slide)

Example

Maze Representation Each cell has a distance (0-252 for a 16 x 16 maze) and Each cell can be represented by 4 walls or 2 walls If you have 4 walls for each cell, then you need to update 2 places on discovering a new wall. If you have 2 walls for each cell, then you need an extra “dummy” row and column. You may also want to have a “visited” bit for speed runs. If you use the “visited” bit, then you don’t need to run the Update Distances algorithm on cells that you have already visited, meaning you can go faster on them.

Two Options For Maze Representation | N | N | N | |W E|W E|W E| | S | S | S | | N | N | N | |W E|W E|W E| | S | S | S | | N | N | N | |W E|W E|W E| | S | S | S | x3 Maze with duplicate walls | | | | | |W X |W X |W X |W X | | S | S | S | S | | | | | | |W |W |W |W X | | S | S | S | S | | | | | | |W |W |W |W X | | S | S | S | S | | | | | | |W |W |W |W X | | S | S | S | S | x3 Maze with Dummy row/column X = dummy cell

Print maze function It is essential for debugging to be able to print out your maze Should look something like this: |*5 *4 V3 | | | Use ‘+’ for posts. Use “---” for north/south walls. Use ‘|’ (pipe) for east/west walls. Use ‘*’ for visited. Use, ^, V for the direction of the mouse. If you display distances in base 10, then you will need to do something else when you have 3 digit distances.

The System Stack Space is allocated for each function call de-allocated for function return Where local variables are stored Only 1 kB max by default in our project files 1 MB by default on Windows 8 MB by default on Linux Recursion and large local arrays are bad on embedded systems due to the limited memory

Dynamic Memory Allocation Allocate memory at runtime on System Heap malloc and free (c standard library) new and delete (c++) Bad on embedded systems Takes an unpredictable amount of time Fragmentation may require moving arrays of data System Heap is small, similar to System Stack Makes your code more complicated and buggy Memory leaks are more difficult to detect No OS to kill your process, tell you what happened

Update Distances Algorithm Use a stack method instead of recursion Have stack S as a global variable (should be statically sized, not dynamic) This algorithm runs every time a new cell is visited by the mouse: If there are any new walls discovered: Make sure S is empty Push current cell and cells adjacent to new walls onto S While S is not empty: currCell = pop(S) correctDist = min(all open neighbor distances) + 1 if currCell.dist != correctDist and currCell.dist != 0: currCell.dist = correctDist push all open neighbors to S

Tips Run your Update Distances algorithm as soon as your mouse enters the cell, not when it reaches the center of the cell. You can use Green’s maze generation excel sheet to create test mazes to run your algorithm. For example “bool readLeftWall(), bool readRightWall(), bool readFrontWall()” will read from Green’s array instead of the mouse’s IR sensors. The stack size for the update distances algorithm should be around 512. It is possible to add a cell more than once, therefore 255 may not be enough.