§ — — Data Structures and Algorithms
Computers work with large amounts of information. To process that information efficiently, data must be arranged in a way that makes storage, retrieval, updating, and computation practical. A data structure is a method of organizing data in memory or storage so that a program can use the data effectively.
A good data structure answers two important questions:
For example, a program that frequently searches for records may need a different structure from a program that mostly adds new records at the end of a list.
Data means raw facts or values that can be processed, such as numbers, names, grades, or symbols.
Structure refers to the arrangement or organization of parts.
A data structure is therefore an organized collection of data that supports specific operations. Common examples include arrays, linked lists, stacks, queues, trees, graphs, and hash tables.
Data structures can be grouped based on how their elements are connected.
| Category | Description | Examples |
|---|---|---|
| Linear | Elements are arranged in a sequence. Each item has a clear previous and next relationship, except at the ends. | Array, linked list, stack, queue |
| Nonlinear / hierarchical | Elements are not arranged in one straight sequence. Items may branch or connect in multiple directions. | Tree, graph, heap |
A data type describes the kind of value a variable can store. Examples include:
true or falseChoosing the correct data type helps a program store values properly and perform valid operations on them.
An Abstract Data Type (ADT) describes data and the operations allowed on that data without focusing on how the data is implemented internally.
For example, a stack ADT may define these operations:
push to add an itempop to remove the most recently added itempeek to view the top itemisEmpty to check whether the stack has no itemsThe ADT describes what the structure can do. The implementation decides how it is built, such as by using an array or a linked list.
An algorithm is a finite set of clear instructions used to solve a problem or perform a task. A program is usually based on one or more algorithms.
A valid algorithm should have:
| Criterion | Meaning |
|---|---|
| Input | It may receive zero or more values. |
| Output | It should produce at least one result. |
| Definiteness | Each instruction must be clear and unambiguous. |
| Finiteness | It must stop after a limited number of steps. |
| Effectiveness | Each step must be possible to perform. |
Pseudocode is a plain-language description of an algorithm. It looks more structured than regular writing but is not tied to a specific programming language. It is useful for planning logic before writing code.
Stepwise refinement means starting with a broad solution and gradually breaking it into smaller, more detailed steps until the algorithm is ready to be coded.
Algorithm analysis studies how many resources an algorithm needs. The most common resources are:
Common cases include:
Write an algorithm, pseudocode, and Java condition that identifies whether a number is positive or negative.
Positive if the condition is true.Negative.INPUT number
IF number > 0 THEN
DISPLAY "Positive"
ELSE
DISPLAY "Negative"
END IF
if (number > 0) {
System.out.println("Positive");
} else {
System.out.println("Negative");
}
Create a program that accepts three grades: prelim, midterm, and final. Compute the average. If the average is at least 75, display Passed; otherwise, display Failed. Then write the algorithm and pseudocode for your solution.
Free Sample
That was 1 of 13 reviewers with answer keys in Data Structures and Algorithms. Unlock all of them for the semester.
Unlock all reviewers →Done with this module? Track it — your progress shows on the subject list.
Up next
Costs, Benefits, and Choosing Data Structures→