Fundamentals Of Data Structures Flashcards

Paper 1

1
Q

What are data structures?

A

Data structures are used by computers as the containers within which information is stored.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an Array

A

An array is an indexed set of related elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are abstract data types/data structures

A

Abstract data structures don’t exist as data structures in their own right, instead they make use of other data structures such as arrays to form a new way of storing data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a Queue

A

A queue is an abstract data structure based on an array(it is referred to as a First In First Out data structure(FIFO)).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are Linear Queues

A

A linear queue is a queue with two pointers(FRONT and REAR pointer) these pointers can be used to identify where to place a new item or used to identity the item at the front of the queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Operations that can be performed on a queue

A

Enqueue => add an item to a queue

Dequeue => to remove from a queue

IsEmpty => checks whether a queue is empty or not

IsFull => checks if queue is full

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are circular queues

A

They are queues where both the front and rare pointers can move to both ends of the queue making the queue more memory efficient.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the method that would need to be followed to attempt to remove an item from a circular queue implemented as a static data structure using an array.

A
  1. Check the queue is (not already) empty;
  2. Add one to the front pointer;
  3. Compare the value of the front pointer with the maximum size of the array;
  4. If equal then front pointer becomes zero.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe the method that would need to be followed to remove an item from a linear queue implemented as a static array.

A

Check if the queue is empty by comparing front and rear pointers.

If front == rear, the queue is empty → Report error

If not empty, increment the front pointer by 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe the method that would need to be followed to add an item to a linear queue implemented as a static array.

A

Check if the queue is not already full

If queue is full report error message

If it isn’t full, add 1 to the value of the rear pointer;

Then add the new item to the position indicated by the rear pointer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are Priority Queues?

A

In a priority queue, items are assigned a priority. Items with the highest priority are dequeued before low priority items.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a stack?

A

A stack is a first in, last out (FILO) abstract data structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Operations that can be performed on a stack

A

Push – Adds an item to the top of the stack.

Pop – Removes and returns the item from the top of the stack.

Peek / Top – Returns the item at the top without removing it.

IsEmpty – Checks if the stack has no items.

IsFull – Checks if the stack is full

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a graph?

A

A graph is an abstract data structure used to represent complex relationships between items within datasets.

Graphs can be used to represent networks such as transport networks, IT networks and the Internet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe a graph

A

A graph consists of nodes (sometimes called vertices) which are joined by edges (sometimes called arcs).

– A weighted graph is one in which edges are assigned a value, representing a value such as time, distance or cost.
– An unweighted graph is a graph where all edges are considered equal, with no numerical values or weights assigned to them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are Adjacency matrices and Adjacency lists.

A

Adjacency List – A way of representing a graph where each vertex stores a list of its connected vertices.(Rather than using a table to represent a graph, a list could be used.)

An adjacency matrix is a tabular representation of a graph. Each of the nodes in the graph is assigned both a row and a column in the table.

an adjacency list only records existing connections in a graph, unlike an adjacency matrix which stores even those edges that don’t exist.

16
Q

Difference between an adjacency list and adjacency matrix.

A
  • Adjacency Matrix => Stores every possible edge between nodes, even those that don’t exist. Almost half of the matrix is repeated data. (Memory Inefficient).
    Where as
    Adjacency List => Only stores the edges that exist in the graph.(Memory efficient)
  • Adjacency Matrix => Allows a specific edge to be queried very quickly, as it can be looked up by its row and column. (Time efficient)
    Where as
    Adjacency List => Slow to query, as each item in a list must be searched sequentially until the desired edge is found. (Time Inefficient)

Adjacency Matrix => Well suited to dense graphs, where there are a large number of edges.
Adjacency List => Well suited to sparse graphs, where there are few edges.

17
Q

What is a tree

A

A tree is a connected, undirected graph with no cycles.

A rooted tree has a root node from which all other nodes stem. When displayed as a diagram, the root node is usually at the top of the tree.

18
Q

What are parent nodes

A

Nodes from which other nodes stem are called parent nodes

19
Q

What are child nodes

A

Nodes with a parent are called child nodes and child nodes with no children are called leaf nodes.

19
Q

What is a binary tree

A

A binary tree is a rooted tree in which each parent node has no more than two child nodes.

Rooted trees (which include Binary trees) can be used to represent family trees or file systems on a computer’s hard drive.

20
Q

What are hash tables?

A

Hash tables are a way of storing data that allows data to be retrieved with a constant time complexity of O(1).

21
Q

What does an hashing algorithm do?

A

A hashing algorithm takes an input and returns a hash.

22
Q

What is collision?

A

This is when two pieces of data produce the same hash value.

23
Describe the steps involved in adding a record to a hash table.(5)
A hash function is applied to the key to generate a hash code. The hash code is mapped to an index in the hash table using modulus (hash % table size). The index is checked for a collision (i.e. if another record already exists there). If there is a collision, it is resolved using a method such as chaining or linear probing. The record is then inserted into the appropriate position in the table.
24
What is a dictionary?
A dictionary is a collection of key-value pairs in which the value is accessed by its associated key.
25
Define Vectors.
Vectors can be represented lists of numbers, functions or ways of representing a point in space.
26
What are static data structures?
These are data structures that are fixed in size.
27
What are dynamic data structures
These are data structures that can change in size to store their content.
28
Difference between Static and dynamic data structures.
Static Data Structures => -- Fixed at compile time. --sequential memory locations. --Can cause overflow errors. --Less flexible—size can't be changed once allocated. Dynamic Data Structures => --Can grow or shrink during runtime --linked via references/pointers --No overflow; memory is added as needed --More flexible—size changes as data is added/removed