CompSci61B, Data Structures Final Exam


 Primrose Harvey
 2 years ago
 Views:
Transcription
1 Your Name: CompSci61B, Data Structures Final Exam Your 8digit Student ID: Your CS61B Class Account Login: This is a final test for mastery of the material covered in our labs, lectures, and readings. It consists of 11 questions worth a total of 100 points. Circle the correct answer for the multiplechoice questions, and write in the space provided for the essay questions. This exam is open book and open note. Partial credit is possible. 1. Write a class file for compsci61b.mystack, extending your compsci61b.myarraylist class, with the following changes: [12 points] add O(1) versions of public boolean push(t value), public T pop(), and public T peek(). iterate from most recently added value to oldest value pop order (that is, FILO) throw UnsupportedOperationExceptions (with any text you want) for the 2 add methods, remove, and the iterator s remove. Here is a list of the methods in compsci61b.myarraylist: public MyArrayList() public boolean add(t value) public boolean add(int, T value) public T remove(int index) public void clear() public boolean replace(int index, T value) public T getentry(int index) public boolean contains(t value) public int size() public boolean isempty() public boolean isfull() public String tostring() public Iterator<T> iterator()  should be in FILO order package compsci61b; public class MyStack<T> extends MyArrayList<T> Write your code here: CompSci61B Midterm Exam, page 1 continued on next page
2 Write your code here (continued): CompSci61B, Data Structures Final Exam CompSci61B Midterm Exam, page 2
3 2. Write a class file for compsci61b.myprorityqueue, extending your compsci61b.mysortedlinkedlist class, with the following changes: [10 points] add public T poll() and public T peek(). ( poll should return the smallest value in the queue, or null if the queue is empty) throw UnsupportedOperationExceptions (with any text you want) for the add methods, remove, and the iterator s remove. Here is a list of the methods in compsci61b. MySortedLinkedList: public boolean remove(t value) public boolean add(t value) public boolean contains(t value) public boolean add(int index, T value) unsupported operation throws an exception public boolean replace(int index, T value) unsupported operation throws an exception public T getentry(int index) public boolean contains(t value) public int size() public boolean isempty() public boolean isfull() public String tostring() public void clear() public Iterator<T> iterator() should be in order smallest to largest package compsci61b; public class MyStack<T> extends MyArrayList<T> Write your code here: CompSci61B Midterm Exam, page 3
4 3. Rewrite MySortedArrayList.add so that it has a best case of O(1): [6 points] public boolean add(t value) // the original version, O(n) efficiency if (value == null) return false; if (nvalues == data.length) doublethearraysize(); // find the insertion location int index = 0; for (; index < nvalues; index++) if (value < data[index]) break; // shift (if necessary) and insert for (int i = nvalues; i > index; i) data[i] = data[i  1]; // move right data[index] = value; // copy into array ++nvalues; return true; public boolean add(t value) // the rewritten version with an O(1) best case Write your code here: CompSci61B Midterm Exam, page 4
5 4. Imagine that you are grading the programming exercise on binary search trees for a future CS61B class and to make your job easier, you decided program a method "isbst" that would tell you whether the binary trees constructed by your students are actually Binary Search Trees. That is, isbst should return true if the input Binary Tree satisfies the Binary Search Tree property and false if not. (Assume that the input is a valid binary tree we just want to see if it is also a binary search tree.) These trees do not implement generics they store Integer values. Assume that you would copy/paste this method into the students submitted source code, and place calls to the method in the students main test code. All students name the private inner node class the same, per the lab specifications. Your program must run in time linear to the size of the input tree. [15 points]...package and import statements... public class MyBinaryTree // per the specification private class Node // per the specification private Integer value; // per the specification private Node left; // per the specification private Node right; // per the specification...possibly methods here......student s code (not you!)... public boolean isbst(node tree) // copy/paste this into student s code Write your code here: CompSci61B Midterm Exam, page 5 continued on next page
6 Write your code here (continued): CompSci61B, Data Structures Final Exam...student s code (not you!), including main test method... CompSci61B Midterm Exam, page 6
7 5. Explain the big oh efficiency for "contains" for each of the following (Circle one each) [6 points total] unsorted array: (a) O(1) (b) O(log n) (c) O(n) (d) O(n log n) [1.5 points] sorted linked list: (a) O(1) (b) O(log n) (c) O(n) (d) O(n log n) [1.5 points] balanced binary tree: (a) O(1) (b) O(log n) (c) O(n) (d) O(n log n) [1.5 points] chained hash table: (a) O(1) (b) O(log n) (c) O(n) (d) O(n log n) [1.5 points] 6. Regarding hash tables: [15 points total] a. While using a hash table with chaining and no maximum load factor, you found out that you inserted too many elements into the table. To be more precise, you actually inserted n log n elements into the hash table whose array size is n. (a) What would be the average lookup time for your hash table now? (b) What if you doubled the size of the Hash Table and rehashed the same elements, what would be the average lookup time now? Assume that you can insert however many elements you want in whatever order you want using whatever hash function you want. Express the answers in big oh notation. [4 points] Answer here: a. b. b. You have two hash tables of the same size, and they are hashing the same set of keys using the same hash function. However, one hash table uses linear probing and one uses chaining. Suppose you can insert however many elements you want in whatever order you want, is it possible for one hash table to have, on average, linear time lookup speed while the other has, on average, constant time lookup speed? Explain. [7 points] Answer here: c. In our implementation of linear probing in hash tables, our array elements could be entry references, null, or blank. What is the purpose of using blanks instead of nulls? [4 points] Answer here: CompSci61B Midterm Exam, page 7
8 7. Specify which data structure you would use in each of these scenarios. Choose from one of the following. If multiple answers are possible, choose the most efficient one. Briefly explain your choices. [9 points total] Queue Stack Priority Queue Binary Search Tree Graph Hash Table a. You're simulating a keyboard and would like to process the keystrokes and then print them on the screen. [1.5 points] b. You need to process the service events for lab 8 but now, the events all take the same amount of time to complete. [1.5 points] c. You're writing a graph traversal program and you would like to use a separate additional data structure to keep track of whether a vertex has been visited or not. [1.5 points] d. You're writing expression parsing program for an early HP calculator that uses reverse polish notation. [1.5 points] e. You want to be able to input the prices of many different cars, and then find cars that are neither too expensive nor too cheap for your customers. [1.5 points] f. You would like to store all possible board configurations for the game of chess and you also want to store what moves you can make to reach one configuration from another. [1.5 points] CompSci61B Midterm Exam, page 8
9 8. Suppose we modify the depthfirst traversal algorithm for a graph to push the node into a stack before traversing its neighbors and then pop the stack at the end, in accordance with the following pseudocode: boolean traverse(vertex v) stack.push(v);... preprocess v... forall Vertex u where (v, u) is an edge if (!stack.contains(v)) traverse(u); stack.pop();... postprocess v... Answer the following 2 questions Provide examples: [7 points total] a. Will this modified depthfirst search algorithm work on a directed graph (digraph), ie. have the same behavior as the normal depthfirst search? [5 points] b. Will it work on an undirected graph? [2 points] CompSci61B Midterm Exam, page 9
10 9. Write a static method which is supposed to take an array of ints between 0 and m inclusive, and count the number of repetitions in the array. The array and m are arguments in the method s parameter list. For example, an array of 1, 3, 1, 4, 3, 3 has 3 repetitions, because the number 1 repeats once and the number 3 repeats twice. Furthermore, your program needs to run in time O(n+m) where n is the size of the array. The variable count is a hint, you don't need to use it you may cross it out  and you can declare any variables of your own. [10 points] public static int countrepetitions(int[] arr, int m) int[] count = new int[m + 1]; Write your code here: CompSci61B Midterm Exam, page 10
11 10. In a graph representation of a maze, the entry point is called A and the exit is Z. There is only one direct path through the maze (without doubling back or circling). Which traversal method(s) will find the direct route from A to Z? Assume that the maze is represented by a series of nodes at the decision points, and the edges include the distance between nodes. (Circle all that apply, and explain) [4 points] (a) depth first (b) breadth first (c) shortest route (d) cheapest route 11. In the BST shown to the right, the value I inside in the node marked 1 is to be removed. This may involve the swapping of values among nodes, and will involve the removal of one node. There are two possible solutions to this problem  identify the changes, in order, for both: [6 points] First possible solution (fill in the blanks): Put value into node # Remove node # Second possible solution (fill in the blanks): Put value into node # Put value into node # Put value into node # Put value into node # Remove node # use as many of these blank as you need CompSci61B Midterm Exam, page 11
CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.
Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure
More information12 Abstract Data Types
12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).
More informationData Structures and Algorithms Written Examination
Data Structures and Algorithms Written Examination 22 February 2013 FIRST NAME STUDENT NUMBER LAST NAME SIGNATURE Instructions for students: Write First Name, Last Name, Student Number and Signature where
More informationDATA STRUCTURES USING C
DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give
More informationBuilding Java Programs
Building Java Programs Iterators, hashing reading: 11.1, 15.3 Making hash browns... (We're talking about hashing. It makes sense.) 2 List Case Study 3 Linked list performance The following code is particularly
More informationKrishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA213 : DATA STRUCTURES USING C
Tutorial#1 Q 1: Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2: What is a Data Type? Differentiate
More informationSample Questions Csci 1112 A. Bellaachia
Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k
More information1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.
1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated
More information1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++
Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The
More informationCS 210 Algorithms and Data Structures College of Information Technology and Engineering Weisberg Division of Engineering and Computer Science
CS 210 Algorithms and Data Structures College of Information Technology and Engineering Weisberg Division of Engineering and Computer Science Semester and Year: Spring 2009 Classroom Section, Meeting Times,
More informationBinary Heap Algorithms
CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn G. Chappell
More informationA binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:
Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)
More informationDefinition. E.g. : Attempting to represent a transport link data with a tree structure:
The ADT Graph Recall the ADT binary tree: a tree structure used mainly to represent 1 to 2 relations, i.e. each item has at most two immediate successors. Limitations of tree structures: an item in a tree
More informationChapter 7. Ch.7 Problem Solving and Algorithms
Chapter 7 Ch.7 Problem Solving and Algorithms QUIZ: Match the steps in Polya s method to the ones in the computer method for problem solving Devise a plan Look back Understand Carry out the plan Analysis
More informationHome Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit
Data Structures Page 1 of 24 A.1. Arrays (Vectors) nelement vector start address + ielementsize 0 +1 +2 +3 +4... +n1 start address continuous memory block static, if size is known at compile time dynamic,
More informationCS 2112 Spring 2014. 0 Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions
CS 2112 Spring 2014 Assignment 3 Data Structures and Web Filtering Due: March 4, 2014 11:59 PM Implementing spam blacklists and web filters requires matching candidate domain names and URLs very rapidly
More informationSchool of Informatics, University of Edinburgh Computer Science 1 Ah [03 04]
School of Informatics, University of Edinburgh Computer Science 1 Ah [03 04] CS1Ah Lecture Note 25 Binary Search Trees This lecture studies binary trees in more detail, in particular their application
More informationData Structure [Question Bank]
Unit I (Analysis of Algorithms) 1. What are algorithms and how they are useful? 2. Describe the factor on best algorithms depends on? 3. Differentiate: Correct & Incorrect Algorithms? 4. Write short note:
More informationState Space Problem Definition
Blind Search State Space Problem Definition One widely used way to describe problems is by listing or describing all possible states. Solving a problem means moving through the state space from a start
More informationChapter 3: Restricted Structures Page 1
Chapter 3: Restricted Structures Page 1 1 2 3 4 5 6 7 8 9 10 Restricted Structures Chapter 3 Overview Of Restricted Structures The two most commonly used restricted structures are Stack and Queue Both
More informationExam study sheet for CS2711. List of topics
Exam study sheet for CS2711 Here is the list of topics you need to know for the final exam. For each data structure listed below, make sure you can do the following: 1. Give an example of this data structure
More informationAnnouncements. FINAL EXAM Monday May 21, 1:30pm Review Session. Wednesday May 16, 79pm
Announcements FINAL EXAM Monday May 21, 1:30pm Review Session Wednesday May 16, 79pm 1 Recitation 12 Root Finding, Sorting, Stacks, Queues 2 Outline Linked Lists Sorting Queues 3 Object References Let
More informationBinary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *
Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest
More information1 23 Trees: The Basics
CS10: Data Structures and ObjectOriented Design (Fall 2013) November 1, 2013: 23 Trees: Inserting and Deleting Scribes: CS 10 Teaching Team Lecture Summary In this class, we investigated 23 Trees in
More informationCE204 Data Structures and Algorithms Part 3
CE204 Data Structures and Algorithms Part 3 23/01/2016 CE204 Part 3 1 Trees The ADTs encountered so far have been linear; list and array implementations have been adequate. We now consider a nonlinear
More informationData Structures Using Java
Data Structures Using Java D. S. Malik P. S. Nair THOMSON COURSE TECHNOLOGY Australia Canada Mexico Singapore Spain United Kingdom United States TABLE OF Contents PREFACE XXV 1.Software Engineering Principles
More informationCS104: Data Structures and ObjectOriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team
CS104: Data Structures and ObjectOriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A
More informationUNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK PSD2023 ALGORITHM & DATA STRUCTURE
STUDENT IDENTIFICATION NO UNIVERSITI MALAYSIA SARAWAK 94300 KOTA SAMARAHAN SARAWAK FAKULTI SAINS KOMPUTER & TEKNOLOGI MAKLUMAT (Faculty of Computer Science & Information Technology) Diploma in Multimedia
More informationCourse: Programming II  Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1
Definition Course: Programming II  Abstract Data Types The ADT Stack The ADT Stack is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit insertions
More informationAlgorithms and Data Structures Written Exam Proposed SOLUTION
Algorithms and Data Structures Written Exam Proposed SOLUTION 20050107 from 09:00 to 13:00 Allowed tools: A standard calculator. Grading criteria: You can get at most 30 points. For an E, 15 points are
More informationGraph. Consider a graph, G in Fig Then the vertex V and edge E can be represented as:
Graph A graph G consist of 1. Set of vertices V (called nodes), (V = {v1, v2, v3, v4...}) and 2. Set of edges E (i.e., E {e1, e2, e3...cm} A graph can be represents as G = (V, E), where V is a finite and
More informationTrees. Tree Definitions: Let T = (V, E, r) be a tree. The size of a tree denotes the number of nodes of the tree.
Trees After lists (including stacks and queues) and hash tables, trees represent one of the most widely used data structures. On one hand trees can be used to represent objects that are recursive in nature
More informationSearching and Sorting
Linear Search Searching and Sorting Binary Search Selection Sort Insertion Sort Bubble (or Exchange) Sort Exercises Unit 27 1 Linear Search Searching is the process of determining whether or not a given
More informationSorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)
Sorting revisited How did we use a binary search tree to sort an array of elements? Tree Sort Algorithm Given: An array of elements to sort 1. Build a binary search tree out of the elements 2. Traverse
More informationPriority Queues. Client, Implementation, Interface. Priority Queues. Abstract Data Types
Client, Implementation, Interface Priority Queues Priority Queue ADT Binary heaps Heapsort Reference: Chapter 6, Algorithms in Java, 3 rd Edition, Robert Sedgewick. Separate interface and implementation
More informationSocial Media Mining. Graph Essentials
Graph Essentials Graph Basics Measures Graph and Essentials Metrics 2 2 Nodes and Edges A network is a graph nodes, actors, or vertices (plural of vertex) Connections, edges or ties Edge Node Measures
More informationBig O and Limits Abstract Data Types Data Structure Grand Tour. http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.
Big O and Limits Abstract Data Types Data Structure Grand Tour http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png Consider the limit lim n f ( n) g ( n ) What does it
More informationLast not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!
ECE 551 C++ Programming, Data structures, and Algorithms Abstract Data Type: Stack Last In First Out (LIFO) 1 2 2 1 4 3 1 3 4 Stacks in Programming Worst line ever! 5 3 1 5 Stacks are not useful for waiting
More informationAS2261 M.Sc.(First Semester) Examination2013 Paper fourth SubjectData structure with algorithm
AS2261 M.Sc.(First Semester) Examination2013 Paper fourth SubjectData structure with algorithm Time: Three Hours] [Maximum Marks: 60 Note Attempts all the questions. All carry equal marks Section A
More informationClass 28: Binary Search Trees. Binary Search Trees
Introduction to Computation and Problem Solving Class 2: Binary Search Trees Prof. Steven R. Lerman and Dr. V. Judson Harward Binary Search Trees In the previous lecture, we defined the concept of binary
More informationAnalysis of Binary Search algorithm and Selection Sort algorithm
Analysis of Binary Search algorithm and Selection Sort algorithm In this section we shall take up two representative problems in computer science, work out the algorithms based on the best strategy to
More informationBinary Search Trees CMPSC 122
Binary Search Trees CMPSC 122 Note: This notes packet has significant overlap with the first set of trees notes I do in CMPSC 360, but goes into much greater depth on turning BSTs into pseudocode than
More informationAPI for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list.
Sequences and Urns 2.7 Lists and Iterators Sequence. Ordered collection of items. Key operations. Insert an item, iterate over the items. Design challenge. Support iteration by client, without revealing
More informationJava Software Structures
INTERNATIONAL EDITION Java Software Structures Designing and Using Data Structures FOURTH EDITION John Lewis Joseph Chase This page is intentionally left blank. Java Software Structures,International Edition
More informationHW3: Programming with stacks
HW3: Programming with stacks Due: 12PM, Noon Thursday, September 18 Total: 20pts You may do this assignment with one other student. A team of two members must practice pair programming. Pair programming
More informationCmpSci 187: Programming with Data Structures Spring 2015
CmpSci 187: Programming with Data Structures Spring 2015 Lecture #12 John Ridgway March 10, 2015 1 Implementations of Queues 1.1 Linked Queues A Linked Queue Implementing a queue with a linked list is
More informationAssignment 3 (concept) Solutions
CS10b Data Structures and Algorithms Assignment 3 (concept) Solutions Due: Friday, February 18th 1. (0%) Consider the following algorithm: Algorithm Power(x, n) Input: A number x and integer n 0 Output:
More informationRecursion. Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive.
Recursion Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive. Why recursion? o For many problems, the recursion solution is more natural than the alternative
More informationITEC2620 Introduction to Data Structures
ITEC2620 Introduction to Data Structures Lecture 8b Search Trees Traversals Typical covered as graph traversals in data structures courses I ve never seen a graph traversal in practice! AI background Tree
More informationBinary Search Trees and Hash Tables
CHAPTER 7 Binary Search Trees and Hash Tables 7.1 Binary Search Trees In Chapter, we introduced containers called a priority queues and dictionaries. A priority queue is a dispenser in which the current
More informationData Structures, Sample Test Questions for the Material after Test 2, with Answers
Data Structures, Sample Test Questions for the Material after Test 2, with Answers 1. Recall the public interfaces of classes List and ListIterator: typedef int ListItemType; class ListIterator{ public:
More informationAnalysis of a Search Algorithm
CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,
More informationOrdered Lists and Binary Trees
Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 60:
More informationCSE 5311 Homework 2 Solution
CSE 5311 Homework 2 Solution Problem 6.26 Show that the worstcase running time of MAXHEAPIFY on a heap of size n is Ω(lg n). (Hint: For a heap with n nodes, give node values that cause MAX HEAPIFY
More informationThe scenario: Initial state Target (Goal) states A set of intermediate states A set of operations that move the agent from one state to another.
CmSc310 Artificial Intelligence Solving Problems by Searching  Uninformed Search 1. Introduction All AI tasks involve searching. General idea: You know where you are (initial state) and where you want
More informationTrees & Binary Search Trees
CMSC 132: ObjectOriented Programming II Trees & Binary Search Trees Department of Computer Science University of Maryland, College Park Trees Trees are hierarchical data structures Onetomany relationship
More informationQueues and Stacks. Atul Prakash Downey: Chapter 15 and 16
Queues and Stacks Atul Prakash Downey: Chapter 15 and 16 Queues Queues occur in real life a lot. Queues at checkout Queues in banks In software systems: Queue of requests at a web servers Properties of
More informationAlgorithms and Data Structures
Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. RalfPeter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2
More informationPES Institute of TechnologyBSC QUESTION BANK
PES Institute of TechnologyBSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions
More informationThe Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n1)!
The Tower of Hanoi Recursion Solution recursion recursion recursion Recursive Thinking: ignore everything but the bottom disk. 1 2 Recursive Function Time Complexity Hanoi (n, src, dest, temp): If (n >
More informationWhy? A central concept in Computer Science. Algorithms are ubiquitous.
Analysis of Algorithms: A Brief Introduction Why? A central concept in Computer Science. Algorithms are ubiquitous. Using the Internet (sending email, transferring files, use of search engines, online
More informationC++ How to Program, 8/e by Pearson Education, Inc. All Rights Reserved.
C++ How to Program, 8/e 19922012 by Pearson Education, Inc. 19922012 by Pearson Education, Inc. 19922012 by Pearson Education, Inc. We ve studied fixedsize data structures such as onedimensional arrays
More informationData Structures and Algorithms
Data Structures and Algorithms CS2452016S06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 060: Ordered List ADT Operations: Insert an element in the list
More informationECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 20081023/5:156:45 REC200, EVI350, RCH106, HH139
ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 20081023/5:156:45 REC200, EVI350, RCH106, HH139 Instructions: No aides. Turn off all electronic media and store them under your desk. If
More informationInternational Journal of Software and Web Sciences (IJSWS) www.iasir.net
International Association of Scientific Innovation and Research (IASIR) (An Association Unifying the Sciences, Engineering, and Applied Research) ISSN (Print): 22790063 ISSN (Online): 22790071 International
More informationSummit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A
Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Developed By Brian Weinfeld Course Description: AP Computer
More informationIntroduction to Programming System Design. CSCI 455x (4 Units)
Introduction to Programming System Design CSCI 455x (4 Units) Description This course covers programming in Java and C++. Topics include review of basic programming concepts such as control structures,
More informationConverting a Number from Decimal to Binary
Converting a Number from Decimal to Binary Convert nonnegative integer in decimal format (base 10) into equivalent binary number (base 2) Rightmost bit of x Remainder of x after division by two Recursive
More informationData Structures. Topic #4
Topic #4 Today s Agenda Stack and Queue ADTs What are they Like Ordered Lists, are position oriented Use of Data Structures for Stacks and Queues arrays (statically & dynamically allocated) linear linked
More informationLecture 6: Binary Search Trees CSCI 700  Algorithms I. Andrew Rosenberg
Lecture 6: Binary Search Trees CSCI 700  Algorithms I Andrew Rosenberg Last Time Linear Time Sorting Counting Sort Radix Sort Bucket Sort Today Binary Search Trees Data Structures Data structure is a
More informationTrees LOGO STYLE GUIDE Schools within the University 1 19
Trees 1 Example Tree 2 A Generic Tree 3 Tree ADT n Tree definition q A tree is a set of nodes which may be empty q If not empty, then there is a distinguished node r, called root and zero or more nonempty
More information2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]
Code No: R05220502 Set No. 1 1. (a) Describe the performance analysis in detail. (b) Show that f 1 (n)+f 2 (n) = 0(max(g 1 (n), g 2 (n)) where f 1 (n) = 0(g 1 (n)) and f 2 (n) = 0(g 2 (n)). [8+8] 2. (a)
More informationUIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything
More informationData Structures. Level 6 C30151. www.fetac.ie. Module Descriptor
The Further Education and Training Awards Council (FETAC) was set up as a statutory body on 11 June 2001 by the Minister for Education and Science. Under the Qualifications (Education & Training) Act,
More information6 Data Structures. 6.1 Quadtree. 6.2 Binary search tree
6 Data Structures 6.1 Quadtree he basic principles of quadtrees have been outlined in the lecture. ollow these steps for the implementation in Java: 1. Download the quadtree.zip file from the course web
More informationCan you design an algorithm that searches for the maximum value in the list?
The Science of Computing I Lesson 2: Searching and Sorting Living with Cyber Pillar: Algorithms Searching One of the most common tasks that is undertaken in Computer Science is the task of searching. We
More informationLecture Notes on Spanning Trees
Lecture Notes on Spanning Trees 15122: Principles of Imperative Computation Frank Pfenning Lecture 26 April 26, 2011 1 Introduction In this lecture we introduce graphs. Graphs provide a uniform model
More informationLecture Notes on Binary Search Trees
Lecture Notes on Binary Search Trees 15122: Principles of Imperative Computation Frank Pfenning Lecture 17 March 17, 2010 1 Introduction In the previous two lectures we have seen how to exploit the structure
More informationData Structures in Java. Session 15 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134
Data Structures in Java Session 15 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134 Announcements Homework 4 on website No class on Tuesday Midterm grades almost done Review Indexing
More informationChapter There are nonisomorphic rooted trees with four vertices. Ans: 4.
Use the following to answer questions 126: In the questions below fill in the blanks. Chapter 10 1. If T is a tree with 999 vertices, then T has edges. 998. 2. There are nonisomorphic trees with four
More informationLecture Notes on Binary Search Trees
Lecture Notes on Binary Search Trees 15122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 17 October 23, 2014 1 Introduction In this lecture, we will continue considering associative
More informationDATA STRUCTURE  STACK
DATA STRUCTURE  STACK http://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm Copyright tutorialspoint.com A stack is an abstract data type ADT, commonly used in most programming
More information10CS35: Data Structures Using C
CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions  a conventional tool for handling a
More information5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.
1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The
More informationData Structures in Java. Session 16 Instructor: Bert Huang
Data Structures in Java Session 16 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3134 Announcements Homework 4 due next class Remaining grades: hw4, hw5, hw6 25% Final exam 30% Midterm
More informationAnnouncements. CSE332: Data Abstractions. Lecture 9: B Trees. Today. Our goal. Mary Search Tree. Mary Search Tree. Ruth Anderson Winter 2011
Announcements CSE2: Data Abstractions Project 2 posted! Partner selection due by 11pm Tues 1/25 at the latest. Homework due Friday Jan 28 st at the BEGINNING of lecture Lecture 9: B Trees Ruth Anderson
More informationMAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) 
=============================================================================================================================== DATA STRUCTURE PSEUDOCODE EXAMPLES (c) Mubashir N. Mir  www.mubashirnabi.com
More informationAlgorithms and Data Structures
Algorithms and Data Structures CMPSC 465 LECTURES 2021 Priority Queues and Binary Heaps Adam Smith S. Raskhodnikova and A. Smith. Based on slides by C. Leiserson and E. Demaine. 1 Trees Rooted Tree: collection
More informationData Structures in the Java API
Data Structures in the Java API Vector From the java.util package. Vectors can resize themselves dynamically. Inserting elements into a Vector whose current size is less than its capacity is a relatively
More informationAlgorithms and Data S tructures Structures Stack, Queues, and Applications Applications Ulf Leser
Algorithms and Data Structures Stack, Queues, and Applications Ulf Leser Content of this Lecture Stacks and Queues Tree Traversal Towers of Hanoi Ulf Leser: Alg&DS, Summer semester 2011 2 Stacks and Queues
More informationLecture 9. Semantic Analysis Scoping and Symbol Table
Lecture 9. Semantic Analysis Scoping and Symbol Table Wei Le 2015.10 Outline Semantic analysis Scoping The Role of Symbol Table Implementing a Symbol Table Semantic Analysis Parser builds abstract syntax
More informationReview of Hashing: Integer Keys
CSE 326 Lecture 13: Much ado about Hashing Today s munchies to munch on: Review of Hashing Collision Resolution by: Separate Chaining Open Addressing $ Linear/Quadratic Probing $ Double Hashing Rehashing
More informationUnordered List Methods
REFERENCE SHEETS Useful properties of logarithms: log b (xy) = log b x + log b y log b (x/y) = log b x  log b y log b x a = alog b x log x a/log x b =log b a Useful properties of exponentials: a (b+c)
More informationBinary Trees and Huffman Encoding Binary Search Trees
Binary Trees and Huffman Encoding Binary Search Trees Computer Science E119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Motivation: Maintaining a Sorted Collection of Data A data dictionary
More informationData Structures grand tour continues Diagnostic Quiz Review Comparable, Comparator, and Function Objects. Check out from SVN: DiagQuizReview
Data Structures grand tour continues Diagnostic Quiz Review Comparable, Comparator, and Function Objects Check out from SVN: DiagQuizReview Written Assignment 2 Pascal Christmas Tree Some review Some new
More informationPseudo code Tutorial and Exercises Teacher s Version
Pseudo code Tutorial and Exercises Teacher s Version Pseudocode is an informal way to express the design of a computer program or an algorithm in 1.45. The aim is to get the idea quickly and also easy
More informationLecture Notes on Linear Search
Lecture Notes on Linear Search 15122: Principles of Imperative Computation Frank Pfenning Lecture 5 January 29, 2013 1 Introduction One of the fundamental and recurring problems in computer science is
More informationEfficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case.
Algorithms Efficiency of algorithms Computational resources: time and space Best, worst and average case performance How to compare algorithms: machineindependent measure of efficiency Growth rate Complexity
More informationThe ADT Binary Search Tree
The ADT Binary Search Tree The Binary Search Tree is a particular type of binary tree that enables easy searching for specific items. Definition The ADT Binary Search Tree is a binary tree which has an
More information1.204 Lecture 6. Data structures: stacks, queues, trees, dictionaries. Data structures
1.204 Lecture 6 Data structures: stacks, queues, trees, dictionaries Data structures Correct and efficient representation of data and applicable rules Stack: last in, first out discipline Queue: first
More information