Data Structures (3rd Exam). 1. [5] Determine whether or not the arrays A = [62, 40, 58, 26, 30, 57, 50, 16, 15], B = [56, 38, 55, 46, 16, 53, 48, 39,

Slides:



Advertisements
Similar presentations
Dana Shapira Hash Tables
Advertisements

CS16: Data Structures & Algorithms | Spring 2014 Midterm Review 3/16/
Introduction to Computer Science Theory
Heapsort O(n lg n) worst case Another design paradigm –Use of a data structure (heap) to manage information during execution of algorithm Comparision-based.
Data Structures Using C++ 2E
Searching Kruse and Ryba Ch and 9.6. Problem: Search We are given a list of records. Each record has an associated key. Give efficient algorithm.
Chapter 19: Searching and Sorting Algorithms
DictionaryADT and Trees. Overview What is the DictionaryADT? What are trees? Implementing DictionaryADT with binary trees Balanced trees DictionaryADT.
@ Zhigang Zhu, CSC212 Data Structure - Section FG Lecture 19 Searching Instructor: Zhigang Zhu Department of Computer Science City College.
授課教授:李錫智 Data Structures -3 rd exam-. 1.[5] Refer to the two trees in Fig. 1. Let’s define the balance factor BF of a node to be the absolute value of.
Pointer Review. Node { int value; Node * next; Node( int val =-1, Node * n = NULL) {value = val; next = n;} } Given a ordered linked list pointed to.
CS 315 March 24 Goals: Heap (Chapter 6) priority queue definition of a heap Algorithms for Insert DeleteMin percolate-down Build-heap.
Definitions Priority Queue – A data structure with quick access to its smallest (or largest) key. Heap – A binary tree that is complete and satisfies the.
Lecture 10 Sept 29 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
Lecture 11 March 5 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
Lecture 4 Feb 5 completion of recursion (inserting into a linked list as last item) analysis of algorithms – Chapter 2.
Lecture 4 Sept 4 Goals: chapter 1 (completion) 1-d array examples Selection sorting Insertion sorting Max subsequence sum Algorithm analysis (Chapter 2)
© 2006 Pearson Addison-Wesley. All rights reserved12 A-1 Chapter 12 Heaps.
Chapter 12 B Priority Queues. © 2004 Pearson Addison-Wesley. All rights reserved 12 B-2 The ADT Priority Queue: A Variation of the ADT Table The ADT priority.
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Value Iteration 0: step 0. Insertion Sort Array index67 Iteration i. Repeatedly swap element i with.
Week 11 Sorting Algorithms. Sorting Sorting Algorithms A sorting algorithm is an algorithm that puts elements of a list in a certain order. We need sorting.
1 C++ Plus Data Structures Nell Dale Chapter 7 Programming with Recursion Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 8 Stacks and Queues Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
CM0551 Exam Prep. What are an algorithm’s time and space complexity? (2 marks) Answer: The growth rate of the algorithm’s time requirement and the computer.
C++ Classes and Data Structures Jeffrey S. Childs
More on Linked List Algorithms. Linked List and Template Remember the implementation of a double linked list we learned before. Some of methods are shown.
Data Structures Using C++1 Search Algorithms Sequential Search (Linear Search) Binary Search.
Chapter 19: Searching and Sorting Algorithms
1 Programming with Recursion Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus and Robert Moyer, Montgomery County Community.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 13 Recursion Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 11 Sorting and Searching.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
C# PROGRAMMING Searching & Sorting. Objective/Essential Standard Essential Standard 3.00 Apply Advanced Properties of Arrays Indicator 3.03 Apply procedures.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 14 Introduction to Sorting Algorithms Jeffrey S. Childs Clarion University of PA © 2008, Prentice.
7.2 Priority Queue ADTs Priority queue concepts
Data Structures Using C++ 2E Chapter 10 Sorting Algorithms.
CSC 211 Data Structures Lecture 13
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 12 – Data Structures – Trees Sorting Algorithms.
A first look an ADTs Solving a problem involves processing data, and an important part of the solution is the careful organization of the data In order.
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
1 Chapter 7 The Linked List as a Data Structure. 2 The List ADT A list is a list of elements. The list of elements consist of the data acted upon by list.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
LAB#6. 2 Overview Before we go to our lesson we must know about : 1. data structure. 2.Algorithms. data structure is an arrangement of data in a computer.
CHAPTER 8 SEARCHING CSEB324 DATA STRUCTURES & ALGORITHM.
Searching Algorithms Sequential Search – inspects every items in a sequential manner. Example, in an array, all values in the array are checked from index.
Hash Tables. 2 Exercise 2 /* Exercise 1 */ void mystery(int n) { int i, j, k; for (i = 1; i
Sorting and Searching. Selection Sort  “Search-and-Swap” algorithm 1) Find the smallest element in the array and exchange it with a[0], the first element.
Review for Final Exam – cs411/511 Definitions (5 questions, 2 points each) Algorithm Analysis (3 questions, 3 points each) General Questions (3 questions,
Data Structures -3 st exam- 授課教師 : 李錫智 教授. 1. [5] Assume we have a binary tree which is implemented in a pointer-based scheme. Describe how to know the.
CHAPTER 17 LINKED LISTS. In this chapter, you will:  Learn about linked lists  Become aware of the basic properties of linked lists  Explore the insertion.
Quick sort, lower bound on sorting, bucket sort, radix sort, comparison of algorithms, code, … Sorting: part 2.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 15 Other Data Structures Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
CS Fall 2009 Sorted List Sets. What is the use of sorting? Remember we sorted a dynamic array so that we could use binary search. There would seem.
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
CS6045: Advanced Algorithms Sorting Algorithms. Heap Data Structure A heap (nearly complete binary tree) can be stored as an array A –Root of tree is.
1 Chapter 6 Methods for Making Data Structures. 2 Dynamic Arrays in Data Structures In almost every data structure, we want functions for inserting and.
1 Chapter 6 Heapsort. 2 About this lecture Introduce Heap – Shape Property and Heap Property – Heap Operations Heapsort: Use Heap to Sort Fixing heap.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Data Structures -3 rd exam- 授課教授:李錫智. 1.[10] Suppose we want to implement a queue by using the following List operations: getLength(); remove(position);
COMP 103 Course Review. 2 Menu  A final word on hash collisions in Open Addressing / Probing  Course Summary  What we have covered  What you should.
Doubly Linked List Review - We are writing this code
Linked lists.
Data Structures Using C++ 2E
Chapter 16-2 Linked Structures
Chapter 16 Linked Structures
Linked lists.
Instructor: Dr. Michael Geiger Spring 2017 Lecture 36: Exam 3 Preview
Presentation transcript:

Data Structures (3rd Exam)

1. [5] Determine whether or not the arrays A = [62, 40, 58, 26, 30, 57, 50, 16, 15], B = [56, 38, 55, 46, 16, 53, 48, 39, 15] are maxheaps. Explain your decisions.

1.A = [62, 40, 58, 26, 30, 57, 50, 16, 15]. Yes. A node >= its daughters

1.B = [56, 38, 55, 46, 16, 53, 48, 39, 15]. No. Node 38 < node 46

2.[10] Suppose you are given an array A = [13, 38, 57, 33, 27, 31, 46, 35, 26, 59]. Please adjust the elements to make A become a maxheap. Show the result.

2.A = [13, 38, 57, 33, 27, 31, 46, 35, 26, 59].

3.[10] Suppose you are given the following elements: 13, 38, 57, 33, 27, 31, 46, 35, 26, 59. Please create a maxheap by enqueueing the elements one by one in the order shown. Show the maxheap in an array.

3.13, 38, 57, 33, 27, 31, 46, 35, 26, 59.

4.[5] Suppose you are given an array A = [13, 38, 57, 33, 27, 31, 46, 35, 26, 59]. Please adjust the elements to make A become a minheap. Show the result.

4.A = [13, 38, 57, 33, 27, 31, 46, 35, 26, 59].

5.[5] Suppose you are given the following elements: 13, 38, 57, 33, 27, 31, 46, 35, 26, 59. Please create a minheap by enqueueing the elements one by one in the order shown. Show the minheap in an array.

5.13, 38, 57, 33, 27, 31, 46, 35, 26, 59.

6.[10] Suppose we use the hash function h(k) = k%13 to insert the following keys 37, 30, 41, 24, 17, 20, 27, 15, 28, 26 into the hash table with the chaining method. Assume that the hash table has 13 positions. Note that a key is inserted as the first element of the underlying chain. Please show your result.

6.37, 30, 41, 24, 17, 20, 27, 15, 28, 26.

7.[10] Consider the function given below: 1bool search( Node *ptr, Bird & bird, Bird dove ) 2{ 3 if ( ptr == NULL ) 4 return false; 5 if ( ptr->info == dove ) { 6 bird = ptr->info; 7 return true; 8 } 9 return search( ptr->next, bird, dove ); 10}

7.which is called for a linked list (where start points to the first node) using the lines of code: if ( search( start, bird, dove ) ) cout << “search successful” << endl; Please answer the following questions: a.In what condition will the function return false? b.In what condition will the function return true? c.What if there were no base case for this function? d.Suppose there are n elements in the linked list. What is the best-case time complexity for this function? e.Suppose there are n elements in the linked list. What is the worst-case time complexity for this function?

7. a. can’t find the desired information. b. Find the desired node. c. Runtime error : ptr = NULL. d. O(1) e. O(n)

8.[10] Suppose we have the following program: 1 for each j, from 1 to (length (A) – 1) 2 {temp = A[ j ]; 3 i = j – 1; 4 while i is greater than -1 and A[ i ] is greater than temp 5 {A[ i + 1 ] = A[ i ]; 6 i--;} 7 A[ i + 1] = temp} Let A = [60, 10, 50, 80, 30, 20, 40, 70]. Please show A after each iteration of the for loop.

8.A = [60, 10, 50, 80, 30, 20, 40, 70].

9.[10] Let A = [60, 10, 50, 80, 30, 20, 40, 70]. Please use heapsort to sort the elements in A In ascending order. Please draw A after the initial stage and each iteration. Please use maxheap.

9.A = [60, 10, 50, 80, 30, 20, 40, 70].

10.[10] Let A = [60, 10, 50, 80, 30, 20, 40, 70]. Please use mergesort to sort the elements in A in ascending order. Please draw the result after the merge of each level.

10.A = [60, 10, 50, 80, 30, 20, 40, 70].

11.[5] Suppose we have the following program: 1 for each j, from 1 to (length (A) – 1) 2 {temp = A[ j ]; 3 i = j – 1; 4 while i is greater than -1 and A[ i ] is greater than temp 5 {A[ i + 1 ] = A[ i ]; 6 i--;} 7 A[ i + 1] = temp} Let B = [80, 50, 30, 40, 90, 60, 20, 70]. Please show A after each iteration of the for loop.

11. B = [80, 50, 30, 40, 90, 60, 20, 70].

12.[5] Let B = [80, 50, 30, 40, 90, 60, 20, 70]. Please use heapsort to sort the elements in A In ascending order. Please draw A after the initial stage and each iteration. Please use maxheap.

12.B = [80, 50, 30, 40, 90, 60, 20, 70].

13.[5] Let B = [80, 50, 30, 40, 90, 60, 20, 70]. Please use mergesort to sort the elements in A in ascending order. Please draw the result after the merge of each level.

13.Let B = [80, 50, 30, 40, 90, 60, 20, 70].