Data Structures 2018 Quiz Answers

Slides:



Advertisements
Similar presentations
1 HeapSort CS 3358 Data Structures. 2 Heapsort: Basic Idea Problem: Arrange an array of items into sorted order. 1) Transform the array of items into.
Advertisements

Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
CHAPTER 7: SORTING & SEARCHING Introduction to Computer Science Using Ruby (c) Ophir Frieder at al 2012.
CIS 068 Welcome to CIS 068 ! Lesson 9: Sorting. CIS 068 Overview Algorithmic Description and Analysis of Selection Sort Bubble Sort Insertion Sort Merge.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 12 – Data Structures – Trees Sorting Algorithms.
1 2. Program Construction in Java. 2.9 Sorting 3 The need Soritng into categories is relatively easy (if, else if, switch); here we consider sorting.
Sorting. 2 contents 3 kinds of sorting methods – Selection, exchange, and insertion O(n 2 ) sorts – VERY inefficient, but OK for ≈ 10 elements – Simple.
Data Structures Stacks and Queues Phil Tayco Slide version 1.0 Feb. 16, 2015.
Priority Queues and Heaps. October 2004John Edgar2  A queue should implement at least the first two of these operations:  insert – insert item at the.
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.
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
Sorting 1. Insertion Sort
Chapter 4, Part I Sorting Algorithms. 2 Chapter Outline Insertion sort Bubble sort Shellsort Radix sort Heapsort Merge sort Quicksort External polyphase.
OCR A Level F453: Data structures and data manipulation Data structures and data manipulation a. explain how static data structures may be.
Priority Queues and Heaps. John Edgar  Define the ADT priority queue  Define the partially ordered property  Define a heap  Implement a heap using.
Priority Queues and Heaps Tom Przybylinski. Maps ● We have (key,value) pairs, called entries ● We want to store and find/remove arbitrary entries (random.
Searching and Sorting Searching algorithms with simple arrays
Sort Algorithm.
Chapter 16: Linked Lists.
Sorting and "Big Oh" ASFA AP Computer Science A SortingBigOh.
C++ Programming:. Program Design Including
Chapter 12 – Data Structures
Course Developer/Writer: A. J. Ikuomola
Lecture No.45 Data Structures Dr. Sohail Aslam.
Review Deleting an Element from a Linked List Deletion involves:
Searching – Linear and Binary Searches
Midterm Review.
Merging Merge. Keep track of smallest element in each sorted half.
Sorting Algorithms.
Simple Sorting Algorithms
Lesson Objectives Aims Understand the following “standard algorithms”:
Data Structures Using C++ 2E
Divide and Conquer.
O(lg n) Search Tree Tree T is a search tree made up of n elements: x0 x1 x2 x3 … xn-1 No function (except transverse) takes more than O(lg n) in the.
CS302 Data Structures Fall 2012.
Sorting Data are arranged according to their values.
Phil Tayco Slide version 1.0 May 7, 2018
Bubble Sort Bubble sort is one way to sort an array of numbers. Adjacent values are swapped until the array is completely sorted. This algorithm gets its.
CMSC 341: Data Structures Priority Queues – Binary Heaps
Arrays and Linked Lists
Algorithm design and Analysis
Selection Sort Sorted Unsorted Swap
Data Structures & Algorithms Priority Queues & HeapSort
CSC215 Lecture Algorithms.
Linked List (Part I) Data structure.
Welcome to CIS 068 ! Lesson 9: Sorting CIS 068.
Sorting Data are arranged according to their values.
MSIS 655 Advanced Business Applications Programming
Straight Selection Sort
Standard Version of Starting Out with C++, 4th Edition
8/04/2009 Many thanks to David Sun for some of the included slides!
IT 4043 Data Structures and Algorithms
Linked List and Selection Sort
Data Structures Sorted Arrays
A G L O R H I M S T A Merging Merge.
Quadratic Sorts & Breaking the O(n2) Barrier
CSE 12 – Basic Data Structures
Sorting And Searching CSE116A,B 4/7/2019 B.Ramamurthy.
Data Structures Introduction
Data Structures Unsorted Arrays
CSE 373, Copyright S. Tanimoto, 2002 Priority Queues -
David Kauchak cs161 Summer 2009
Heaps By JJ Shepherd.
A G L O R H I M S T A Merging Merge.
CO4301 – Advanced Games Development Week 4 Binary Search Trees
A G L O R H I M S T A Merging Merge.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Instructor: Dr. Michael Geiger Spring 2017 Lecture 30: Sorting & heaps
EE 312 Software Design and Implementation I
Presentation transcript:

Data Structures 2018 Quiz Answers Phil Tayco Slide version 1.0 May 17, 2018

Quiz 1 Which of the following is true about Big-O? O(n) is considered better performance than O(n2) Given an ordered set of numbers from lowest to greatest in a data structure like an array. Which of the following is true? Since the smallest number will always be the first element, the algorithm for finding the smallest number in the array is O(1) The algorithm to find the sum of all the numbers in the sorted array is O(n) Which of the following statements is/are true? Big-O measures the performance of your algorithm as the size of the data set it is working with increases in size

Quiz 2 Which of the following is true about deleting elements in an unordered array? None of the above O(1) is achieved for which of the following functions in an unordered array? append Which of the following statements is true about linear search in an unordered array? It is impossible to get better performance than O(n) Technically, the performance is O(2n) when using comparison operations. The category of performance is characterized as O(n) The update function in an unordered array is O(n) - True

Quiz 3 Which of the following is true about search, insert, update and delete functions for a sorted array? When compared to an unordered array, search is significantly improved with sorted arrays, but adding new elements to a sorted array is worse Which of the following is true when comparing arrays and linked lists? With unsorted data, search, insert, update and delete all perform in the same O category One of the primary advantages with linked lists over arrays is dynamic memory usage If the data is sorted, arrays are significantly better than linked lists for search 3a) 6 -> 8 -> 10 -> 7 -> 4 -> null 3b) 6 -> 8 -> 7 -> 4 -> null 3c) 6 -> 8 -> 7 -> null

Quiz 4 1) Final linked list stack: 2 -> 6 -> 5 -> 10 2) Final array queue: 6 10 - 8 1 3) Final linked list priority queue (showing only priorities): 50 -> 25 -> 10 -> 5 Bubble sort: 3 4 2 5 1 3 2 4 1 5 2 3 1 4 5 2 1 3 4 5 1 2 3 4 5

Quiz 4 Selection sort: 3 4 2 5 1 1 4 2 5 3 1 2 4 5 3 1 2 3 5 4 1 2 3 4 5 Insertion sort: 3 4 2 5 1 3 4 2 5 1 2 3 4 5 1

Quiz 5 1) Output on screen 2) Fix: Comparing L L Comparing L E False Change “return isPalindrome(str, s, e-1);” to “return isPalindrome(str, s+1, e-1);”

Quiz 6 Bubble sort: 2 1 3 9 4 5 7 6 1 2 3 4 5 7 6 9 1 2 3 4 5 6 7 9 (remaining iterations repeat with no swaps) Description is correct Selection sort: 2 1 3 9 4 5 7 6 1 2 3 9 4 5 7 6 1 2 3 4 9 5 7 6 1 2 3 4 5 9 7 6 1 2 3 4 5 6 7 9 <- incorrect part on quiz

Quiz 6 Insertion sort: 2 1 3 9 4 5 7 6 1 2 3 9 4 5 7 6 1 2 3 4 9 5 7 6 1 2 3 4 5 9 7 6 <- incorrect part on quiz 1 2 3 4 5 7 9 6 1 2 3 4 5 6 7 9 Mergesort: All correct until… Merge [7] and [6] to make [7 6] should be Merge [7] and [6] to make [6 7] Quicksort is correct

Quiz 7 First tree: 2 1 7 4 9 3 5 8 10 (second 4 on list is a quiz error) Second tree: 1 4 6 10 8 11 9

Quiz 7 Third tree: 5 4 3 1 2

Quiz 7 Final tree: 30 10 55 20 75 5 45 12 55 11

Quiz 8 2-3-4 tree: 4 2 7 9 0 1 3 5 6 8 10 12 Multiple choice: D B