Lecture 5: Data Structures

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/44

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.

45 Terms

1
New cards

Structures (structs)

“super variable” that provides a way to unify several variables of different types into a single, new variable type which can be assigned its own type name.

2
New cards

Arrow Operator (→)

an operator that does two things back-to-back: First, it dereferences the pointer on the left side of the operator. Second, it accesses the field on the right side of the operator.

3
New cards

Linked List Node

a special kind of struct with two members: Data of some data type (int, char, float…) and A pointer to another node of the same type

4
New cards

Linked List

a type of data structure that combines the use of pointers, dynamic memory allocation, and structs which gives the ability to grow and shrink a collection of like values to fit our needs.

5
New cards

Create a Linked List

knowt flashcard image
6
New cards

Search through a linked list to find an element.

knowt flashcard image
7
New cards

Insert a new node into the linked list (singly)

knowt flashcard image
8
New cards

Delete an entire Linked List

knowt flashcard image
9
New cards

Difference between a Singly-Linked List and a Doubly-Linked List

a singly linked list can only ever move in one direction through the list while a doubly linked list allows us to move forward and backward through the list, all by simply adding one extra pointer to our struct definition

10
New cards

Insert a new node into a linked list (doubly)

knowt flashcard image
11
New cards

Delete a node from a linked list.

knowt flashcard image
12
New cards

Benefit of using Linked Lists

supports extremely efficient insertion and deletion of elements (operations are done in constant time)

13
New cards

Downfall of using Linked lists

lost the ability to randomly-access list elements (accessing a desired element now takes linear time)

14
New cards

Stack

a special type of structure that can be used to maintain data in an organized way and is commonly implemented as an array or a linked list (follows LIFO)

15
New cards

Last in, first out (LIFO)

important rule of a stack; when data is added to the stack, it sits “on top,” and so if an element needs to be removed, the most recently added element is the only element that can legally be removed.

16
New cards

Push

Stack operation that adds a new element to the top of the stack.

17
New cards

Pop

Stack operation that removes the most recently-added element from the top of the stack

18
New cards

Array based implementation of a stack

knowt flashcard image
19
New cards

Use of push() in a array-based implementation of a stack

knowt flashcard image
20
New cards

Use of pop() in a array-based implementation of a stack

knowt flashcard image
21
New cards

Linked List-based implementation of a stack

knowt flashcard image
22
New cards

Use of push() in a linked list-based implementation of a stack

dynamically allocate a new node, set its next pointer to point to the current head of the list, then move the head pointer to the newly-created node.

23
New cards

Use of pop() in a linked list-based implementation of a stack

traverse the linked list to its second element (if it exists), free the head of the list, then move the head pointer to the (former) second element

24
New cards

Queue

a special type of structure that can be used to maintain data in an organized way and is commonly implemented as an array or a linked list (follows FIFO)

25
New cards

FIFO

Important Rule of a queue; when data is added to the queue, it is tacked onto the end, and so if an element needs to be removed, the element at the front is the only element that can legally be removed.

26
New cards

Enqueue

Queue operation that adds a new element to the end of the queue.

27
New cards

Dequeue

Queue operation that removes the oldest element from the front of the queue.

28
New cards

Array-based implementation of a queue

knowt flashcard image
29
New cards

Use of enqueue() for a Array-based implementation of a queue

knowt flashcard image
30
New cards

Use of dequeue() for a Array-based implementation of a queue

knowt flashcard image
31
New cards

Linked List-based implementation of a queue

knowt flashcard image
32
New cards

Use of Enqueue() in a Linked List-based implementation of a queue

knowt flashcard image
33
New cards

Use of dequeue() in a Linked List-based implementation of a queue

knowt flashcard image
34
New cards

Usefulness of Hash tables’ ability to combine the random access ability of an array with the dynamism of a linked list.

downfall is that they are not great at ordering or sorting data,

<p>downfall is that they are not great at ordering or sorting data,</p>
35
New cards

Hash table consists of..

  1. a hash function, which returns an nonnegative integer value called a hash code.

  2. an array capable of storing data of the type we wish to place into the data structure.

36
New cards

A good hash function should..

knowt flashcard image
37
New cards

Collision

occurs when two pieces of data, when run through the hash function, yield the same hash code

38
New cards

Linear probing

a method to solve collisions where if we have a collision, we try to place the data in the next consecutive element in the array (wrapping around to the beginning if necessary) until we find a vacancy. That way, if we don’t find what we’re looking for in the first location, at least hopefully the element is somewhere nearby.

39
New cards

Clustering

a possible problem of linear probing where once there’s a miss, two adjacent cells will contain data, making it more likely in the future that the cluster will grow.

40
New cards

Chaining

a method to solve collisions where instead of each element of the array holding just one piece of data, it held multiple pieces of data (If each element of the array is a pointer to the head of a linked list, then multiple pieces of data can yield the same hash code and we’ll be able to store it all)

41
New cards

Trie

combines structures and pointers together to store data in a roadmap (no collisions and no two pieces of data (unless identical) have the same path)

42
New cards

Array Summary

knowt flashcard image
43
New cards

Linked List Summary

knowt flashcard image
44
New cards

Hash Table Summary

knowt flashcard image
45
New cards

Tries Summary

knowt flashcard image