Introduction to Data Structures Flashcards

1
Q

What is a data structure?

A

A data structure is a set of data elements that provide an efficient way to store, organize, and use data in the computer.

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

Why do we need data structures?

A

When data is stored in increasingly large amounts, and the data is not stored and organized efficiently through the use of data structures, 3 problems arise:

  1. Processing: Large amounts of processing speeds are required to handle the data, and the processor is likely to fail
  2. Searching: Searching through the data becomes slow and inefficient
  3. Multiple requests: If the data is stored on a server, the more the request for the data from that server the more likely it is to fail
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the advantages of data structures?

A
  1. Efficiency: The efficiency of a program depends on the data structure used e.g In a searching algorithm it is better to use a binary search tree or sorted array, to
    reduce the number of traversals needed for searching, and increase efficiency.
  2. Re-usability: Data structures only need to be implemented once and can be used multiple times throughout the program.
  3. Abstraction: Data structures provide abstraction as they can be used by client programs that do not know about the details of their implementation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How are data structures classified?

A

Data structures are of two types: primitive and nonprimitive
primitive data structures include: int, float, char, e.t.c
nonprimitive data structures include: Linear and Nonlinear data structures
nonlinear data structures include: trees and graphs
linear data structures include: static and dynamic data structures
static data structures include: arrays
dynamic data structures include: stacks, queues, linked list

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

What is a linear data structure and what are the types of linear data structures?

A

Linear data structures are data structures whose data elements are organized in a linear and non-hierarchical manner they include:
1. Arrays: A collection of data elements of the same data type, that share the same name but different positions/indexes within the collection
2. Linked List: A collection of elements called nodes, each node containing data and a pointer pointing to the next node in the collection
3. Stacks: Linear data structures where insertion and deletion are done at one end called the top
4. Queues: Linear data structures where insertion is done at one end called the rear and deletion is done at the other end called the front

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

What is a non-linear data structure and what are the types of non-linear data structures?

A

A nonlinear data structure is a data structure whose elements are organized in a nonsequential manner and elements can be connected to multiple other elements. They
include:
1. Trees: A multilevel data structure where data elements are called nodes, nodes up a level are called parents, and the nodes connected to them on a level below are called
children, the topmost node is called the root node, and the bottom-most nodes are called the leave node, each node can have multiple children and a parent except the leave nodes
and the root node respectively

  1. Graphs: A data structure, with data elements called nodes each node can be connected to multiple other nodes through a link called an edge
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between a graph and a tree?

A

Graphs can form a cycle while tress cannot

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

What are the types of operations that can be performed on a data structure?

A

There are 6 operations that can be performed on data structures which include:
1. Traversal: When every element in the data structure is visited
2. Inserting: When an element is added to the data structure
3. Deleting: When an element is removed from the data structure
4. Searching: When the position of an element in the data structure is located
5. Sorting: When elements are arranged in a specific order
6. Merged: When multiple data structures are fused together to form a single data structure

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

How do you know if a linked list has a loop?

A

-> Inianalize two pointers slow and fast, both starting at the head of the linked list
-> The slow pointer should move one step at a time, while the fast pointer moves two pointers at a time
-> If the fast pointer eventually equals the slow pointer, then there is a loop, else there is no loop

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

What is an abstract data type?

A

It is a way of defining a structure, without getting into the details of its implementation

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