Written Midterm Solutions

Slides:



Advertisements
Similar presentations
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Advertisements

1 AVL-Trees (Adelson-Velskii & Landis, 1962) In normal search trees, the complexity of find, insert and delete operations in search trees is in the worst.
Solution of Assignment 3 and Midterm CSC2100B. AVL Tree A binary search tree is a binary tree in which every node has larger key than the nodes in its.
AVL Trees COL 106 Amit Kumar Shweta Agrawal Slide Courtesy : Douglas Wilhelm Harder, MMath, UWaterloo
Trees Types and Operations
Lecture 10 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
MA/CSSE 473 Day 25 Transform and Conquer Student questions?
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
Priority Queues and Heaps Bryce Boe 2013/11/20 CS24, Fall 2013.
CS 3610 Midterm Review.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
Lecture 2 Sorting. Sorting Problem Insertion Sort, Merge Sort e.g.,
MA/CSSE 473 Day 21 AVL Tree Maximum height 2-3 Trees Student questions?
Tree Traversal.
AVL Trees. AVL Node Structure The AVL node structure follows the same structure as the binary search tree, with the addition of a term to store the.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
CSE205 Review Session SAMUEL & JESSA. Recursion WHAT IS RECURSION?  Recursion is a tool a programmer can use to invoke a function call on itself. 
Data Structures AVL Trees.
1 Algorithms CSCI 235, Fall 2015 Lecture 6 Recurrences.
Copyright © 2005 Pearson Addison-Wesley. All rights reserved Balancing Binary Trees There are many approaches to balancing binary trees One method.
 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 2 Sorting (insertion Sort, Merge Sort)
Chapter 7 Trees_ Part2 TREES. Depth and Height 2  Let v be a node of a tree T. The depth of v is the number of ancestors of v, excluding v itself. 
BSTs, AVL Trees and Heaps Ezgi Shenqi Bran. What to know about Trees? Height of a tree Length of the longest path from root to a leaf Height of an empty.
Priority Queues and Heaps. John Edgar  Define the ADT priority queue  Define the partially ordered property  Define a heap  Implement a heap using.
Merge Sort 1/12/2018 5:48 AM Merge Sort 7 2   7  2  2 7
Lecture 2 Sorting.
MA/CSSE 473 Day 20 Finish Josephus
COMP 53 – Week Fourteen Trees.
Lecture 15 Nov 3, 2013 Height-balanced BST Recall:
Lec 13 Oct 17, 2011 AVL tree – height-balanced tree Other options:
Top 50 Data Structures Interview Questions
Heaps, Heapsort, and Priority Queues
PROJECT -1 (4 points) Week before midterm, C++.
Midterm Review.
Lecture 15 AVL Trees Slides modified from © 2010 Goodrich, Tamassia & by Prof. Naveen Garg’s Lectures.
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
UNIT III TREES.
Topic:- ALGORITHM Incharge Faculty – Lokesh Sir.
CS Anya E. Vostinar Grinnell College
Cse 373 April 26th – Exam Review.
ITEC 2620M Introduction to Data Structures
(edited by Nadia Al-Ghreimil)
Chapter 6 Transform and Conquer.
Draw pictures to indicate the subproblems middleMax solves at each level and the resulting maxPtr and PrevPtr for each on this linked list:
Priority Queue and Binary Heap Neil Tang 02/12/2008
B-Tree Insertions, Intro to Heaps
CS223 Advanced Data Structures and Algorithms
Searching: linear & binary
Chapter 6: Transform and Conquer
Searching CLRS, Sections 9.1 – 9.3.
Binary Tree Traversals
CS200: Algorithms Analysis
(2,4) Trees 2/15/2019 (2,4) Trees (2,4) Trees.
(edited by Nadia Al-Ghreimil)
CS223 Advanced Data Structures and Algorithms
CSE 332: Data Abstractions Sorting I
DATA STRUCTURE.
Solving Recurrences Continued The Master Theorem
AVL-Trees (Part 1).
Divide & Conquer Algorithms
CSE 326: Data Structures Lecture #9 AVL II
Hash Maps: The point of a hash map is to FIND DATA QUICKLY.
CSCE 3110 Data Structures & Algorithm Analysis
CSCE 3110 Data Structures & Algorithm Analysis
Algorithms CSCI 235, Spring 2019 Lecture 6 Recurrences
CSCE 3110 Data Structures & Algorithm Analysis
Algorithms CSCI 235, Spring 2019 Lecture 26 Midterm 2 Review
Algorithms CSCI 235, Spring 2019 Lecture 8 Recurrences III
EE 312 Software Design and Implementation I
CMPT 225 Lecture 16 – Heap Sort.
Presentation transcript:

Written Midterm Solutions Yang Zhengwei

Time Complexity

Time Complexity

Stack and Queue

Idea For each element, determine the state of the stack or the queue. According to the state, judge whether an output is feasible. Answer

Tree

Idea Traverse the tree, at the same time label it Answer (b) Pre-order:8,4,2,1,3,6,5,7,12,10,9,11,14,13,15 Post-order:1,3,2,5,7,6,4,9,11,10,13,15,14,12,8 (c) 2^n (d) find the root of every subtree when rebuild the tree

AVL Tree

Idea You could go to this web site to check every step of insertion and deletion. https://www.cs.usfca.edu/~galles/visualization/AVLtree.html a) d) b) 1 c) 1, 6, 9, 12 e) upper-bound: 2^(h+1) – 1 lower bound:

Idea Upper bound: a complete tree of height h Lower bound: N(h) = N(h-1) + N(h-2) + 1 do you know why? The additional 1 is the above equation is for the root node. How to Solving the recurrence equation? Fibonacci Sequence

Heap

Idea You could go to this web site to check every step of insertion and deletion. https://www.cs.usfca.edu/~galles/visualization/Heap.html a) Swap the root with the last element, then delete the last element and maintain the heap from root.

Short Questions The operators are associated right-to-left, so we calculate right first. 10-(20 * 8 / (5 – 2 – 1)) – 20 = 10 – (20 * 8 / (5 – (2 – 1)) – 20 …= - 10

Short Questions  

Short Questions

Short Questions d) No, not search tree e) f) pointer: worst case of push/pop always O(1) array: only need to store data itself, no pointers Delete a node / Reverse the list A divide and conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same (or related) type, until these become simple enough to be solved directly. The solutions to the sub-problems are then combined to give a solution to the original problem.