Introducing Algorithms in C: A Step by Step Guide to Algorithms in C
()
About this ebook
Study elementary and complex algorithms with clear examples and implementations in C. This book introduces data types (simple and structured) and algorithms with graphical and textual explanations. In the next sections, you’ll cover simple and complex standard algorithms with their flowcharts: everything is integrated with explanations and tables to give a step-by-step evolution of the algorithms.
The main algorithms are: the sum of three or n numbers in a loop, decimal-to-binary conversion, maximum and minimum search, linear/sequential search, binary search, bubble sort, selection sort, merging of two sorted arrays, reading characters from a file, stack management, and factorial and Fibonacci sequences.The last section of Introducing Algorithms in C is devoted to the introduction of the C language and the implementation of the code, which is connected to the studied algorithms. The book is full of screenshots and illustrations showingthe meaning of the code.
What You Will Learn
- Implement algorithms in C
- Work with variables, constants, and primitive and structured types
- Use arrays, stacks, queues, graphs, trees, hash tables, records, and files
- Explore the design of algorithms
- Solve searching problems, including binary search, sorting, and bubble/selection sort
- Program recursive algorithms with factorial functions and Fibonacci sequences
Who This Book Is For
Primarily beginners: it can serve as a starting point for anyone who is beginning the study of computer science and information systems for the first time.
Related to Introducing Algorithms in C
Related ebooks
Beginning Mathematica and Wolfram for Data Science: Applications in Data Analysis, Machine Learning, and Neural Networks Rating: 0 out of 5 stars0 ratingsPractical MATLAB: With Modeling, Simulation, and Processing Projects Rating: 0 out of 5 stars0 ratingsLinear Programming: Foundations and Extensions Rating: 0 out of 5 stars0 ratingsCoding for beginners The basic syntax and structure of coding Rating: 0 out of 5 stars0 ratingsR Data Science Quick Reference: A Pocket Guide to APIs, Libraries, and Packages Rating: 0 out of 5 stars0 ratingsPractical Java Machine Learning: Projects with Google Cloud Platform and Amazon Web Services Rating: 0 out of 5 stars0 ratingsMATLAB Machine Learning Recipes: A Problem-Solution Approach Rating: 0 out of 5 stars0 ratingsBeginning MATLAB and Simulink: From Novice to Professional Rating: 0 out of 5 stars0 ratingsThe Joys of Hashing: Hash Table Programming with C Rating: 0 out of 5 stars0 ratingsComputer Algebra: Fundamentals and Applications Rating: 0 out of 5 stars0 ratingsJoe Celko's Trees and Hierarchies in SQL for Smarties Rating: 0 out of 5 stars0 ratingsPractical Numerical C Programming: Finance, Engineering, and Physics Applications Rating: 0 out of 5 stars0 ratingsData Analysis for Corporate Finance: Building financial models using SQL, Python, and MS PowerBI Rating: 0 out of 5 stars0 ratingsIntroduction to Programming Languages Rating: 4 out of 5 stars4/5Numerical C: Applied Computational Programming with Case Studies Rating: 0 out of 5 stars0 ratingsJust Enough R: Learn Data Analysis with R in a Day Rating: 4 out of 5 stars4/5Distributed Algorithms Rating: 3 out of 5 stars3/5Optimizing AI and Machine Learning Solutions: Your ultimate guide to building high-impact ML/AI solutions (English Edition) Rating: 0 out of 5 stars0 ratingsSimple Data Science (R) Rating: 5 out of 5 stars5/5Machine Learning Algorithms for Data Scientists: An Overview Rating: 0 out of 5 stars0 ratingsMathematica Data Analysis Rating: 0 out of 5 stars0 ratingsBiostatistics and Computer-based Analysis of Health Data using R Rating: 0 out of 5 stars0 ratingsText Mining with MATLAB® Rating: 0 out of 5 stars0 ratingsData Structures and Algorithms with Go: Create efficient solutions and optimize your Go coding skills (English Edition) Rating: 0 out of 5 stars0 ratingsProgramming Concepts in C++ Rating: 0 out of 5 stars0 ratingsUltimate Enterprise Data Analysis and Forecasting using Python Rating: 0 out of 5 stars0 ratingsHP Prime Guide Algebra Fundamentals: HP Prime Revealed and Extended Rating: 0 out of 5 stars0 ratingsInstant Heat Maps in R How-to Rating: 0 out of 5 stars0 ratingsCollection of Raspberry Pi Projects Rating: 5 out of 5 stars5/5
Programming For You
Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5Game Development with Unreal Engine 5: Learn the Basics of Game Development in Unreal Engine 5 (English Edition) Rating: 0 out of 5 stars0 ratingsExcel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5C# Programming from Zero to Proficiency (Beginner): C# from Zero to Proficiency, #2 Rating: 0 out of 5 stars0 ratingsPython Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Learn JavaScript in 24 Hours Rating: 3 out of 5 stars3/5Python QuickStart Guide: The Simplified Beginner's Guide to Python Programming Using Hands-On Projects and Real-World Applications Rating: 0 out of 5 stars0 ratingsPYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5Problem Solving in C and Python: Programming Exercises and Solutions, Part 1 Rating: 5 out of 5 stars5/5Python Data Structures and Algorithms Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5The Unofficial Guide to Open Broadcaster Software: OBS: The World's Most Popular Free Live-Streaming Application Rating: 0 out of 5 stars0 ratingsPython GUI Programming Cookbook - Second Edition Rating: 5 out of 5 stars5/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5
Reviews for Introducing Algorithms in C
0 ratings0 reviews
Book preview
Introducing Algorithms in C - Luciano Manelli
© Luciano Manelli 2020
L. ManelliIntroducing Algorithms in Chttps://doi.org/10.1007/978-1-4842-5623-7_1
1. Data Structures
Luciano Manelli¹
(1)
Taranto, Italy
The study of algorithms is connected to data structures. A data structure is a way to store data to facilitate organization and modifications. Every data structure is used for a specific purpose, so it is important to know the characteristics of several of them so you can choose the data structures that are appropriate for the operations performed by an algorithm.
Variables and Constants
A variable represents a memory location that stores an assigned value. Each variable is associated with a data type and stores one or some values. Variables can change their value during program execution, but they cannot change their structure or their data type. A variable is characterized by three elements.
Name: A variable’s name must be unique and inherent to the programming context, mainly to avoid ambiguity in the program.
Type: A variable’s type indicates whether the variable is an integer, a float, a character, and so on. Each type allocates different space in central memory.
Content: A variable’s content is the value assigned to the variable in a step of the program execution.
Furthermore, the most important operators are assignment and comparison.
Assignment: The symbol = (a single equal sign) assigns a value to a variable.
Test for equality: The symbol == (two equal signs) compares the values of two variables (an expression with a final value of true or false).
For example, if we wanted to assign the value 4 to the variable a and the value 5 to the variable b, we would write the following:
a=4;
b=5;
For example, if we wanted to compare a and b, we would write the following:
a==b;
Note that C and Java programs use this notation.
For example, if we wanted to sum two variables (a and b) and we wanted to store the result of this operation in the variable SUM, we would write the following:
SUM = a+b;
In some cases, we might be interested in the iterative sum of a set of values for an algorithm. For example, if we wanted to know the sum of some integer values, we could use an intermediate variable and write the following:
intermediate_sum = final_sum + new_value;
final_sum = intermediate_sum;
We could also write in a compact form, without using an intermediate variable, as shown here:
final_sum = final_sum + new_value;
In computer science, we can add the new_value to the content of the variable final_sum and store the result in the same variable, final_sum. Reading the formula from left to right, the first variable final_sum indicates the new value of the sum, the second variable indicates the value currently stored in the variable final_sum, and the third variable indicates a new value (new_value) that has to be added to the current variable final_sum.
../images/492269_1_En_1_Chapter/492269_1_En_1_Figa_HTML.pngIn some cases, we are interested in the use of a counter, such as an index i that increases its value at each step of an algorithm. For example, consider an integer index named i that is incremented by 1 at each step. This condition is expressed in the following formula:
../images/492269_1_En_1_Chapter/492269_1_En_1_Figb_HTML.pngReading the formula from left to right, the first index i indicates the new value of the counter, the second variable indicates the value currently stored in the counter i, and the third variable indicates a new value (1) that has to be added to the current variable i.
Constants are similar to variables, but they cannot change their value during program execution. They also usually have a different type of declaration in the program. For example, if we wanted to assign an integer value (4) to the constant const in the C language, we would write the following:
#define CONST = 4
Once a constant is defined, it cannot be modified by the program.
Primitive Types
It is possible to define the following primitive types:
Numeric: This type includes integers (numbers without decimal points) and floats (numbers with a decimal after a decimal point). They are stored differently in memory and have different scopes. A float is usually declared when more precision is needed.
Character: The character type includes letters and dots.
Boolean (true and false): Booleans usually are used to compare variable values. The comparison can be either true or false.
Structured Types
To represent data in other ways, it is possible to define structured types. The following are the basic structuring methods presented in this chapter:
Array
Linked list
Queue
Stack
Graph
Tree
Hash table
Record
File
Array
One of the most important elementary data structures is the array. An array is a sequence of n items of the same data type stored contiguously in computer memory. An array is accessible by specifying a value of the array’s index (an integer between 0 and n – 1, where n is the length of the array).
So, an array is characterized by the following:
Name (for example,