Important to remember CISC220 Midterm 2

0.0(0)
studied byStudied by 5 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/60

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

61 Terms

1
New cards

What differs a tree vs binary search tree?

a tree each node has 1 parent and 0 or more children in a BST each node has 1 parent and 0-2 children

2
New cards

What are nodes with no children called?

leaf

3
New cards

How do you remove a node with two children

look for a replacement node either in the left subtree right max or right subtree left min

4
New cards

How do you calculate the number of nodes in a BST?

2^levels-1 and 2^levels (not including 2^levels)

5
New cards

How do you figure out how many levels are in a BST?

log_2 (n)

6
New cards

If there are between 2^(levels-1) and 2^(levels) nodes, it will take at most _______________ steps to find any node.

level number

7
New cards

How can you tell if a BST is balanced?

at any node, the height of the left subtree and the height of the right subtree differ by ONE

8
New cards

AVL left rotation

unbalanced node = -2 and right child balance = -1

(x→leftChild→rightChild)

9
New cards

AVL right rotation

Unbalanced node = 2 and left child balance = 1

(x→rightChild→leftChild)

10
New cards

AVL Left right rotation

unbalance node = -2 and right child = 1

11
New cards

AVL Right left rotation

unbalanced node = 2 left child balance = -1

12
New cards

What is the time complexity for the best case for BST (balanced)?

O(log n)

13
New cards

What is the time complexity for the worst case for BST (unbalanced)?

O(n)

14
New cards

What is the time complexity for maintaining, finding, inserting, removing in an AVL tree?

O(log n)

15
New cards

What is the order for Pre-Order

root left right

16
New cards

What is the order for in order

left root right

17
New cards

What is the order for post order

children before parent

18
New cards

What is Pre-Order used for?

copying a tree

19
New cards

What is post-order used for

deleting a tree

20
New cards

What is In-Order used for?

Getting the order of a tree (BST)

21
New cards

What is QuickSort average run time? (Best case: unsorted algo)

O(n log n)

22
New cards

What is QuickSort average run time? (Worst Case: sorted algo)

O(n²)

23
New cards

What are some ways to make a sorted list of QuickSort closer to O(n log n)

  • Scramble array before quicksort

  • Use middle element of subarray as pivot

  • use a random element of the array as pivot

  • median of three elements as the pivot

  • All of the above

All of the above

24
New cards

What is the logic for quicksort?

All values to the left are less than the pivot all values to the right are greater than pivot

25
New cards

What is merge sort algorithm?

Combine two sorted sequences into one larger sorted

26
New cards

What is best case time for merge sort?

O(n log n)

27
New cards

What is worst case time for merge sort?

O(n log n)

28
New cards

What is time complexity for merging in merge sort

O(n)

29
New cards
<p>Identify which sorting algorithm this is</p>

Identify which sorting algorithm this is

Merge Sort

30
New cards
<p>Identify which sorting algorithm this is</p>

Identify which sorting algorithm this is

Quick Sort

31
New cards

What are the characteristics of a set?

No Duplicates, no order, all data is the same type

32
New cards

Hash functions take a _________ and calculates a number that can be used as an _________ in the map

a. pizza; food

b. key; index

c index; key

key; index

33
New cards

What are three things we need to worry about when Hashing?

Hashing function, array size, collisions

34
New cards

What are the qualities of a good hashing function?

  • maps all keys indices within the array

  • distributes keys evenly throughout array

  • avoids collisions

  • computes quickly and consistently

35
New cards

Why is it important to have the array size prime for a hash function?

Spread remainder more evenly throughout the array

36
New cards

What should hash function be careful of in terms of hashing strings?

large num of shorter words and prefixes that words have in common

37
New cards

What is Chaining?

Make the hash array be an array of linked lists

38
New cards

What is linear probing?

Keep going to next index until empty space

39
New cards

what is quadratic probing?

jump using i^i (1×1, 2×2, 3×3….)

40
New cards

What is double hashing?

Use a second hash function is theres a collision at the first collision function

41
New cards

What are problems with linear clustering?

Clustering around one area in the array and then takes too long to search and wastes space:(

42
New cards

How to remove from a hashmap with chaining?

Just remove from linked list!

43
New cards

Huge arrays with little data = ???

fewer collisions but wasted space

44
New cards

Smaller arrays with large amounts of data = ???

More collisions but less wasted space

45
New cards

What does Load facotr indicate??

how full the array is

46
New cards

What is the formula for a load factor

number of indices filled / total number of slots

47
New cards

What to do if load gets less than under 25%

Make new array HALF old array size, up to nearest prime and rehash all values (less wasted space)

48
New cards

What to do if load is over 70%

allocate new array double old array size, take pairs rehash (less collisions)

49
New cards

Time complexity: Finding in an unbalanced binary search tree

O(n)

50
New cards

Time complexity: Inserting into a balanced binary search tree

O( log n)

51
New cards

Time complexity: Sorting an ordered list using mergesort

O(n log n)

52
New cards

Time complexity: Sorting a completely random list using quicksort

O(n log n)

53
New cards

Time complexity: Sorting an ordered list (with the first number as the pivot) using quicksort

O(n²)

54
New cards

Time complexity: Finding optimally in a hashmap

O(n)

55
New cards

Time complexity: Finding in a balanced binary search tree

O(log n)

56
New cards

true or false: a binary tree differs from a tree in that each node can have more than one successor

false

57
New cards

true or false: a complete tree is one in which each level is full, except the lead level, which if full from left to right

true

58
New cards

true or false: a binary search tree differs from a tree in that each node, the left childs data is less than the nodes data and the right childs data is greater than the nodes data

true

59
New cards

true of false: a balanced binary seach tree is balanced. balanced means that for each node, the height of the left child and the height of the right child differ by no more than one. 

true

60
New cards

what is a general tree?

a node can have any number of children

61
New cards

What is a full binary tree?

A full binary tree is a binary tree in which all of the nodes have either 0 or 2 offspring