Swift Data Structure and Algorithms - Erik Azar - E-Book

Swift Data Structure and Algorithms E-Book

Erik Azar

0,0
33,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Master the most common algorithms and data structures, and learn how to implement them efficiently using the most up-to-date features of Swift 3

About This Book

  • Develop a deep understanding of the collections in the Swift Standard Library with this step-by-step guide
  • Develop native Swift data structures and algorithms for use in mobile, desktop, and server-based applications
  • Learn about performance efficiency between different data structures and algorithms

Who This Book Is For

This book is for developers who want to learn how to implement and use common data structures and algorithms natively in Swift. Whether you are a self-taught developer without a formal technical background or you have a degree in Computer Science, this book will provide with the knowledge you need to develop advanced data structures and algorithms in Swift using the latest language features.

What You Will Learn

  • Get to know about the basic data structures and how to use the Swift REPL
  • Use the Swift Standard Library collections bridging to Objective-C collections, and find out about protocol-oriented programming
  • Find out about Swift generators and sequences, and see how to use them to implement advanced data structures such as Stack, StackList, Queue, and LinkedList
  • Implement sorting algorithms such as Insertion Sort, Merge Sort, and Quick Sort and understand the performance trade-offs between them
  • See how to implement various binary trees, B-Tree, and Splay Trees
  • Perform advanced searching methods using Red-Black trees, AVL trees, and Trie trees, and take a look at several substring search algorithms
  • Get to know about the data structures used in graphs and how to implement graphs such as depth-first search, breadth-first search, directed graphs, spanning tree, and shortest path
  • Explore algorithm efficiency and see how to measure it

In Detail

Apple's Swift language has expressive features that are familiar to those working with modern functional languages, but also provides backward support for Objective-C and Apple's legacy frameworks. These features are attracting many new developers to start creating applications for OS X and iOS using Swift.

Designing an application to scale while processing large amounts of data or provide fast and efficient searching can be complex, especially running on mobile devices with limited memory and bandwidth. Learning about best practices and knowing how to select the best data structure and algorithm in Swift is crucial to the success of your application and will help ensure your application is a success. That's what this book will teach you.

Starting at the beginning, this book will cover the basic data structures and Swift types, and introduce asymptotic analysis. You'll learn about the standard library collections and bridging between Swift and Objective-C collections. You will see how to implement advanced data structures, sort algorithms, work with trees, advanced searching methods, use graphs, and performance and algorithm efficiency. You'll also see how to choose the perfect algorithm for your problem.

Style and approach

This easy-to-follow yet comprehensive guide can either be read from beginning to end, or depending on your current knowledge level, you can jump to the specific chapter that interests you. Each chapter topic starts with an introduction to the topic and algorithm before moving on to the hands-on implementation and analysis.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 319

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Swift Data Structure and Algorithms

Swift Data Structure and Algorithms

Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: November 2016

Production reference: 1111116

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham 

B3 2PB, UK.

ISBN 978-1-78588-450-4

www.packtpub.com

Credits

Authors

Erik Azar

Mario Eguiluz Alebicto

Copy Editor

Safis Editing

Reviewer

Doug Sparling

Project Coordinator

Ritika Manoj

Commissioning Editor

Kunal Parikh

Proofreader

Safis Editing

Acquisition Editor

Shweta Pant

Indexer

Rekha Nair

Content Development Editor

Divij Kotian

Graphics

Jason Monteiro

Technical Editor

Prashant Mishra

Production Coordinator

Shraddha Falebhai

About the Authors

Erik Azar is a computer scientist with over 20 years of professional experience of architecting and developing scalable, high-performance desktop, web, and mobile applications in the areas of network engineering, system management and security, and enterprise business services, having worked in diverse positions in companies ranging from startups to Fortune 500 companies. He has been developing applications on macOS and iOS since attending his first WWDC in 2007, when Apple announced the initial iPhone.

Erik is an expert developer and architect for Availity, LLC, based in Jacksonville, Florida, where he works with teams to deliver software solutions in the healthcare industry.

Erik has performed technical reviews for several Packt Publishing books on Java RESTful APIs and security, enjoying the experience so much he decided to write his first book for Packt Publishing.

When Erik is not being a geek, he enjoys spending time with his wife, Rebecca, and his three kids, and getting out to ride his motorcycle up and down the Florida coast.

I want to thank my children, Patrick, Kyra, and Cassandra; my parents; and especially my wife, Rebecca, for their support and encouragement while writing this book. I’d also like to thank Michael Privat and Robert Warner for their support, encouragement, and guidance on this project as well. Lastly, I want to thank Mario, Divij, Prashant, and our technical reviewers for all of their hard work and guidance working on this book. It’s been a great experience working with all of you.

Mario Eguiluz Alebicto is a software engineer with over 10 years of experience in development. He started developing software with Java, switched later to Objective-C when the first iPhone delighted the world, and now he is also working with Swift. He founded his own startup to develop mobile applications for small companies and local shops. He has developed apps for different Fortune 500 companies and also for new disrupting startups since 2011. Now, he is working as a contractor in mobile applications, while writing technical and teaching materials whenever possible.

Apart from software development, Mario loves to travel, learn new things, play sports, and has considered himself a hardcore gamer since he was a child.

I want to thank my mother and sister for their love and unconditional support. Borja, you helped me so much when I needed it. Gloria, thanks for keeping me positive beyond my limits. Also want to thank Divij, Erik, and the entire team for their guidance and work on this book. You guys are awesome!

About the Reviewers

Doug Sparling works as a technical architect and software developer for Andrews McMeel Universal, a publishing and syndication company in Kansas City, MO. At AMU, he uses Go for web services, Python for backend services, Ruby on Rails and WordPress for website development, and Objective-C, Swift, and Java for native iOS and Android development. AMU’s sites include www.gocomics.com, www.uexpress.com, www.puzzlesociety.com, and www.dilbert.com.

He also was the co-author of a Perl book, Instant Perl Modules, for McGraw-Hill, and a reviewer for other Packt Publishing books, including jQuery 2.0 Animation Techniques: Beginner’s Guide and WordPress Web Application Development. Doug has also played various roles for Manning Publications as a reviewer, technical development editor, and proofer, working on books such as Go in Action, The Well-Grounded Rubyist 2nd Edition, iOS Development with Swift, and Programming for Musicians and Digital Artists.

www.PacktPub.com

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

This book aims to teach experienced developers how to leverage the latest Swift language features. With Swift, Apple's new programming language for macOS, iOS, watchOS, tvOS, and Linux, you can write software that is fast and helps promote safer coding practices. With Swift and Xcode playgrounds, Apple has made it easy for developers to learn about the best practices and new programming concepts. Apple has open sourced the Swift language, that is, they have made it available on a wide range of platforms now, not just the Apple ecosystem. By doing this, developers are now able to develop server-side code on multiple platforms, in addition to developing code for the traditional line of Apple products.

Today, so many consumers are dependent on their smartphones and Internet access, the effect being the amount of data is growing exponentially, and being able to process, sort, and search that data as quickly as possible is more important than ever. Understanding how data structures and algorithms affect the efficiency of processing huge amounts of data is the key to any successful application or software library.

You will learn about the important Swift features and the most relevant data structures and algorithms, using a hands-on approach with code samples in Xcode Playgrounds for each data structure and algorithm covered in this book. We teach you factors to consider when selecting one type or method over another. You also learn how to measure the performance of your code using asymptotic analysis, a concept commonly used in the software industry in order to choose the best algorithm and data structure for a particular use case.

With knowledge learned in this book, you will have the best tools available to help you develop efficient and scalable software for your applications.

We hope you enjoy reading the book and learning more about some of the advanced Swift features, while also understanding how slight modifications to your existing code can dramatically improve the performance of your applications.

What this book covers 

Chapter 1, Walking Across the Playground, contains an introduction to data structures and algorithms, the Swift REPL, and how to enter Swift statements into it to produce results on the fly.

Chapter 2, Working with Commonly Used Data Structures, covers classes and structures, the implementation details for the array, dictionary, and set collection types, how Swift interoperates with Objective-C and the C system libraries, and protocol-oriented programming introduction.

Chapter 3, Standing on the Shoulders of Giants, covers how to conform to Swift protocols, how to implement a stack and queue structure, and implement several types so you can gain experience for choosing the right type based on the requirements of your application.

Chapter 4, Sorting Algorithms, covers algorithms, sorting algorithms and how to apply them using an array data structure, explore different algorithms that use comparison sorting and look at both simple sorting and divide-and-conquer strategies.

Chapter 5, Seeing the Forest through the Tree, explains the tree data structure, including a definition and its properties, an overview of different types of trees, such as binary trees, binary search trees (BST), B–trees, and splay trees with implementation details.

Chapter 6, Advanced Searching Methods, covers more advanced tree structures: red-black trees, AVL trees, Trie trees (Radix trees) and covers several Substring search algorithms.

Chapter 7, Graph Algorithms, explains graph theory and data structures for graphs, as well as depth-first search, breadth-first search, spanning tree, shortest path, and SwiftGraph.

Chapter 8, Performance and Algorithm Efficiency, shows you algorithm efficiency and how to measure it, Big-O notation, orders of common functions, and evaluating runtime complexity.

Chapter 9, Choosing the Perfect Algorithm, learn how to deal with problems that require algorithms and data structures by creating a high level solution, writing the implementation in Swift, calculating Big-O complexities of our solution to check if the algorithm behaves properly in a real-world situation, measuring and detecting bottlenecks, and modifying the solution to achieve better performance.

What you need for this book 

The basic requirements for this book are as follows:

Xcode, at least v8.1macOS Sierra 10.12 or OS X El Capitan 10.11.5 or later

Who this book is for 

Swift Data Structures and Algorithms is intended for developers who want to learn how to implement and use common data structures and algorithms natively in Swift. Whether you are a self-taught developer without a formal technical background or you have a degree in Computer Science, this book will provide with the knowledge you need to develop advanced data structures and algorithms in Swift using the latest language features. An emphasis is placed on resource usage to ensure the code will run on a range of platforms from mobile to server. A previous background in an object-oriented language is helpful, but not required, as each concept starts with a basic introductory.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important to us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code 

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Swift-Data-Structure-and-Algorithms. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book 

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/SwiftDataStructureandAlgorithms_ColorImages.pdf .

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.

Overview of data structures

The following is a table providing an overview of some of the most common and advanced data structures, along with their advantages and disadvantages:

Table 1.2 – Overview of Data Structures

Data Structure

Advantages

Disadvantages

Array

Very fast access to elements if index is known, fast insertion of new elements.

Fixed size, slow deletion, slow search.

Sorted array

Quicker search over non-sorted arrays.

Fixed size, slow insertion, slow deletion.

Queue

Provides FIFO (First In, First Out) access.

Slow access to other elements.

Stack

Provides LIFO (Last In, First Out).

Slow access to other elements.

List

Quick inserts and deletes.