Introduction to Data Structures Flashcards
What is a data structure?
A data structure is a set of data elements that provide an efficient way to store, organize, and use data in the computer.
Why do we need data structures?
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:
- Processing: Large amounts of processing speeds are required to handle the data, and the processor is likely to fail
- Searching: Searching through the data becomes slow and inefficient
- 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
What are the advantages of data structures?
- 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. - Re-usability: Data structures only need to be implemented once and can be used multiple times throughout the program.
- Abstraction: Data structures provide abstraction as they can be used by client programs that do not know about the details of their implementation
How are data structures classified?
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
What is a linear data structure and what are the types of linear data structures?
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
What is a non-linear data structure and what are the types of non-linear data structures?
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
- Graphs: A data structure, with data elements called nodes each node can be connected to multiple other nodes through a link called an edge
What is the difference between a graph and a tree?
Graphs can form a cycle while tress cannot
What are the types of operations that can be performed on a data structure?
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 do you know if a linked list has a loop?
-> 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
What is an abstract data type?
It is a way of defining a structure, without getting into the details of its implementation