! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

Similar documents
l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first

CS 216 Exam 1 Fall SOLUTION

Ch. 17: Linked Lists. Introduction to Linked Lists

CSCE 2014 Final Exam Spring Version A

Dynamic Data Structures

Week 3: Pointers (Part 2)

First Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19

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

1. Write step by step code to delete element from existing Doubly Linked List. Suppose that all declarations are done

! A data structure representing a list. ! A series of dynamically allocated nodes. ! A separate pointer (the head) points to the first

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

CSE030 Fall 2012 Final Exam Friday, December 14, PM

Programming Assignment 2

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

Computer Science Foundation Exam. Dec. 19, 2003 COMPUTER SCIENCE I. Section I A. No Calculators! KEY

Computer Programming II C++ (830)

! A data type for which: ! An ADT may be implemented using various. ! Examples:

Midterm Review. PIC 10B Spring 2018

Cpt S 122 Data Structures. Data Structures

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

Question Q1 Q2 Q3 Q4 Q5 Q6 Q7 Total

Computer Programming II Python

CS171 Midterm Exam. October 29, Name:

Basic Data Structures (Version 7) Name:

Review for Test 1 (Chapter 1-5)

CS 311 Data Structures and Algorithms, Fall 2009 Midterm Exam Solutions. The Midterm Exam was give in class on Wednesday, October 21, 2009.

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

CS201- Introduction to Programming Current Quizzes

Problem One: Loops and ASCII Graphics

Linked Lists. Gaddis Ch. 17. CS 2308 :: Spring 2016 Molly O'Neil

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

This exam is worth 24 points, or 24% of your total course grade. The exam contains six

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

Summer Final Exam Review Session August 5, 2009

Introduction to Computer Science Midterm 3 Fall, Points

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

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

CS24 Week 4 Lecture 2

Name: I. 20 II. 20 III. 20 IV. 40. CMSC 341 Section 01 Fall 2016 Data Structures Exam 1. Instructions: 1. This is a closed-book, closed-notes exam.

Exam 3 Chapters 7 & 9

A linear-list Data Structure where - addition of elements to and - removal of elements from are restricted to the first element of the list.

Data Structure (CS301)

Dynamic Memory Allocation

Homework #3 CS2255 Fall 2012

Ch 8. Searching and Sorting Arrays Part 1. Definitions of Search and Sort

LECTURE 03 LINKED LIST

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

UNIT 6A Organizing Data: Lists Principles of Computing, Carnegie Mellon University

Part I: Short Answer (12 questions, 65 points total)

CS24 Week 3 Lecture 1

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

An Introduction to Trees

CS350 - Exam 1 (100 Points)

Data Structures (CS301) LAB

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Multiple choice questions. Answer on Scantron Form. 4 points each (100 points) Which is NOT a reasonable conclusion to this sentence:

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

Computer Science Foundation Exam

Introduction to the Stack. Stacks and Queues. Stack Operations. Stack illustrated. elements of the same type. Week 9. Gaddis: Chapter 18

Pointers and Arrays CS 201. This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book.

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

Largest Online Community of VU Students

UNIVERSITY REGULATIONS

CS201 Some Important Definitions

FORM 2 (Please put your name and form # on the scantron!!!!)

Data Structure Advanced

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first

UNIT 6A Organizing Data: Lists. Last Two Weeks

1 Short Answer (7 Points Each)

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

! A data type for which: ! In fact, an ADT may be implemented by various. ! Examples:

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

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012

Largest Online Community of VU Students

Computer Science E-22 Practice Final Exam

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

Definition of Stack. 5 Linked Structures. Stack ADT Operations. ADT Stack Operations. A stack is a LIFO last in, first out structure.

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

! Pass by value: when an argument is passed to a. ! It is implemented using variable initialization. ! Changes to the parameter in the function body

Midterm Exam (REGULAR SECTION)

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

CSCI-1200 Data Structures Fall 2017 Lecture 7 Order Notation & Basic Recursion

SYSC 2006 CD. Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

CS 206 Introduction to Computer Science II

Ashish Gupta, Data JUET, Guna

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion

Run Time Environment

Transcription:

Final Exam Exercises Chapters 1-7 + 11 Write C++ code to:! Determine if a number is odd or even CS 2308 Fall 2018 Jill Seaman! Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)! Assign a category based on ranges (wind speed)!1 - Tropical Depression: <38mph - Tropical Storm: 39-73mph - Hurricane: >=74mph!2 Write C++ code to: Chapters 1-7 + 11! Pass arguments by value and reference - Return multiple values from a function: compute the area AND perimeter of a rectangle! Process an Array: - find maximum/minimum value - sum/average the values in the array - count values passing a test (such as >100) Binary Search Example The target of your search is 39. Given the following array of integers (values on top, indexes on bottom), record the values that 39 is compared to in each iteration of a binary search. 1 7 8 14 20 42 55 67 78 101 112 122 170 179 190 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Repeat the exercise with a target of 179. Solution for 39 (which is not in the list): 67 14 42 20!3!45

Example Sorting Problem Given the following list of integers, show what order the integers would be in after executing: a) one complete pass of the bubble sort b) two passes of the selection sort. Assume the following numbers are in an array (subscripts along the bottom). 112 73 8 140 22 42 88 67 0 1 2 3 4 5 6 7!5 Big O Notation In order of increasing growth (less efficiency) - O(1) constant - O(log n) logarithmic - O(n) linear - O(n log n) linearithmic - O(n 2 ) quadratic when using big O notation to describe the efficiency of an algorithm: - what does n represent? - what does the function inside the ( ) describe?!6 Give the efficiency of each using big-o notation! Linear search! Binary search on an already sorted list! Bubble sort! Selection sort! Access one element in an array! Array processing: - sum, average, show list, find max/min - delete all elements!7 Give the efficiency of each using big-o notation! Linked list operations: - insert at head - append (with no tail pointer) - delete a node with a given value - destructor ( delete all nodes) - access one element (by index) - sum, average, show list, find max/min (traversal) if you have to traverse the list, it s O(n). if you have to traverse the list once for each element, it s O(n 2 )!8

Pointers! Tracing code with pointers, what is output? int *ptr1, *ptr2; int foo1, foo2 = 13; ptr1 = &foo1; ptr2 = &foo2; foo1 = 42; cout << "*ptr1 - " << *ptr1 << endl; cout << "*ptr2 - " << *ptr2 << endl; ptr1 = ptr2; cout << "foo1 - " << foo1 << endl; cout << "foo2 - " << foo2 << endl; ptr2 = &foo1; *ptr1 = *ptr2; cout << "foo1 - " << foo1 << endl; cout << "foo2 - " << foo2 << endl;!9 Pointers! Rewrite using pointer notation instead of [ ]: for (int x = 0; x < 100; x++) cout << array[x] << endl;! Write a function to swap the values of its parameters, using pointers instead of pass by reference.! Write a function to double the size of an array, by dynamically allocating a new array that is twice as big, and copying the elements from the original. - who is responsible for deallocating this dynamically allocated array? What statement is used to deallocate it?!10 Linux Commands! What linux command would you use to: A. List (display) the files in the current directory? B. Display the name of the current directory? C. Make a new directory called Assignments? D. Make Assignments the current directory? E. Edit a file called myfile.txt? F. Compile a file called myprog.cpp? G. View the contents of myprog.cpp on the screen? H. Delete the file myprog.cpp? I. Execute a makefile? J. Compile a file called a.cpp to an object file?!11 Classes! Give the class declaration, and function implementations: Consider a Student class, which stores a student using three values: a name (string) an ID number (int) and a grade (double). It has 2 constructors (one default, one with 3 arguments), and set and get function for the name and grade. The default student has an empty string for the name, and 0 for the other two variables. The other constructor takes the initial name, ID number, and grade. There is a function print() that outputs the three values. The student also has a function letter() that calculates and returns the letter grade corresponding to the grade ( A if grade is 90 or more, B if grade is 80 or more (but less than 90), etc).!12

Linked Lists: find four errors int main() { struct node { node * next; // create empty list node * head; // insert six nodes at front of list node *n; for (int i=0;i<=5;i++) { n = new node; n->data = i; n->next = head; // print list n = head; while (!n) { cout << n->data << " "; n = n->next; cout << endl;!13 Linked Lists! Write a function that takes an array of ints and converts it to a linked list by inserting each element to the front of the list (the order will be reversed). Return a pointer to the first node. struct Node { Node *next; ; Node *convertreverse (int list[], int size) { Spoiler alert! Solution on next slide.!14 Linked Lists! Write a function that takes an array of ints and converts it to a linked list by inserting each element to the front of the list (the order will be reversed). struct Node { Node *next; ; Node *convertreverse (int list[], int size) { Node *head = NULL; for (int i=0; i<size; i++) { Node *newnode = new Node; newnode->data = list[i]; newnode->next = head; head = newnode; return head;!15 Stacks and Queues exercises Suppose the following operations are performed on an empty stack. Insert numbers in the diagram to show what will be stored in the stack after the operations have executed (label the top): int x; push(3); push(5); push(9); x = pop(); push(2); x = pop(); push(0);!16

Stacks and Queues exercises Suppose the following operations are performed on an empty queue. Insert numbers in the diagram to show what will be stored in the queue after the operations have executed (label the front+rear): int x; enqueue(3); enqueue(5); enqueue(9); x = dequeue(); enqueue(2); x = dequeue(); enqueue(0);!17 Disclaimer! The exercises in this lecture do not cover ALL of the material that will be on the final exam.! These exercises do provide some sample exam questions (though many will be in multiple choice format on the exam).! There will be questions that will require writing programs or functions or class declarations and implementations.! There will be questions (mostly multiple choice) that will test your understanding of the concepts we have covered (vocabulary, etc).!18