final int a = 10; for(int i=0;i<a;i+=2) { for(int j=i;j<a;j++) { System.out.print("*"); } System.out.println(); }

Similar documents
final int a = 10; for(int i=0;i<a;i+=2) { for(int j=i;j<a;j++) { System.out.print("*"); } System.out.println(); }

CSCE 145 Exam 1 Review Answers. This exam totals to 100 points. Follow the instructions. Good luck!

CSCE 145 Exam 1 Review. This exam totals to 100 points. Follow the instructions. Good luck!

== isn t always equal?

Where does the insert method place the new entry in the array? Assume array indexing starts from 0(zero).

COL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi

CMSC Introduction to Algorithms Spring 2012 Lecture 7

CSE 143 SAMPLE MIDTERM

Basic Data Structures

Stacks and Queues. Introduction to abstract data types (ADTs) Stack ADT. Queue ADT. Time permitting: additional Comparator example

Basic Data Structures 1 / 24

CS171 Midterm Exam. October 29, Name:

CS24 Week 4 Lecture 2

Stacks and Queues

Name CPTR246 Spring '17 (100 total points) Exam 3

All the above operations should be preferably implemented in O(1) time. End of the Queue. Front of the Queue. End Enqueue

.:: UNIT 4 ::. STACK AND QUEUE

CSE 143 Sample Midterm Exam #7 (11wi)

CMSC 132: Object-Oriented Programming II. Stack and Queue

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

CSE 143. Lecture 4: Stacks and Queues

Interfaces & Generics

Linked Lists. References and objects

CSE 143, Winter 2009 Sample Midterm Exam #2

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

Building Java Programs

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010

CMSC 132, Object-Oriented Programming II Summer Lecture 9:

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues

Queues. Stacks and Queues

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

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

Lesson 3: Understanding General Software Development

Stack and Queue. Stack:

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10

16-Dec-10. Collections & Data Structures ABSTRACTION VS. IMPLEMENTATION. Abstraction vs. Implementation

CSE 373 SEPTEMBER 29 STACKS AND QUEUES

1. Introduction. Lecture Content

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues

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

How to Win Coding Competitions: Secrets of Champions. Week 2: Computational complexity. Linear data structures Lecture 5: Stack. Queue.

Data Structure Advanced

Building Java Programs

: Principles of Imperative Computation, Spring Homework 3 Theory [Update 1]

Day 6. COMP1006/1406 Summer M. Jason Hinek Carleton University

Linked Structures. See Section 3.2 of the text.

Write a program to implement stack or any other data structure in Java ASSIGNMENT NO 15

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

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues

List, Stack and Queue Implementation

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CSE 373 Data Structures and Algorithms. Lecture 2: Queues

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )

CSE 143 SAMPLE MIDTERM SOLUTION

csci 210: Data Structures Stacks and Queues

COSC160: Data Structures: Lists and Queues. Jeremy Bolton, PhD Assistant Teaching Professor

Chapter 18: Stacks And Queues

CSE 143 Sample Midterm Exam #1

Section 05: Solutions

Data Abstraction and Specification of ADTs

The Stack ADT. Stacks and Queues. Stack: Illustration. What is a Stack? Accessors top size isempty

SCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING. EKT224: ALGORITHM AND DATA STRUCTURES (Stack, Queue, Linked list)


Chapter 18: Stacks And Queues. Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Advanced Java Concepts Unit 3: Stacks and Queues

1 P age DS & OOPS / UNIT II

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

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.

CS 206 Introduction to Computer Science II

A queue is a linear collection whose elements are added on one end and removed from the other

ECE Fall st Midterm Examination (120 Minutes, closed book)

CS350 - Exam 1 (100 Points)

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

Points off Total off Net Score. CS 314 Final Exam Spring 2016

Chapter 18: Stacks And Queues

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

DNHI Homework 3 Solutions List, Stacs and Queues

Abstract Data Types. Abstract Data Types

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

Announcements Queues. Queues

Stacks and Queues. Chapter Stacks

CSE 143 Sample Midterm Exam #8 (12wi)

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

#06 More Structures LIFO FIFO. Contents. Queue vs. Stack 3. Stack Operations. Pop. Push. Stack Queue Hash table

CS 2630 Computer Organization. Meeting 10/11: data structures in MIPS Brandon Myers University of Iowa

Algorithms and Data Structures Exercise I

Lists, Stacks and Queues in C. CHAN Hou Pong, Ken CSCI2100A Data Structures Tutorial 4

Stacks and Queues. EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG

No Aids Allowed. Do not turn this page until you have received the signal to start.

STACKS AND QUEUES. Problem Solving with Computers-II

Linked Lists and Abstract Data Structures A brief comparison

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

CMP Points Total Midterm Spring Version (16 Points) Multiple Choice:

Matriculation number:

Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types

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.

Transcription:

CSCE 146 Exam 1 Review Part 1 Java Review This part went over the basics of Java, and the focus was mostly on arrays. There will be no questions that involve reading from and writing to files. Short Answer 1. Given this programming snippet, what will print out at the end? final int a = 10; for(int i=0;i<a;i+=2) for(int j=i;j<a;j++) System.out.print("*"); System.out.println(); 2. Will this piece of code give an error? If so why? If not what will it print out? int[] a = 1,2,3,4,5,6,7,8,9,10; for(int i=1;i<5;i++) System.out.println(a[i]); System.out.println(a[i*2]);

3. Given this programming snippet, what will print out at the end? int[][] a = new int[5][5]; for(int i=0;i<a.length;i++) for(int j=0;j<a[i].length;j++) a[i][j] = i+j; for(int i=1;i<a.length;i+=2) for(int j=a.length-1;j>=0;j-=2) System.out.print(a[i][j]+" "); System.out.println();

Programming 4. Write a method that takes in an of integers array and will print out any values in array that are divisible by 7 public void printout7s(int[] a) //PUT YOUR CODE HERE 5. Write a static method that takes two vectors (1D arrays) of integers, subtracts them, and then returns the results. Also both arrays should be the same size or else return null.

Part 2 Linked Lists Building on arrays, we introduce a new way to group together like information. Using nodes which contain data and links, we created a resizable collection of data. Short Answer 6. What s one of the greatest advantages of using a linked list over an array? 7. Given the linked list below, redraw the links after a new node is inserted after the node that contains 4. Indicate new links by arrows and mark out the broken links. Also assume the new node contains the value 8 3 12 4 20

Programming 8. Write a method that inserts a new value after another a given value in a linked list of integers. If a node with the given value doesn t exist put the new node and new value at the end. The method should not return any values and should take in both the value being search for and also the value to be added. Also assume that nodes have both data and link values as seen in given code description.

9. Write a method that removes all instances strictly less than a given value in an integer linked list. This method should not return anything and is given the value which will determine if a node is removed. Also assume that nodes have both data and link values as seen in given code description.

Part 3 Queues Grouping data on the principle first in first out (FIFO) we learned how add data (enequeue) and remove data (dequeue) in these elegant data structures. It is important to know how the operations enequeue, dequeue, and peek all work using either arrays or linked lists. 10. Given this programming snippet, what will print out at the end? Add is the same as enqueue and remove is the same as dequeue. Queue<Integer> intqueue = new LinkedList<Integer>(); for(int i=0;i<21;i+=3) intqueue.add(i); while(intqueue.size()>3) intqueue.remove(); for(int i : intqueue) System.out.println(i);

11. Given and initial queue these lines of pseudo-code, fill in how the queue looks after each step. 1. Dequeue 3 times 2. Enqueue 7 3. Enqueue 12 4. Enqueue 23 5. Dequeue 2 times 25 74 84 3 23 85 96 1 2 3 4 5

Programming 12. With the given linked list in this exam, write a method that enqueues a new node with an int value given in the parameter. Make sure to change the links properly to ensure that the data structure remains a queue.

Part 4 Stacks This data structure used the last in first out (LIFO) principle in order to add (push) and remove (pop) data. It s important to know how the operations push, pop, and peek work using either arrays or linked lists. Short Answer 13. Given this programming snippet what will print out? for(double i=0;i<100.0;i+=13.0) dubstack.push(i); for(int i=0;i<2;i++) dubstack.pop(); dubstack.push(50.0); while(dubstack.isempty()==false) System.out.println(dubStack.pop());

14. Given this pseudo-code what will the stack look like at each step. 1. Push 23 2. Pop 3 times 3. Push 18 4. Push 22 5. Pop 25 74 84 3 23 85 96 1 2 3 4 5

Programming 15. With the given linked list structure write a method for pop for a stack of type int. Integer Linked List for reference public class IntLinkedList public class ListNode int data; LinkNode link; public ListNode(int adata, ListNode alink) this.data = adata; this.link = alink; ListNode head; ListNode tail;