CEG 221 Lesson 7: Algorithm Development From Start to Finish Mr. David Lippa.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Week 5 Part I Kyle Dewey. Overview Exam will be back Thursday New office hour More on functions File I/O Project #2.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
CEG 221 Lesson 5: Algorithm Development II Mr. David Lippa.
CEG 221 Lesson 1: Review I Mr. David Lippa. Overview: Review of Required Concepts Basic data types –Normal basic types, size_t, time_t Basic programming.
Lecture 4 CSE 331 Sep 9, Blog posts for lectures Starts from today See Sep 8 post on the blog.
Lecture 5 CSE 331 Sep 11, HW 1 out today Will be handed out at the END of the lecture Read the homework policy document carefully START EARLY! ©ehow.com.
C Language Summary HTML version. I/O Data Types Expressions Functions Loops and Decisions Preprocessor Statements.
CEG 221 Lesson 4: Algorithm Development I Mr. David Lippa.
CEG 221 Lesson 2: Homogeneous Data Types Mr. David Lippa.
Exercise 10 Review: pointers, strings and recursion.
CEG 221 Lesson 3: Review II & Beyond Mr. David Lippa.
Lecture 9 CSE 331 Sep 21, Gale-Shapley Algorithm Intially all men and women are free While there exists a free woman who can propose Let w be such.
Lecture 8 CSE 331 Sep 17, HW 1 due today Place Q1 and Q2 in separate piles I will not accept HWs after 1:15pm.
V-1 University of Washington Computer Programming I File Input/Output © 2000 UW CSE.
Week 9 Part 2 Kyle Dewey. Overview Announcement More with structs and memory Assertions Exam #2 Course review.
Linked Structures, Project 1: Linked List Bryce Boe 2013/07/11 CS24, Summer 2013 C.
Week 11 - Friday.  What did we talk about last time?  Exam 2 post mortem  Cycle detection  Connectivity.
1 Project 5: Median. 2 The median of a collection of numbers is the member for which there are an equal number less than or equal and greater than or.
Strings in C. Strings are Character Arrays Strings in C are simply arrays of characters. – Example:char s [10]; This is a ten (10) element array that.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
General Programming Introduction to Computing Science and Programming I.
Practical Electronics & Programming
C Programming Tutorial – Part I CS Introduction to Operating Systems.
Android JNI and JAR Library JNI Library 1. JNI *.c sources file must include jni header file jni.h #include 2. In Make file CFLAGS must add -I $(NDK_INC)/
Shell (Addendum). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Engr 0012 (04-1) LecNotes Engr 0012 (04-1) LecNotes C++ errors/debugging build/compile compiler does not recognize a statement build/compile.
EXERCISE Arrays, structs and file processing. Question An online store sells various types of children’s clothing. You are to create a program that stores.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Design & Co-design of Embedded Systems Final Project: “The Match Maker” Second Phase Oral Presentation Safa S. Mahmoodian.
EXERCISE Arrays, structs and file processing. Question You own a pet store. You want to keep an inventory of all the pets that you have. Pets available.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
Lesson - 2. Introduction When we make a program we must follow some steps, called Programming Development Life Cycle (PDLC). Programming steps are five:
Lecture 13: Arrays, Pointers, Code examples B Burlingame 2 Dec 2015.
More About Data Types & Functions. General Program Structure #include statements for I/O, etc. #include's for class headers – function prototype statements.
C LANGUAGE Characteristics of C · Small size
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
COP 3275 – Character Strings and Introduction to Pointers Instructor: Diego Rivera-Gutierrez.
Gramming An Introduction to C Programming (assuming that you already know Java; this is not an introduction to C++)
1 Project 2: Sorting Cats. Write a C++ console application to read a text file containing information about cats and output the information to the screen.
FILES IN C. File Operations  Creation of a new file  Opening an existing file  Reading from a file  Writing to a file  Moving to a specific location.
13/10/2016CS150 Introduction to Computer Science 1 Multidimensional Arrays  Arrays can have more than one column  Two dimensional arrays have two columns.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
Stable marriages Competitive programming and problem solving Yoram Meijaard.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
An Introduction to C Programming (assuming that you already know Java; this is not an introduction to C++)
A bit of C programming Lecture 3 Uli Raich.
Chapter 1 Introduction Recursion
C Programming Tutorial – Part I
Review: NFA Definition NFA is non-deterministic in what sense?
Programming in C Input / Output.
Lecture 7 CSE 331 Sep 15, 2010.
Lecture 6 CSE 331 Sep 13, 2010.
More About Data Types & Functions
S. Raskhodnikova; based on slides by K. Wayne
IPC144 Week 10 – Lesson 2 Working with Files
FILE HANDLING IN C.
File Input and Output.
Java for Beginners University Greenwich Computing At School DASCO
Lecture 10 CSE 331 Sep 21, 2012.
Lecture 6 CSE 331 Sep 12, 2011.
An Introduction to STL.
0,1,2,3,4 pointer of 1,2,3 and 4. This is a wrapup that requires user action. housekeeping.
Week 10 - Wednesday CS221.
Chapter 1 Introduction Recursion
Presentation transcript:

CEG 221 Lesson 7: Algorithm Development From Start to Finish Mr. David Lippa

Overview Algorithm Development : Stable Marriage –What is the Stable Marriage Algorithm? Data Structure Development –struct PersonType Function Development –Populating people from a file Putting It Together Questions

Stable Marriage Algorithm Assume Equal Numbers of Men & Women One gender proposes, the other accepts/rejects proposals and can dump their current intended. –Each follow rules of engagement (ha ha) The overall algorithm: –While there are still unengaged people, go through a round of match-making

Stable Marriage: Rules of Engagement Men (Proposer) Unengaged  propose Dumped  go to next on preference list Women (Proposee) Unengaged  accept Engaged and … –Like current better  tell suitor to buzz off –Like new one better  dump fiancé for the new guy

Overall Algorithm // define data structures // make people // build preference lists while(someoneIsNotEngaged) { for each unengaged man { propose to next on preference list } // display results

Define a Person // define NAME_SIZE, NUM_PPL struct PersonType { char mName[NAME_SIZE]; struct PersonType* mpSpouse; struct PersonType* mpPreferences[NUM_PPL]; unsigned int mPreferred; int mHash; }; /* the hash value will be used in populating each person’s preference list */

Load People We need to get their preference list from the user. In this case, we will be using fprintf / fscanf, and instead of getting input or writing output from/to the terminal, we will be getting it from a file. So let’s define the file

Define Persons.txt Defined to be a list of people Then each person and his/her preference list Do this twice – one for men and for women

Make Persons.txt 5Austin David Jon Ichabod Manuel 5Anna Bertha Jamie Katherine Michelle Austin Michelle Katherine Bertha Anna Jamie David Katherine Jamie Bertha Anna Michelle Jon Jamie Anna Michelle Katherine Bertha Ichabod Jamie Anna Michelle Katherine Bertha Manuel Katherine Michelle Anna Bertha Jamie Anna David Jon Ichabod Manuel Austin Bertha Jon David Austin Manuel Ichabod Jamie Manuel Ichabod Jon Austin David Katherine David Austin Manuel Ichabod Jon Michelle Manuel Jon Ichabod Austin David

What else do we need? Finds a person by name If it doesn’t exist, it returns NULL Prototype: struct PersonType* find(struct PersonType*[], char* name); We won’t implement this function – assume that it works

Loader Pseudo Code 1) Read first line int num = how many to read Each string is a person’s name, add them to the array of structures 2) Do (1) one more time 3) For (i = 0; i < num; i++) read name find name in the list of pointers for (j = 0; j < num; j++) Read next person on preference list Find the person pointer Add person to name’s preference list 4) Do (3) one more time

Questions?