This document provides an overview of algorithms and data structures including binary search, recursion, arrays, linked lists, selection sort, and Big O notation. It explains binary search and how it is faster than simple linear search, taking logarithmic time rather than linear time. It also discusses recursion and how recursive functions require a base case to avoid infinite loops. Additionally, it compares arrays and linked lists, explaining when each is better to use, such as arrays enabling random access and linked lists facilitating efficient inserts and deletes. Selection sort is demonstrated as an O(n^2) sorting algorithm. Overall, the document serves as an introduction to fundamental algorithms and computer science concepts.
Project Risk Management Grading Guide
Resources:
· Baltzan, P., and Phillips, A. (2015). Business Driven Information Systems (5th ed).
· Week 5 articles
· It is recommended students search the Internet for a Project Risk Management Plan template.
Scenario: You are an entrepreneur in the process of researching a business development idea. As you create a high-level Information Technology (IT) strategy for your new enterprise, it is important to address risks to IT. A Project Risk Management Plan will guide the process of identifying enterprise risks and the appropriate steps to mitigate and manage the risks. The Data Collection Plan is intended to describe a high-level process for applying enterprise resources in identifying, analyzing, and mitigating IT risks. The Risk Management Plan is a working document, which is expected to change over time as new project details emerge.
Create a high-level Project Risk Management Plan for your project in a minimum of 1,050 words which includes the following information:
· A description of the enterprise IT risks
· An assessment of the enterprise exposure to each risk
· A summary of the highest priority risks
· High-level procedures to mitigate and manage the most likely risks
· High-level procedures to address business resumption and disaster recovery
Cite a minimum of 3 peer-reviewed references from the University of Phoenix Library.
Format consistent with APA guidelines.
Submit your assignment.
chapter 6
The Acquisition of Memories and
the Working-Memory System
Acquisition, Storage, and Retrieval
How does new information-whether it's a friend's phone number or a fact you hope to memorize for the bio exam-become established in memory? Are there ways to learn that are particularly effective? Then, once information is in storage, how do you locate it and "reactivate" it later? And why does search through memory sometimes fail-so that, for example, you forget the name of that great restaurant downtown (but then remember the name when you're midway through a mediocre dinner someplace else)?
In tackling these questions, there's a logical way to organize our inquiry. Before there can be a some new information. Therefore, acquisition-the process memory, you need to gain, or "acquire," of gaining information and placing it into memory-should be our first topic. Then, once you've acquired this information, you need to hold it in memory until the information is needed. We refer to this as the storage phase. Finally, you remember. In other words, you somehow locate the information in the vast warehouse that is memory and you bring it into active use; this is called retrieval.
This organization seems logical; it fits, for example, with the way most "electronic memories" (e.g., computers) work. Information ("input") is provided to a computer (the acquisition phase). The information then resides in some dormant form, generally on the hard drive or perhaps in the cloud (the storage phase). Finally, th ...
Unstructure: Smashing the Boundaries of Data (SxSWi 2014)Ian Varley
When it comes to thinking about data, most software designers are stuck in a rigid, 2-dimensional mindset: "rows and columns." A shame, because breaking free from this "tyranny of the table" can bring our software to new heights: intuitive user experiences, fast development iterations, and cohesive apps.
In this workshop, we'll cover a few concepts that bring data design out of the 1970s, like: sparse representation, emergent schema, ultra-structure, prototype-driven design, graph theory, traversing the time dimension, and more. We'll run the gamut of philosophical approaches to understanding what is important in your mental (and software) model, and how to transcend your two-dimensional picture of data, and trade it in for an N-dimensional one.
Working hands-on with a simple "mock company" and its new killer app, you'll learn:
* The basic concepts of data design: entities, relationships, attributes, and types (along with a few better ways to notate them)
* How to experiment with creating these data structures in a couple existing cloud-based frameworks (e.g. google apps engine, force.com, heroku, etc.).
* How emergent techniques like schema-on-read and ultra-structure can simplify modeling (or, sometimes, complicate it)
* How statistical techniques from the data mining world can loosen our insistence on rigid models
* Why the time dimension is important (in data as well as schema)
There's an old joke that goes, “The two hardest things in programming are cache invalidation, naming things, and off-by-one errors.” In this talk, we'll discuss the subtle art of naming things – a practice we do every day but rarely talk about.
Avoid adding a new library to the projectPVS-Studio
Suppose, you need to implement an X functionality in your project. Theorists of software development will say that you have to take the already existing library Y, and use it to implement the things you need. Suppose, you need to implement an X functionality in your project. Theorists of software development will say that you have to take the already existing library Y, and use it to implement the things you need. In fact, it is a classic approach in the software development - reusing your own or others' previously created libraries (third-party libraries). And most of the programmers go this way.
Describes techniques for injecting "Semantic Intelligence" into search applications. Focuses on Apache Solr and Lucidworks Fusion, but these techniques are generally applicable to any search engine because all of them use the same basic mechanism - inverted token mapping at their 'core'.
There's an old joke that goes, “The two hardest things in programming are cache invalidation, naming things, and off-by-one errors.” In this talk, we'll discuss the subtle art of naming things – a practice we do every day but rarely talk about.
1 CS110 - Introduction to Computers and Applications .docxhoney725342
1
CS110 - Introduction to Computers and Applications
Spring 2016 - Scratch Project #5
Due Date: Friday, April 15th , at 11:00 P.M.
Accept Until Date: Friday, April 22
nd
, 11:00 P.M.
Evaluation: 20 points
Submit to Sakai: Scratch program (.sb file)
Related Materials: Resources posted in Sakai → Lecture Topics → Scratch
Scratch Website: http://scratch.mit.edu/
TA Lab Support Schedule (in Sakai Resources Folder)
Questions? Meet with your TA during office hours; Visit a campus computing center
during CS110 Lab Support Hours
Background
In this assignment you will use the build another Scratch program. In this program you will be
working more with variables, loops, random numbers and lists.
_____________________________________________________________________
Goal
This assignment will require you to create a Scratch program using lists. A list allows us to associate one
variable name with multiple items or values. Scratch provides us with the following instructions and
references.
add item to end of list
Delete item from list (in this case,
the first item)
adds item in a specified position in
list (in this case, position 1)
replaces item in list with some
other value (in this case, item 1
replaced with thing).
refers to an item in the list (in this
case, item 1)
refers to the number of items in
the list.
Deletes one (or all) elements from
the list
Deletes the element in position position
http://scratch.mit.edu/
2
from the list
Example code using lists:
Adding items to a list
Open Scratch. Go to Variable block. Click on Make A List. Name the list food.
The list is currently empty.
Click on the + sign and add a food item. Do this at least three times.
Reporting items in a list
Make a new variable named count.
Add the code on the right.
o count will keep track of which item
in the list you are looking at
o repeat loop will execute as many times
as it has items in the list
o the first item I want is item #1 so I change
count by 1. Then I want item #2 so the second
time through the loop I increment count again.
I do this until I've looked at each item.
Hide your food list by un-checking the checkbox next to the list variable, food.
Alternative method for adding items to a list: You can also populate your list by importing
items from a text file. This way is much easier. Use a text editor to create a file named
friends.txt. Add the following to your file, one per line and safe your text file.
Mickey Mouse
Donald Duck
Tom and Jerry
Bugs Bunny
Tweety Bird
Garfield
Speedy Gonzales
Pluto
Bambi
Create a Scratch list and name it friends. Right click on the empty friends list on the stage. Click import
and navigate to friends.txt. Like magic, your list is populated and it has length 9.
Modify your previous code segment:
...
The IT discipline of machine learning has become increasingly important in recent years. It promises to solve types of problems for which normal software development is considered unsuitable or too costly.
I am Joe L. I am a Python Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, University of Chicago, USA. I have been helping students with their homework for the past 8 years. I solve assignments related to Python Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Python Programming Assignments.
1. Think “Relevant ==> Simple ==> Intricate.”
2. Visualize “mastery blocks.”
3. Generate comprehensive examples.
4. Assessment.
5. End with lead to next topic.
Project Risk Management Grading Guide
Resources:
· Baltzan, P., and Phillips, A. (2015). Business Driven Information Systems (5th ed).
· Week 5 articles
· It is recommended students search the Internet for a Project Risk Management Plan template.
Scenario: You are an entrepreneur in the process of researching a business development idea. As you create a high-level Information Technology (IT) strategy for your new enterprise, it is important to address risks to IT. A Project Risk Management Plan will guide the process of identifying enterprise risks and the appropriate steps to mitigate and manage the risks. The Data Collection Plan is intended to describe a high-level process for applying enterprise resources in identifying, analyzing, and mitigating IT risks. The Risk Management Plan is a working document, which is expected to change over time as new project details emerge.
Create a high-level Project Risk Management Plan for your project in a minimum of 1,050 words which includes the following information:
· A description of the enterprise IT risks
· An assessment of the enterprise exposure to each risk
· A summary of the highest priority risks
· High-level procedures to mitigate and manage the most likely risks
· High-level procedures to address business resumption and disaster recovery
Cite a minimum of 3 peer-reviewed references from the University of Phoenix Library.
Format consistent with APA guidelines.
Submit your assignment.
chapter 6
The Acquisition of Memories and
the Working-Memory System
Acquisition, Storage, and Retrieval
How does new information-whether it's a friend's phone number or a fact you hope to memorize for the bio exam-become established in memory? Are there ways to learn that are particularly effective? Then, once information is in storage, how do you locate it and "reactivate" it later? And why does search through memory sometimes fail-so that, for example, you forget the name of that great restaurant downtown (but then remember the name when you're midway through a mediocre dinner someplace else)?
In tackling these questions, there's a logical way to organize our inquiry. Before there can be a some new information. Therefore, acquisition-the process memory, you need to gain, or "acquire," of gaining information and placing it into memory-should be our first topic. Then, once you've acquired this information, you need to hold it in memory until the information is needed. We refer to this as the storage phase. Finally, you remember. In other words, you somehow locate the information in the vast warehouse that is memory and you bring it into active use; this is called retrieval.
This organization seems logical; it fits, for example, with the way most "electronic memories" (e.g., computers) work. Information ("input") is provided to a computer (the acquisition phase). The information then resides in some dormant form, generally on the hard drive or perhaps in the cloud (the storage phase). Finally, th ...
Unstructure: Smashing the Boundaries of Data (SxSWi 2014)Ian Varley
When it comes to thinking about data, most software designers are stuck in a rigid, 2-dimensional mindset: "rows and columns." A shame, because breaking free from this "tyranny of the table" can bring our software to new heights: intuitive user experiences, fast development iterations, and cohesive apps.
In this workshop, we'll cover a few concepts that bring data design out of the 1970s, like: sparse representation, emergent schema, ultra-structure, prototype-driven design, graph theory, traversing the time dimension, and more. We'll run the gamut of philosophical approaches to understanding what is important in your mental (and software) model, and how to transcend your two-dimensional picture of data, and trade it in for an N-dimensional one.
Working hands-on with a simple "mock company" and its new killer app, you'll learn:
* The basic concepts of data design: entities, relationships, attributes, and types (along with a few better ways to notate them)
* How to experiment with creating these data structures in a couple existing cloud-based frameworks (e.g. google apps engine, force.com, heroku, etc.).
* How emergent techniques like schema-on-read and ultra-structure can simplify modeling (or, sometimes, complicate it)
* How statistical techniques from the data mining world can loosen our insistence on rigid models
* Why the time dimension is important (in data as well as schema)
There's an old joke that goes, “The two hardest things in programming are cache invalidation, naming things, and off-by-one errors.” In this talk, we'll discuss the subtle art of naming things – a practice we do every day but rarely talk about.
Avoid adding a new library to the projectPVS-Studio
Suppose, you need to implement an X functionality in your project. Theorists of software development will say that you have to take the already existing library Y, and use it to implement the things you need. Suppose, you need to implement an X functionality in your project. Theorists of software development will say that you have to take the already existing library Y, and use it to implement the things you need. In fact, it is a classic approach in the software development - reusing your own or others' previously created libraries (third-party libraries). And most of the programmers go this way.
Describes techniques for injecting "Semantic Intelligence" into search applications. Focuses on Apache Solr and Lucidworks Fusion, but these techniques are generally applicable to any search engine because all of them use the same basic mechanism - inverted token mapping at their 'core'.
There's an old joke that goes, “The two hardest things in programming are cache invalidation, naming things, and off-by-one errors.” In this talk, we'll discuss the subtle art of naming things – a practice we do every day but rarely talk about.
1 CS110 - Introduction to Computers and Applications .docxhoney725342
1
CS110 - Introduction to Computers and Applications
Spring 2016 - Scratch Project #5
Due Date: Friday, April 15th , at 11:00 P.M.
Accept Until Date: Friday, April 22
nd
, 11:00 P.M.
Evaluation: 20 points
Submit to Sakai: Scratch program (.sb file)
Related Materials: Resources posted in Sakai → Lecture Topics → Scratch
Scratch Website: http://scratch.mit.edu/
TA Lab Support Schedule (in Sakai Resources Folder)
Questions? Meet with your TA during office hours; Visit a campus computing center
during CS110 Lab Support Hours
Background
In this assignment you will use the build another Scratch program. In this program you will be
working more with variables, loops, random numbers and lists.
_____________________________________________________________________
Goal
This assignment will require you to create a Scratch program using lists. A list allows us to associate one
variable name with multiple items or values. Scratch provides us with the following instructions and
references.
add item to end of list
Delete item from list (in this case,
the first item)
adds item in a specified position in
list (in this case, position 1)
replaces item in list with some
other value (in this case, item 1
replaced with thing).
refers to an item in the list (in this
case, item 1)
refers to the number of items in
the list.
Deletes one (or all) elements from
the list
Deletes the element in position position
http://scratch.mit.edu/
2
from the list
Example code using lists:
Adding items to a list
Open Scratch. Go to Variable block. Click on Make A List. Name the list food.
The list is currently empty.
Click on the + sign and add a food item. Do this at least three times.
Reporting items in a list
Make a new variable named count.
Add the code on the right.
o count will keep track of which item
in the list you are looking at
o repeat loop will execute as many times
as it has items in the list
o the first item I want is item #1 so I change
count by 1. Then I want item #2 so the second
time through the loop I increment count again.
I do this until I've looked at each item.
Hide your food list by un-checking the checkbox next to the list variable, food.
Alternative method for adding items to a list: You can also populate your list by importing
items from a text file. This way is much easier. Use a text editor to create a file named
friends.txt. Add the following to your file, one per line and safe your text file.
Mickey Mouse
Donald Duck
Tom and Jerry
Bugs Bunny
Tweety Bird
Garfield
Speedy Gonzales
Pluto
Bambi
Create a Scratch list and name it friends. Right click on the empty friends list on the stage. Click import
and navigate to friends.txt. Like magic, your list is populated and it has length 9.
Modify your previous code segment:
...
The IT discipline of machine learning has become increasingly important in recent years. It promises to solve types of problems for which normal software development is considered unsuitable or too costly.
I am Joe L. I am a Python Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, University of Chicago, USA. I have been helping students with their homework for the past 8 years. I solve assignments related to Python Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Python Programming Assignments.
1. Think “Relevant ==> Simple ==> Intricate.”
2. Visualize “mastery blocks.”
3. Generate comprehensive examples.
4. Assessment.
5. End with lead to next topic.
In his public lecture, Christian Timmerer provides insights into the fascinating history of video streaming, starting from its humble beginnings before YouTube to the groundbreaking technologies that now dominate platforms like Netflix and ORF ON. Timmerer also presents provocative contributions of his own that have significantly influenced the industry. He concludes by looking at future challenges and invites the audience to join in a discussion.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Climate Impact of Software Testing at Nordic Testing DaysKari Kakkonen
My slides at Nordic Testing Days 6.6.2024
Climate impact / sustainability of software testing discussed on the talk. ICT and testing must carry their part of global responsibility to help with the climat warming. We can minimize the carbon footprint but we can also have a carbon handprint, a positive impact on the climate. Quality characteristics can be added with sustainability, and then measured continuously. Test environments can be used less, and in smaller scale and on demand. Test techniques can be used in optimizing or minimizing number of tests. Test automation can be used to speed up testing.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Removing Uninteresting Bytes in Software FuzzingAftab Hussain
Imagine a world where software fuzzing, the process of mutating bytes in test seeds to uncover hidden and erroneous program behaviors, becomes faster and more effective. A lot depends on the initial seeds, which can significantly dictate the trajectory of a fuzzing campaign, particularly in terms of how long it takes to uncover interesting behaviour in your code. We introduce DIAR, a technique designed to speedup fuzzing campaigns by pinpointing and eliminating those uninteresting bytes in the seeds. Picture this: instead of wasting valuable resources on meaningless mutations in large, bloated seeds, DIAR removes the unnecessary bytes, streamlining the entire process.
In this work, we equipped AFL, a popular fuzzer, with DIAR and examined two critical Linux libraries -- Libxml's xmllint, a tool for parsing xml documents, and Binutil's readelf, an essential debugging and security analysis command-line tool used to display detailed information about ELF (Executable and Linkable Format). Our preliminary results show that AFL+DIAR does not only discover new paths more quickly but also achieves higher coverage overall. This work thus showcases how starting with lean and optimized seeds can lead to faster, more comprehensive fuzzing campaigns -- and DIAR helps you find such seeds.
- These are slides of the talk given at IEEE International Conference on Software Testing Verification and Validation Workshop, ICSTW 2022.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
Enhancing Performance with Globus and the Science DMZGlobus
ESnet has led the way in helping national facilities—and many other institutions in the research community—configure Science DMZs and troubleshoot network issues to maximize data transfer performance. In this talk we will present a summary of approaches and tips for getting the most out of your network infrastructure using Globus Connect Server.
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
6. Binary search
Suppose you’re searching for a word in a Dictionary. The word starts with K. You could
start at the beginning and keep flipping pages until you get to the Ks. But you’re more likely
to start at a page in the middle, because you know the Ks are going to be near the middle
of the Dictionary.
8. Binary search
Now suppose you log on to Facebook. When you do, Facebook has to verify that you have an
account on the site. So, it needs to search for your username in its database. Suppose your
username is kareem. Facebook could start from the As and search for your name—but it
makes more sense for it to begin somewhere in the middle. This is a search problem. And all
these cases use the same algorithm to solve the problem: binary search.
9. Binary search
Binary search is an algorithm; its input is a sorted list of elements (I’ll explain later why it
needs to be sorted). If an element you’re looking for is in that list, binary search returns the
position where it’s located. Otherwise, binary search returns null.
12. Binary search
Suppose you’re looking for a word in the dictionary. The dictionary has 240,000 words. In the
worst case, how many steps do you think each search will take?
Simple search could take 240,000 steps if the word you’re looking for is the very last one in
the book. With each step of binary search, you cut the number of words in half until you’re
left with only one word.
13. Binary search
So binary search will take 18 steps—a big difference! In general, for any list of n, binary search
will take log2 n steps to run in the worst case, whereas simple search will take n steps.
15. Binary search
For a list of 1,024 elements, log 1,024 = 10, because 210
== 1,024. So for a list of 1,024
numbers, you’d have to check 10 numbers at most.
17. Binary search-Running time
Generally you want to choose the most efficient algorithm— whether you’re trying to
optimize for time or space.
Back to binary search. How much time do you save by using it? Well, the first approach
was to check each number, one by one. If this is a list of 100 numbers, it takes up to 100
guesses. If it’s a list of 4 billion numbers, it takes up to 4 billion guesses. So the maximum
number of guesses is the same as the size of the list. This is called linear time. Binary
search is different. If the list is 100 items long, it takes at most 7 guesses. If the list is 4
billion items, it takes at most 32 guesses. Powerful, eh? Binary search runs in logarithmic
time (or log time, as the natives call it). Here’s a table summarizing our findings today
19. Binary search-Big O notation
Big O notation is special notation that tells you how fast an algorithm is.
Big O establishes a worst-case run time
20. Visualizing different Big O run times
Here’s a practical example you can follow at home with a few pieces of paper and a pencil.
Suppose you have to draw a grid of 16 boxes.
Algorithm 1 One way to do it is to draw 16 boxes, one at a time. Remember, Big O
notation counts the number of operations. In this example, drawing one box is one
operation. You have to draw 16 boxes. How many operations will it take, drawing
one box at a time?
22. Visualizing different Big O run times
You can “draw” twice as many boxes with every fold, so you can draw 16 boxes in 4 steps.
What’s the running time for this algorithm? Come up with running times for both
algorithms before moving on. Answers: Algorithm 1 takes O(n) time, and algorithm 2 takes
O(log n) time.
23. Some common Big O run times
Here are five Big O run times that you’ll encounter a lot, sorted from fastest to slowest:
O(log n), also known as log time. Example: Binary search.
O(n), also known as linear time. Example: Simple search.
O(n * log n). Example: A fast sorting algorithm, like quicksort .
O(n2 ). Example: A slow sorting algorithm, like selection sort .
O(n!). Example: A really slow algorithm, like the traveling salesperson.
24. Visualizing different Big O run times
Algorithm speed isn’t measured in seconds, but in growth of
the number of operations.
Instead, we talk about how quickly the run time of an
algorithm increases as the size of the input increases.
25. The traveling salesperson
You might have read that last section and thought, “There’s no way I’ll ever run
into an algorithm that takes O(n!) time.” Well, let me try to prove you wrong!
Here’s an example of an algorithm with a really bad running time. This is a
famous problem in computer science, because its growth is appalling and some
very smart people think it can’t be improved. It’s called the traveling salesperson
problem
26. The traveling salesperson
● You have a salesperson.
● The salesperson has to go to five cities.
● This salesperson, whom I’ll call Opus, wants to hit all five cities while traveling the minimum
distance. Here’s one way to do that: look at every possible order in which he could travel to the
cities.
27. The traveling salesperson
● He adds up the total distance and then picks the path with the lowest distance. There are 120
permutations with 5 cities, so it will take 120 operations to solve the problem for 5 cities. For 6
cities, it will take 720 operations (there are 720 permutations). For 7 cities, it will take 5,040
operations!
28. The traveling salesperson
In general, for n items, it will take n! (n factorial) operations to compute the result. So this is O(n!) time,
or factorial time. It takes a lot of operations for everything except the smallest numbers. Once you’re
dealing with 100+ cities, it’s impossible to calculate the answer in time—the Sun will collapse first. This is
a terrible algorithm! Opus should use a different one, right? But he can’t. This is one of the unsolved
problems in computer science. There’s no fast known algorithm for it, and smart people think it’s
impossible to have a smart algorithm for this problem. The best we can do is come up with an
approximate solution; see chapter 10 for more.
29. Selection Sort-How Memory Works
Imagine you go to a show and need to check your things. A chest of drawers is available.
Each drawer can hold one element. You want to store two things, so you ask for two drawers.
30. Selection Sort-How Memory Works
Imagine you go to a show and need to check your things. A chest of drawers is available.
Each drawer can hold one element. You want to store two things, so you ask for two drawers.
32. Selection Sort-How Memory Works
And you’re ready for the show! This is basically how your computer’s memory works. Your
computer looks like a giant set of drawers, and each drawer has an address.
fe0ffeeb is the address of a slot in memory. / Each time you want to store an item in memory, you
ask the computer for some space, and it gives you an address where you can store your item. If you
want to store multiple items, there are two basic ways to do so: arrays and lists. I’ll talk about arrays
and lists next, as well as the pros and cons of each. There isn’t one right way to store items for
every use case, so it’s important to know the differences.
33. Arrays and linked lists
Sometimes you need to store a list of elements in memory. Suppose you’re writing an app to
manage your todos. You’ll want to store the todos as a list in memory. Should you use an array, or a
linked list? Let’s store the todos in an array first, because it’s easier to grasp. Using an array means
all your tasks are stored contiguously (right next to each other) in memory.
34. Arrays and linked lists
Now suppose you want to add a fourth task. But the next drawer is taken up by someone else’s
stuff!
It’s like going to a movie with your friends and finding a place to sit— but another friend joins you,
and there’s no place for them. You have to move to a new spot where you all fit. In this case, you
need to ask your computer for a different chunk of memory that can fit four tasks. Then you need
to move all your tasks there.
35. Arrays and linked lists
If another friend comes by, you’re out of room again—and you all have to move a second time!
What a pain. Similarly, adding new items to an array can be a big pain. If you’re out of space and
need to move to a new spot in memory every time, adding a new item will be really slow. One easy
fix is to “hold seats”: even if you have only 3 items in your task list, you can ask the computer for 10
slots, just in case. Then you can add 10 items to your task list without having to move.
36. Arrays and linked lists
This is a good workaround, but you should be aware of a couple of downsides:
You may not need the extra slots that you asked for, and then that memory will
be wasted. You aren’t using it, but no one else can use it either.
You may add more than 10 items to your task list and have to move anyway. So
it’s a good workaround, but it’s not a perfect solution. Linked lists solve this
problem of adding items.
37. Linked lists
With linked lists, your items can be anywhere in memory.
Each item stores the address of the next item in the list. A bunch of random memory addresses are
linked together.
38. Which are used more: arrays or lists?
Obviously, it depends on the use case. But arrays see a lot of use because they allow random
access. There are two different types of access: random access and sequential access. Sequential
access means reading the elements one by one, starting at the first element. Linked lists can only
do sequential access. If you want to read the 10th element of a linked list, you have to read the first
9 elements and follow the links to the 10th element. Random access means you can jump directly
to the 10th element. You’ll frequently hear me say that arrays are faster at reads. This is because
they provide random access. A lot of use cases require random access, so arrays are used a lot.
Arrays and lists are used to implement other data structures, too
39. EXERCISES
Would you use an array or a linked list to implement this queue? (Hint: Linked lists are good for
inserts/deletes, and arrays are good for random access. Which one are you going to be doing here?)
Let’s run a thought experiment. Suppose Facebook keeps a list of usernames. When someone tries
to log in to Facebook, a search is done for their username. If their name is in the list of usernames,
they can log in. People log in to Facebook pretty often, so there are a lot of searches through this
list of usernames. Suppose Facebook uses binary search to search the list. Binary search needs
random access—you need to be able to get to the middle of the list of usernames instantly.
Knowing this, would you implement the list as an array or a linked list?
40. Selection Sort
Suppose you have a bunch of music on your computer. For each artist, you have a play count.
You want to sort this list from most to least played, so that you can rank your favorite artists. How
can you do it?
41. Selection Sort
One way is to go through the list and find the most-played artist. Add that artist to a new list.
43. Selection Sort
Let’s put on our computer science hats and see how long this will take to run. Remember that O(n)
time means you touch every element in a list once. For example, running simple search over the list
of artists means looking at each artist once
44. Selection Sort
To find the artist with the highest play count, you have to check each item in the list. This takes O(n)
time, as you just saw. So you have an operation that takes O(n) time, and you have to do that n
times:
This takes O(n × n) time or O(n2 ) time.
46. Recursion
● Suppose you’re digging through your grandma’s attic and come across a mysterious locked
suitcase.
● Grandma tells you that the key for the suitcase is probably in this other box.
● This box contains more boxes, with more boxes inside those boxes. The key is in a box somewhere.
What’s your algorithm to search for the key? Think of an algorithm before you read on.
47. Recursion
1. Make a pile of boxes to look through.
2. Grab a box, and look through it.
3. If you find a box, add it to the pile to look through later.
4. If you find a key, you’re done! 5.
5. Repeat.
48. Recursion
Recursion is where a function calls itself. Here’s the second way in
pseudocode:
Recursion is used when it makes the solution clearer. There’s no performance
benefit to using recursion; in fact, loops are sometimes better for
performance. I like this quote by Leigh Caldwell on Stack Overflow: “Loops may
achieve a performance gain for your program. Recursion may achieve a
performance gain for your programmer. Choose which is more important in
your situation!”1
50. Recursion
Write out this code and run it. You’ll notice a problem: this function will run
forever!
51. Recursion
When you write a recursive function, you have to tell it when to stop recursing.
That’s why every recursive function has two parts: the base case, and the
recursive case. The recursive case is when the function calls itself. The base
case is when the function doesn’t call itself again … so it doesn’t go into an
infinite loop.