COP3530 Midterm

Ace your homework & exams now with Quizwiz!

Advantages/Disadvantages of ArrayList

+ Get/Set take constant time - Insertion/removal is expensive (O(n))

Advantages/Disadvantages of LinkedList

+ Insertion/removal is cheap + Adds/removes from the front are constant time operations + Has efficient methods addFirst, removeFirst, addLast, removeLast, getFirst and getLast. - Not easily indexable, get calls are expensive (O(n))

Algorithm

- A high-level description of a piece-by-piece or step by-step process. - A well ordered collection of clear and effectively computable operations that when executed produces a result and halts in a finite amount of time.

Why use recursion if it is less efficient?

- Cleaner/elegant solutions - Some problems with ADTs require recursion, such as Tree Traversals, Graph Traversals, and Search Problems.

AVL Tree (Adelson-Velskii and Landis)

A binary search tree with a balance condition, for every node in the tree, the height of the left and right subtrees can differ by at most 1. Contain/Find, Insert, and Lazy Delete can be performed in O(log(n)) time. Height is log(n). buildTree with n nodes is O(nlog(n)).

Binary Search Tree

A binary tree in which the values of all items in its left subtree are smaller than the right subtree.

Binary min-heap

A binary tree that is completely filled, with the possible exception of the bottom level, which is filled from left to right. The priority of every non-root node is less important than the priority of its parent. The key of a node <= the keys of the children. Height is O(log(n))

Tree

A collection of nodes, which can be empty, otherwise the special node r is caled the root. All its subtrees are connected by a directed edge from r. There are n-1 edges.

Priority Queue

A data structure with insert, add, and deleteMin which finds, returns, and removes the minimum element in the priority queue. Each element has a priority.

Stack

A list with the restriction that insertions and deletions can be performed in only one position, namely, the end of the list, called the top. Stacks are LIFO - Last In First Out. Push inserts on the top, pop deletes the most recently inserted element.

Implementation

A specific implementation of a data structure in a specific programming language

Data Structure

A specific organization of data for implementing an ADT

Binary Tree

A tree in which every node has at most two children. Max number of leaves: 2^h Max number of nodes: 2^(h+1) - 1

Efficiency covers

CPU, Memory, Disk, Network

Linked List

Consists of a collection of nodes, which are not necessarily adjacent in memory. Each node contains the element and a link to a node containing its successor (next link). printList and find(x) are O(N), findKth is no longer as efficient, findKth(i) is O(i). Adding to the front/removing the first item takes O(1) time, adding at the end takes O(1), removing last is complicated and requires doubly linked list

Doubly Linked-List

Every node maintains a link to its previous node in the list, allows for removing last item

Abstract Data Type (ADT)

Formal (Mathematical) description/model of components of the data and the set of operations that are allowed. Lists, sets and graphs are ADT, integers, reals and booleans are data types.

Euclid's Algorithm

Greatest Common Divisor = GCD(a, b) = GCD(b, a mod b) - If a < b, exchange a and b - a / b = r, if r = 0 b is the GCD

Implementation of Generic Trees

Have each node, beside its data/key, link to each child of the node. Simplest solution is to keep the children of each node in a linked list of tree nodes.

Performance

How much time is used when a program is executed; depends on the computer, operating system, compiler, etc.

O(log(n)) algorithm

If it takes constant time O(1), to cut the problem size by a fraction (normally 1/2). Input is pre-read because to take in a list of N numbers takes N.

Postorder Traversal

Left subtree, right subtree, root O(n)

Inorder Traversal

Left subtree, root, right subtree

Height

Length of the longest path from n to a leaf. All leaves are at height 0.

Depth

Length of the unique path from the root to n. Root is at depth 0.

List

Linear sequence of an arbitrary number of items. printList = O(n), find = O(n), findKth = O(1), insert/remove = O(n)

Queue

List of elements such that elements are inserted at the end of the list and deleted at the front of the list, FIFO - First In First Out Enqueue inserts at the end, dequeue removes the first element. Both linked list and array implementations give O(1) running times for every operation.

Leafs

Nodes with no children

Siblings

Nodes with the same parent

Binary Search

O(logN), cutting sorted list in halves depending on midpoint value in relation to search value. O(1) best case.

ArrayList implementation of Stack

Push by incrementing topOfStack and then set theArray[topOfStack] = x. To pop we set the return value to theArray[topOfStack] and then decrement topOfStack. Pop/Push are both very fast constant time operations.

Preorder Traversal

Root, left subtree, right subtree O(n)

Collections API

Set of classes and interfaces in Java that implement commonly reusable collection data structures, in Java.util

Priority Queue Implementation

Simple linked list: Insertion at the front is O(1), deleteMin is O(n) Sorted linked-list: Insertion at the front is O(n), deleteMin is (1). Binary search tree: Insertion and deleteMin are O(log(n)).

LinkedList Implementation of Stack

Singly linked list, push by inserting at the front of the list, pop by deleting the element at the front. Top operation examines the element at the front of the list and returns its value.

Big-O

T(n) = O(f(n)) such that T(n) <= cf(n) Greatest amount of some resource (time) that is required by an algorithm for some input size n

Big-Ω

T(n) = Ω(g(n)) such that T(n) >= cg(n) Least amount of some resource (time) that is required by an algorithm for some input size n

Hashing

Technique used for performing insertions, deletions, and searches in constant average time. Tree operations that require any ordering information among the elements are not supported efficiently, so no findMin or findMax. The ideal hash table data structure is merely an array of some fixed size, containing the items. The ideal hash table data structure is merely an array of some fixed size, containing the items.

Binary Search Tree Deletion

The hardest operation is deletion. If the node is a leaf, it can be deleted immediately. if the node has one child, the node can be deleted after its parent adjusts a link to bypass the node. If the node has two children, replace the data of the node with the smallest data of the right subtree, then recursively delete that node.

Tree Traversal

The process of visiting all the nodes of a tree. We always start from the root node, we do not randomly access a node in a tree.

Complexity

What happens as the size of the problem being solved gets larger?

Priority Queue (heap) operations

findMin: return root.data deleteMin: returns root.data, moves right-most leaf in last row to root to restore structure property, if necessary percolate down to restore heap properties, O(log(n)) insert: put new node in next position on bottom row to restore structure property, percolate up to restore heap properties, O(log(n)) but average O(1)

Unsorted linked-list, Unsorted Array, Sorted Linked List, Sorted Array, AVL-Tree, insert find and delete running time complexity

insert find delete Unsorted linked-list O(1) O(N) O(N) Unsorted array O(1) O(N) O(N) Sorted linked list O(N) O(N) O(N) Sorted array O(N) O(logN) O(N) AVL-tree O(logN) O(logN) O(logN)*


Related study sets

Excel Associate 2019 Skill Review 3

View Set

NCLEX - PN Review - CARDIOVASCULAR

View Set

Combo(Kap2+guide+mag2+bar+crunch+j2z)_copy_mag2

View Set

Chapter 4:Career Longevity: Self-Care, Burnout Prevention, and the Wellness Model.

View Set

Chapter 10 - Tourism Motivation & Travel Benefits

View Set

Ch 5 Reproductive Tract Infections (Ricci, Kyle & Carman: Maternity and Pediatric Nursing, Third Edition)

View Set