Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
C# Data Structures and Algorithms - Second Edition
C# Data Structures and Algorithms - Second Edition

C# Data Structures and Algorithms: Harness the power of C# to build a diverse range of efficient applications, Second Edition

eBook
€20.98 €29.99
Print
€25.99 €37.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon AI Assistant (beta) to help accelerate your learning
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

C# Data Structures and Algorithms - Second Edition

Data Types

Welcome to the first chapter in which you’ll start your amazing adventure with data structures and algorithms in the context of the C# programming language. First, we’ll provide a short introduction to this language. You will get to know how broad its possibilities are, in how many scenarios you can apply this language, as well as some basic constructions that you can use. This isn’t a C# course, so we won't be presenting various features one by one, and only a brief description will be provided.

The remaining part of this chapter is dedicated to data types, both built-in and user-defined, which you can use in your applications. First, you will learn what the difference is between value and reference types. Then, you will go through various available data types, starting with value types. Here, we will cover integral numeric types, floating-point numeric types, Boolean types, Unicode characters, constants, enumerations, value tuples, struct types...

C# as a programming language

As a developer, you have probably heard about many programming languages, including C#, Java, C++, C, PHP, and Ruby. In all of them, you can use various data structures, as well as implement algorithms, to solve both basic and complex problems. However, each language has a specificity that’s visible while implementing data structures and accompanying algorithms. As mentioned previously, this book only focuses on the C# programming language. This is also the main topic of this section.

The C# language, pronounced C sharp, is a modern, general-purpose, strongly typed, and object-oriented programming language that can be used while developing a wide range of applications, such as web, mobile, desktop, distributed, and embedded solutions, as well as even games! It cooperates with various additional technologies and platforms, including ASP.NET Core, XAML, and Unity. Therefore, when you learn the C# language, as well as get to know more about data...

.NET-based console applications

To keep things simple, while reading this book, you will create many console-based applications, but the data structures and algorithms could be used in other kinds of solutions as well. The console-based applications will be created in Microsoft Visual Studio 2022 Community. This integrated development environment (IDE) is a comprehensive solution for developing various kinds of projects and is equipped with many great features that simplify the development and testing of your applications.

Just after launching the IDE, we can proceed by creating a new project. To create one, follow these steps:

  1. Click on File | New | Project in the main menu.
  2. Choose Console App on the right in the Create a new project window.
  3. Type the name of the project (Project name), select a location for the files (Location), and enter the name of the solution (Solution name). Then, press Next.
  4. In the Additional information window, set the framework version...

Division of data types

While developing applications in the C# language, you could use various data types, which are divided into two main groups, namely value types and reference types. The difference between them is quite simple – a variable of a value type directly contains data, while a variable of a reference type just stores a reference to data, which is located somewhere else.

Here’s an illustration of this:

Figure 1.1 – The difference between value and reference types

Figure 1.1 – The difference between value and reference types

As you can see, a variable of a value type (shown as A) stores its actual value directly in the stack memory, while a variable of a reference type only stores a reference here. The actual value is located in the heap memory. Therefore, it is possible to have two or more variables of a reference type that reference the same value, as indicated by the C and D boxes in the preceding figure.

Be careful – it is a simplification!

Please remember that...

Value types

To give you a better understanding of data types, let’s start by analyzing the first group, namely value types. They are further divided into the following categories:

  • Structs encapsulating data and functionalities, which are divided into the following categories:
    • Built-in value types, also referred to as simple types. These are divided into:
      • Integral numeric types
      • Floating-point numeric types
      • Boolean values
      • Unicode UTF-16 characters
    • Value tuples
    • User-defined struct types
  • Constants
  • Enumerations

All of these groups will be described in this section, starting with the simple types.

Integral numbers

The first group of built-in value types are the integral numeric types, which allow you to store various integer values. Similar to other simple types, they can be used either as keywords or as types from the System namespace. Such types differ by the number of bytes used and whether signed or unsigned integral values are represented by them.

Imagine...

Reference types

The second main group of types is reference types. As a quick reminder, a variable of a reference type does not directly contain data because it just stores a reference to data, which is located somewhere else. In this group, you can find four built-in types, namely object, string, delegate, and dynamic. Moreover, you can declare classes, records, and interfaces. Nullable reference types exist as well. All of these types will be described in this section. Let’s get started!

Objects

The Object class (the object alias) is declared in the System namespace and performs an important role while developing applications in C#. Why? Because all other types in the unified type system of C# inherit directly or indirectly from Object. This means that built-in value types, built-in reference types, as well as user-defined value types and user-defined reference types, are derived from the Object class.

Imagine an object

If you want to understand the object type...

Summary

This was only the first chapter of this book, but it contained quite a lot of information that will be useful while you’re reading the remaining ones. First, the C# programming language was briefly presented with a focus on showing various data types, both value and reference ones. You learned the difference between them and why understanding this difference is so important while developing applications.

Next, you saw various value types, including the built-in ones, such as integral numeric types, floating-point numeric types, Boolean type, and Unicode characters. Then, you learned about constants, enumerations, value tuples, user-defined struct types, and nullable value types. All of these were equipped with detailed descriptions, as well as some code examples to make understanding easier and faster.

Finally, you learned about the second group of types, namely reference types. Here, you saw the object and string types, classes, records, interfaces, as well as...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Master lists, stacks, queues, dictionaries, sets, and trees, among other data structures
  • Delve into effective design and implementation techniques to meet your software requirements
  • Visualize data structures and algorithms through illustrations for a clearer understanding of their analysis
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Building your own applications is exciting but challenging, especially when tackling complex problems tied to advanced data structures and algorithms. This endeavor demands profound knowledge of the programming language as well as data structures and algorithms. C# Data Structures and Algorithms, armed with critical knowledge from an entrepreneur, author, industry expert, and seasoned developer with significant international experience, offers just that to C# developers. Starting with an introduction to algorithms, this book gradually immerses you in the world of arrays, lists, stacks, queues, dictionaries, and sets. Real-world examples, enriched with code snippets and illustrations, provide a practical understanding of these concepts. You’ll also learn how to sort arrays using various algorithms, setting a solid foundation for your programming expertise. As you progress, you’ll venture into more complex data structures – trees and graphs – and discover algorithms for tasks such as determining the shortest path in a graph before advancing to see various algorithms in action, such as solving Sudoku. By the end of this book, you’ll be able to use the C# language to build algorithmic components that are not only easy to understand and debug but also seamlessly applicable in various apps, spanning web and mobile platforms.

What you will learn

  • Understand the fundamentals of algorithms and their classification
  • Store data using arrays and lists, and explore various ways to sort arrays
  • Build enhanced applications with stacks, queues, hashtables, dictionaries, and sets
  • Create efficient applications with tree-related algorithms, such as for searching in a binary search tree
  • Boost solution efficiency with graphs, including finding the shortest path in the graph
  • Implement algorithms solving Tower of Hanoi and Sudoku games, generating fractals, and even guessing the title of this book

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 29, 2024
Length 372 pages
Edition : 2nd Edition
Language : English
ISBN-13 : 9781803248271
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon AI Assistant (beta) to help accelerate your learning
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Feb 29, 2024
Length 372 pages
Edition : 2nd Edition
Language : English
ISBN-13 : 9781803248271
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Table of Contents

13 Chapters
Preface Chevron down icon Chevron up icon
1. Chapter 1: Data Types Chevron down icon Chevron up icon
2. Chapter 2: Introduction to Algorithms Chevron down icon Chevron up icon
3. Chapter 3: Arrays and Sorting Chevron down icon Chevron up icon
4. Chapter 4: Variants of Lists Chevron down icon Chevron up icon
5. Chapter 5: Stacks and Queues Chevron down icon Chevron up icon
6. Chapter 6: Dictionaries and Sets Chevron down icon Chevron up icon
7. Chapter 7: Variants of Trees Chevron down icon Chevron up icon
8. Chapter 8: Exploring Graphs Chevron down icon Chevron up icon
9. Chapter 9: See in Action Chevron down icon Chevron up icon
10. Chapter 10: Conclusion Chevron down icon Chevron up icon
11. Index Chevron down icon Chevron up icon
12. Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
CAMILO REYES Jun 20, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Code samples were very solid, everything compiles with on warnings on net8.0. The ideas in the book were welcomed and I can see myself applying some of these techniques in a real project.
Feefo Verified review Feefo image
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.