1 Midterm Review (overview of fall 2005 midterm) Professor Jennifer Rexford COS 217.

Slides:



Advertisements
Similar presentations
Pointers.
Advertisements

Stacks, Queues, and Linked Lists
Linked Lists.
CSCE 3110 Data Structures & Algorithm Analysis
C and Data Structures Baojian Hua
418115: II. Linked List A linked list can be thought of a chain of linked list elements. A linked list element contains a single data item, and contains.
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
1 Abstract Data Types. Objectives To appreciate the concept and purpose of abstract data types, or ADTs To understand both the abstract behavior and the.
Data Structures (Second Part) Lecture 3 : Array, Linked List, Stack & Queue Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 7 : September 8.
C Programming : Elementary Data Structures 2009/04/22 Jaemin
Week 7 - Friday.  What did we talk about last time?  Allocating 2D arrays.
1 Abstract Data Types (ADTs) Professor Jennifer Rexford COS 217.
CSE1303 Part A Data Structures and Algorithms Lecture A7 – Nodes and Linked Structures.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Linked List C and Data Structures Baojian Hua
1 Midterm Review (overview of fall 2005 midterm) Professor Jennifer Rexford COS 217.
1 Inner Workings of Malloc and Free Professor Jennifer Rexford COS 217.
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A5 – Basic Data Structures – Continued (Lists)
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
Data Structures Week 5 Further Data Structures The story so far  We understand the notion of an abstract data type.  Saw some fundamental operations.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Linked Lists. Dynamic Data Structure Applications –where amount of required memory is determined at run-time.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
CSC2100B Tutorial 2 List and stack implementation.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
Chapter 8 Queue I CS Data Structures I COSC2006 April 24, 2017
Collection Classes Eric Roberts CS 106B January 14, 2013 (Part 1: Vectors, Grids, Stacks, and Queues)
1 Data Structures - Part II CS215 Lecture #8. Stacks  Last-In-First-Out (LIFO)  Stacks are often used in programming when data will need to be used.
Abstract Data Type (ADT) – visit 3/4 1.'is_mem_av()' Semantics Definitions: none, strong and weak semantics ULz data type and sketch of data structure,
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 11 – Data Structures.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
CS261 Data Structures Linked Lists - Introduction.
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
1 Midterm Exam COS Midterm Exam Statistics  Average score: 72  Median score: 76  Range of scores: More detailed breakdown  6 people.
Advanced Pointers and Structures Pointers in structures Memory allocation Linked Lists –Stacks and queues Trees –Binary tree example.
1 Function Pointers and Abstract Data Types CS 217.
CISC220 Spring 2010 James Atlas Lecture 04: Pointers, Functions, Memory Management, ADTs, Classes, Hardware, Software, Graphics, Networking, AI, Databases,
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Queues Dale Roberts, Lecturer
Chapter 12 – Data Structures
Abstract Data Types in C
5.13 Recursion Recursive functions Functions that call themselves
Data Structures and Algorithms
Stack and Queue APURBO DATTA.
Programmazione I a.a. 2017/2018.
Pointers and Linked Lists
CSC215 Homework Homework 11 Due date: Dec 19, 2016.
Lists.
Linked Lists.
Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.
CSC 143 Queues [Chapter 7].
Queues: Implemented using Arrays
Review & Lab assignments
Data Structures and Algorithms
CS148 Introduction to Programming II
Python: Stacks and Queues (as an Array)
Chapter 9: Pointers and String
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
Abstract Data Types (ADTs), After More on the Heap
Queues: Implemented using Linked Lists
Abstract Data Types Stacks CSCI 240
Presentation transcript:

1 Midterm Review (overview of fall 2005 midterm) Professor Jennifer Rexford COS 217

2 1. Modulo Arithmetic and Character I/O void f(unsigned int n) { do { putchar(‘0’ + (n % 10)); } while (n /= 10); putchar(‘\n’); } What does f(837) produce? What does this function do?

3 1. Modulo Arithmetic and Character I/O void f(unsigned int n){ for ( ; n; n /= 10) putchar(‘0’ + (n % 10)); putchar(‘\n’); } When is the answer different?

4 2. Pointers and Strings void f(char *s) { char *p = s; while (*s) s++; for (s--; s>p; s--,p++) { char c = *s; *s = *p; *p = c; } What does this function do?

5 3. Short Answer In the memory layout for a UNIX process:  Why does the heap grow from the top down and the stack from the bottom up, instead of both growing from the top down or both growing from the bottom up? Text Data BSS Stack Heap

6 4. Deterministic Finite Automata Valid numbers  “-34”  “78.1”  “+298.3”  “-34.7e-1”  “34.7E-1”  “7.”  “.7”  “999.99e99” Invalid numbers  “abc”  “-e9”  “1e”  “+”  “17.9A”  “0.38+”  “.”  “38.38f9” Identify whether or not a string is a floating-point number

7 4. Deterministic Finite Automata Optional “+” or “-” Zero or more digits + - # # #

8 4. Deterministic Finite Automata Optional “+” or “-” Zero or more digits Optional decimal point  Followed by zero or more digits. + - # # ## #..

9 4. Deterministic Finite Automata Optional “+” or “-” Zero or more digits Optional decimal point  Followed by zero or more digits. # # ## #. Optional exponent “E” or “e”  Followed by optional “+” or “-”  Followed by one or more digits. E E e e # # #

10 5: Abstract Data Types Interface for a Queue (a first-in-first-out data structure) #ifndef QUEUE_INCLUDED #define QUEUE_INCLUDED typedef struct Queue_t *Queue_T; Queue_T Queue_new(void); int Queue_empty(Queue_T queue); void Queue_add(Queue_T queue, void* item); void* Queue_remove(Queue_T queue); #endif

11 5: Abstract Data Types An implementation for a Queue #include #include "queue.h" struct list { void* item; struct list *next; }; struct Queue_t { struct list *head; struct list *tail; }; Why void*? Why declared here and not in queue.h?

12 5: Abstract Data Types An implementation for a Queue_new Queue_T Queue_new(void) { Queue_T queue = malloc(sizeof *queue); assert(queue != NULL); queue->head = NULL; queue->tail = NULL; return queue; } Implement a check for whether the queue is empty.

13 5: Abstract Data Types An implementation for a Queue_empty int Queue_empty(Queue_T queue) { assert(queue != NULL); return queue->head == NULL; }

14 5: Abstract Data Types An implementation for a Queue_add 321 head tail 0 newnode 321 head tail 0

15 5: Abstract Data Types An implementation for a Queue_add head tail 0 newnode 0 head tail NULL

16 5. ADT Common Mistakes Adding to the queue  Implementing a stack rather than a queue –Adding element to the head, rather than the tail  Not handling the case where the queue is empty  Missing assert() after call to malloc() for new entry Removing from the queue  Missing assert() when removing an element from an empty queue  Not handling removing the last item from the queue  Not doing a free() to return space used by the head element

17 Preparing for the Exam Studying for the exam  Read through lecture and precept nodes  Study past midterm exams  Read through exercises in the book Exam logistics  Wednesday 10-10:50am in COS 105 (regular place and time)  Open book, open notes, open mind… just no computer  No questions on UNIX tools (e.g., emacs, gcc, gdb, …) No Wednesday/Thursday precept this week  Have a great spring break!