S02 - Fundamentals of Data Structures

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

1/52

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.

53 Terms

1
New cards

Advantages of Arrays

Direct access to data

2
New cards

Disadvantages of Arrays

Potentially wasteful of memory

3
New cards

Static data structure

Size is declared at compile-time and doesn’t change during runtime

4
New cards

Advantages of static data structure

With memory allocation fixed, no control or oversight is needed to prevent potential overflow or underflow issues when adding new items or removing existing ones.

5
New cards

Dynamic data structure

Size can grow or shrink during runtime

6
New cards

Disadvantage of dynamic data structure

Requires extra memory to store pointers to the next item

7
New cards

Differences of Static and Dynamic data structures

  • Static data structures have storage size determined at compile-time

  • Dynamic data structures can grow/shrink at runtime

  • Static data structures have fixed size

  • Static data structures can waste space/memory if the number of items stored is small relative to the size of the structure

  • Dynamic data structures only take up the amount of storage space required for the actual data

  • Dynamic data structures require pointers to the next item which requires memory

  • Static data structures store data in consecutive memory locations

8
New cards

Abstract Data Type (ADT)

Logical description of how we view the data and possible operations

9
New cards

Linear queues

FIFO logic, items join at the rear and leave at the front

10
New cards

What does the front pointer in a queue point to

Next item to remove

11
New cards

What does the rear pointer in a queue point to

Last item added

12
New cards

Methods for queues

Enqueue(item), Dequeue(), isFull(), isEmpty()

13
New cards

Stacks

LIFO logic, items are pushed on top of the stack and removed from the top of the stack

14
New cards

Basic operations of stacks

Push(item), pop(), peek(), isFull(), isEmpty()

15
New cards

Explain how a single stack can be used to reverse the order of the items in a queue

Until the queue is empty, repeatedly remove items from the front of the queue and push it on top of the stack and add them to the rear of the queue

16
New cards

Call stack

System-level data structure. Keeps track of the point to which each subroutine should return control when it finishes executing, the use of this is hidden from the programmer in HLL.

17
New cards

Stack frame contents

  • Return address on completion of subroutine execution

  • Values of all parameters

  • Values of all local variables

18
New cards

How are calls to subroutines executed

  1. The parameters are added to a stack frame

  2. Local variables are added to the same stack frame

  3. Local variables are added to the same stack frame

  4. The address to which execution returns after the end of the subroutine is reached is added to the same stack frame

  5. Execution is transferred to the subroutine code

19
New cards

What happens when the subroutine completes execution?

  1. The stack is popped

  2. Program control is returned to the address mentioned in the popped stack frame

  3. The values of local variables are parameters are also extracted from the stack frame

  4. Execution is transferred back to the return address

20
New cards

Abstraction

The process of removing unnecessary details from some representation

21
New cards

Use of adjacency matrix

Many edges, useful if many changes needed to the graph due to direct access to an edge

22
New cards

Advantages of adjacency matrix

More useful when there are lots of edges, or when many changes are made to the graph due to an edge

23
New cards

Disadvantages of adjacency matrix

Not useful for sparse graph with not many connections - most cells empty, memory space wasted

24
New cards

Why an adjacency matrix shouldn’t be used

For a sparse graph with not many connections, waste of memory

25
New cards

Graph

diagram consisting of vertices, joined by edges where each edge joins exactly two vertices

26
New cards

Uses of adjacency list

Large, sparsely connected graph, only uses storage for connections that exist which is more space efficient

27
New cards

Adjacency list

An alternative way of representing a graph - a list of nodes is created, and each node points to a list of adjacent nodes - dictionary data structure

28
New cards

Advantages of adjacency list

Only uses storage for connections that exist - more space efficient. Good way of representing a large, sparsely connected graph

29
New cards

Tree

fully connected undirected graph with no cycles; doesn’t have to have a root

30
New cards

Rooted tree

tree with one node designated as the root

31
New cards

Binary tree

Rooted tree in which every node has at most 2 children

32
New cards

Binary search tree

  • Items are added using an algorithm, by comparing a new item with the root of the tree, then with every subtree’s root

  • Makes search quicker

  • Items can also be output in order

33
New cards

Binary search tree

Items are added using an algorithm by comparing a new item with the root of the tree, then with every subtree’s root

34
New cards

Advantages of binary search tree

Makes the search quicker, items can be output in order which is faster than the usual sort algorithm

35
New cards

Uses of binary search trees in Computer Science

OS: directory of files and folder structure; Compiler: to build syntax trees; Routers: store routing tables

36
New cards

Hash table

Data structure that creates mapping between keys and values

37
New cards

Collision

When two keys compute the same hash

38
New cards

Hashing algorithm

Calculation that takes the key as input and computes into a hash that is what is stored in the hash table

39
New cards

Collision resolution

Store the record in the next available location in the file

40
New cards

Explain how a value is stored in a hash table

Hashing algorithm is applied to the key; The result is an index of where to store the value in an array; It is possible that the hashing algorithm might generate the same key for two different values (collision); in which case a collision handling method is used

41
New cards

What happens if the load factor of a hash table is >60-65%

Increase table size and rehash all data items; choose a prime number as the hash table size

42
New cards

Searching the hash table

Apply the hash function to the key of the item sought. If target is at the hash then it is found, if not then look for a ‘deleted’ marker. If there is no marker, the item is not found.

43
New cards

Scalar multiplication

Scaling the original vector by a factor of a given multiplier

44
New cards

Convex combination

Space bounded by two vectors and the line joining their ends

45
New cards

Dot product

Value resulting in the sum of products u.v = u1v1+u2v2+u3v3+…+unvn

46
New cards

Applications of dot product

Calculate parity bit in GF(2)

47
New cards

Galois Field

Given to a set that consists of a finite number of items

48
New cards

Dictionary

An abstract data type made up of associated pairs, key and a value

49
New cards

Use of dictionaries

Applications where items need to be looked up: ASCII or Unicode table, foreign language dictionary, trees and graphs

50
New cards

Vector

A mathematical quantity that has both magnitude and direction

51
New cards

Vector addition

If the two vectors are represented as an arrow in the 2D space, the vector addition is the diagonal vector of the resulting parallelogram; its effect is vector translation, of one of the two vectors across the other

52
New cards

Scaler multiplication

Scaling the original vector by a factor of given multiplier

53
New cards

Convex combination

Space bounded by two vectors and the line joining their ends; Formula: w = αu + βv, where α, β >= 0 and α+β=1; vector w will fall on the line, or inside the space if α+β < 1 (this is the convex hull)