Data Structure and Algorithms final exam

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play

1/52

encourage image

There are no tags or description

Looks like no tags are added yet.

53 Terms

1
New cards

encapsulation

bundling of data and methods within a class

2
New cards

accessibility

public - everywhere

private - same class

protected - same package and subclasses

3
New cards

overriding

child provides new implementation of a method that was defined in the parent class

4
New cards

dynamic binding

method executed is determined at runtime by object type

5
New cards

Arithmetic Exception cause

divide by zero

6
New cards

Null Pointer Exception cause

using null reference

7
New cards

Array Index Out Of Bounds Exception cause

invalid array index

8
New cards

Number format Exception cause

invalid string to number conversion

9
New cards

IO Exception cause

file IO problems

10
New cards

recursion

method calls itself to solve smaller version of the same problem, must include base case and a recursive call

11
New cards

Stack Overflow Error cause

missing base case in recursion

12
New cards

lists

ordered collection allowing duplicates, maintains insertion order

13
New cards

ArrayList

resizable, fast random access, less memory

14
New cards

LinkedList

stores elements as connected nodes, slow random access, fast insertion/deletion at beginning or middle, more memory

15
New cards
16
New cards

time complexity of access and insertion/deletion of ArrayList and LinkedList

ArrayList - access O(1), insertion/deletion O(n)

LinkedList - access O(n), insertion/deletion O(1)

17
New cards

stack and its common functions

last in first out

push() - inserts element at top

pop() - removes top element

18
New cards

queue and its common functions

first in first out, implemented by classes such as LinkedList, ArrayDeque, and PriorityQueue

peek() - views the top

poll() - removes the top

19
New cards

priority queue

processes based on priority not insertion order

20
New cards

set

stores unique elements, O(n) insertion

21
New cards

sets lookup and ordering

HashSet - O(1) av and O(n) worst lookup, no ordering

LinkedHashSet - O(1) av and O(n) worst lookup, insertion order

TreeSet - O(log n) lookup, sorted order

22
New cards

map

stores data in key value pairs, O(n) insertion

23
New cards

maps lookup and ordering

HashMap - O(1) av and O(n) worst lookup, no order

LinkedHashMap - O(1) av and O(n) worst lookup, insertion order

TreeMap - O(log n) lookup, sorted order

24
New cards

time complexity of loop dividing by two or doubling

O(log n)

25
New cards

insertion and bubble sort time complexity

best O(n), av and worst O(n²)

26
New cards

quick sort time complexity

best and av O(n log n), worst O(n²)

27
New cards

merge and heap sort time complexity

best, av and worst O(n log n)

28
New cards

insertion sort

  1. mark first element as sorted

  2. starting at index 1, compare element with elements to the left until finding one smaller

  3. repeat until sorted


29
New cards

bubble sort

  1. start at first element and compare it to the next, swap if first is greater

  2. continue for all adjacent elements in array to complete one pass, now last element is sorted

  3. continue until a pass with no swaps


30
New cards

quick sort

  1. pick a pivot and put all numbers smaller on left and all larger on right by going left to right

  2. then swap the pivot to the correct location

  3. repeat for left and right groups until sorted


31
New cards

merge sort

  1. divide list into halves until single elements remain

  2. sort back upward until list is sorted by combining the halves


32
New cards

heap sort

  1. move largest element to the end and repeat until sorted

  2. to create tree work backwards, completely filling in each level until moving to the next


33
New cards

stable sorts

insertion, bubble, and merge

34
New cards

insertion in binary search tree

start at root, go left or right depending on the value and insert when a null position is found

35
New cards

deletion in binary search tree (3 cases)

  1. no children - just delete

  2. one child - delete and move child to replace it

  3. two children - find smallest value in right subtree and replace node that is being deleted


36
New cards

insertion/deletion in BST time complexity

best and av O(log n), worst O(n)

37
New cards

inorder traversal

left, root, right (ascending order in BST)

38
New cards

preorder traversal

root, left, right

39
New cards

post order traversal

left, right, root

40
New cards

AVL tree

self balancing binary search tree

41
New cards

AVL balance factor

= height left subtree - height right subtree

42
New cards

time complexity in AVL tree

insert/search/delete O(log n), rotation O(1)

43
New cards

hash table

stores values

44
New cards

hash function

maps key to an index

45
New cards

hash collision

hash function produces same table index for 2 keys

46
New cards

linear probing

checks consecutive slots

47
New cards

quadratic probing

jumps by increasing square values

48
New cards

double hashing

reduces collisions and most clustering

49
New cards

getDegree(#)

look at all points that have # in either spot, then how many unique neighbors there are (other number in points)

50
New cards

sum of vertex degrees

n(n-1)

51
New cards

number of edges

n(n-1) / 2

52
New cards

left bitwise shift

num1 × 2^num2

53
New cards

right bitwise shift

num1 / 2^num2