Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Similar documents
Linked List using a Sentinel

moretosearch = (location < length);

[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 9. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University

Review Questions for Final Exam

Midterm Exam. Sample Solutions

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

CSCE 110 PROGRAMMING FUNDAMENTALS

CMSC 202 Midterm Exam 1 Fall 2015

The Memory Manager Project

Exceptions, Case Study-Exception handling in C++.

Lists. linking nodes. constructors. chasing pointers. MCS 360 Lecture 11 Introduction to Data Structures Jan Verschelde, 17 September 2010.

Midterm Practice TA: Brian Choi Section Webpage:

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

Name. CPTR246 Spring '17 (100 total points) Exam 2

CS 225. Data Structures

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

CS 103: Introduction to Programming Fall Written Final Exam 12/11/16, 4:30PM 6:30PM

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

Computer Programming

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

Data Structures (CS301) LAB

CS 103 Unit 15. Doubly-Linked Lists and Deques. Mark Redekopp

CHAPTER 3 BASIC INSTRUCTION OF C++

Ch. 17: Linked Lists. Introduction to Linked Lists

CSCE121: Introduction to Program Design and Concepts Practice Questions for Midterm 3

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

CSCE 110 PROGRAMMING FUNDAMENTALS

Object oriented programming

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

do { statements } while (condition);

CS 141, Introduction to Computer Science Fall Midterm Exam

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

Do not turn to the next page until the start of the exam.

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

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)

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

CS 115 Exam 3, Spring 2010

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

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Multiple Choice Questions (20 questions * 5 points per question = 100 points)

CS 455 Final Exam Spring 2015 [Bono] May 13, 2015

Introduction to Programming

University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway

2. It is possible for a structure variable to be a member of another structure variable.

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CS 376b Computer Vision

Queue Implementations

Midterm Practice Exam

Spring 2008 Data Structures (CS301) LAB

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

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

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review Questions for Final Exam KEY

1 #include <iostream> 2 using namespace std; 3 4 // implementing the dynamic List ADT using Linked List 5 6 class Node{ 7 8 private: 9 int data; 10

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

Example Final Questions Instructions

VARIABLES & ASSIGNMENTS

Student Name and ID CS 32, WINTER 2015, PRACTICE MIDTERM I.

Lecture 7. Log into Linux New documents posted to course webpage

Integer Data Types. Data Type. Data Types. int, short int, long int

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

! 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)

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

Lab Instructor : Jean Lai

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

lecture09: Linked Lists

Perfect square. #include<iostream> using namespace std; int main(){ int a=1; int square; while(true){ } cout<<square<<endl; }

Programming with Recursion. What Is Recursion?

Increment and the While. Class 15

Apllications. March 03, Indian Institute of Space Science and Technology. MA122 - Computer Programming and. Apllications.

CS 115 Midterm 2A Solutions

Name: UTLN: CS login: Comp 15 Data Structures Midterm 2018 Summer

Tutorial Letter 102/1/2012 Programming: Data Structures

CSC1322 Object-Oriented Programming Concepts

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

pointers + memory double x; string a; int x; main overhead int y; main overhead

Unit 7. 'while' Loops

REVIEW. The C++ Programming Language. CS 151 Review #2

EE 109 Lab 8a Conversion Experience

Chapter 2: Introduction to C++

Lecture 23: Pointer Arithmetic

CS 115 Midterm 2 Solutions

Ch 6. Functions. Example: function calls function

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

Due Date: See Blackboard

Exercises with Linked Lists CS 16: Solving Problems with Computers I Lecture #15

Security Coding Module - Buffer Overflow Data Gone Wild CS1

EE 355 Unit 11b. Doubly-Linked Lists and Deques. Mark Redekopp

ADT Unsorted List. Outline

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Chapter 13. Recursion. Copyright 2016 Pearson, Inc. All rights reserved.

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

CS32 Final Exam. E03, F15, Phill Conrad, UC Santa Barbara

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

First Chocolate Code-Off for CISC220 Fall 17

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, November 24, 2015

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.

Al Imam Mohammad Ibn Saud Islamic University College of Computer and Information Sciences Computer Science Department

Transcription:

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A Name: ID#: Section #: Day & Time: Instructor: Answer all questions as indicated. Closed book/closed Notes. No Questions and NO PDAs (calculators, handheld devices, cell phones, etc.) are allowed. Q1) Consider the following ordered linked list. Each node is based on the struct named nodetype,which is defined as follows: struct nodetype int info; nodetype* link; First Last 3 3 5 7 9 10 Count C Q1.1) What is the output of the following code? (12 Points; 3 points each) cout << First->info << endl; cout << (First->link->info == c->info)<<endl; cout << c->link->link->info << endl; c = c->link->link; cout << c->info << endl; 3 0 9 9 Page 1 of 5

Q1.2) Write a single C++ statement to do the following (9 Points) A. Make the pointer c points to the Second Node with info equals to 3? (3 Points) c = First->link; B. Set the info of first node to 2 instead of 3? (3 Points) First->info = 2; C. Set the info of last node to 15 instead of 10? (3 Points) Last->info = 15; Q2) Consider the following figure which represents a doubly linked list. Each node is based on the struct named nodetype, which is defined as follows: struct nodetype int info; nodetype* next; nodetype* back; First p Last Count 5 2 4 8 10 Q2.1) What is the output of the following code? (12 Points; 3 points each) cout << p->next->back->info; cout << First->next->next->info; p = p->back; cout << p->back->next->next->info; cout << Last->back->back->info; Page 2 of 5

Q2.2) Write the required code to insert a new node with number 7 between and 8. There is no need to search for the required location just add the node pointed to by q. Please ignore the changes that you have made in the previous question. (12 Points) q 7 q->next = p->next; q->back = p; p->next->back = q; p->next = q; Q3) When you answer the questions 3.1, 3.2, 3.3, and 3.4, please consider carefully the definition of the following program: #include <iostream> using namespace std; struct node int info; node * link; ; class linkedlisttype private: node *head; public: linkedlisttype() head = NULL; int getnodescount(void); // Returns the number of nodes currently available in the linked list int replacealloccurr(int oldval, int newval) // Replaces all occurrences of the oldval with newval within the list int findsecondoccurr(int item); // Finds the position (Node Number) of the second occurrence of an item // within the list. // More member functions for usual list operations ; Page 3 of 5

Q3.1) Write the implementation of the member function named: int getnodescount(void); It returns the number of nodes currently available in the linked list. (11 Points) int linkedlisttype::getnodescount() s while( p!= NULL ) // 2 Points // 2 Points Q3.2) Write the implementation of the member function named: int replacealloccurr(int oldval, int newval); This function finds all occurrences of an existing value (oldval) and replaces them with a new value (newval) and returns the number of replaced item. (12 Points) int linkedlisttype::replacealloccurr(int oldval, int newval) s while( p!= NULL ) if (p->info == oldval) p->info = newval; // 2 Point Page 4 of 5

Q3.3) Write the implementation of the member function named: int findsecondoccurr(int item); It returns the node number of the second occurrence of an item within the list. Otherwise, if the item is not present in the list for at least two times, this function should return a zero. (22 Points) int linkedlisttype::findsecondoccurr(int item) bool found; bool first; found = false; first = false; while( p!= NULL &&!found) if ( p->info == item ) if (first == false) first = true; else found = true; if (found) else return 0; // 2 Point Q3.4) What is the Time-Complexity (Big O notation) for the functions you provided in: (10 Points) Q3.1: O(n) Q3.2: O(n) Q3.3: O(n) // 4 Points Page 5 of 5