Introduction, Why are you here?
Read: Ch. 1
(draft)
4/5 MergeSort, Recurrences, Asymptotics Read: Ch. 2.3, 3 (draft) (draft) (draft) (draft) | 4/7 Homework 1 released | 4/10 Asymptotics (for real this time). Solving recurrences and the master theorem. Read: Ch. 4.3-4.5 Dasgupta-Papadimitriou-Vazirani Sec. 2.2: (draft) (draft) (draft) | 4/12 Median and Selection Read: Ch. 9 (draft) (draft) (Note: Slides have been updated since lecture. Now with fewer typos!) | 4/14 Homework 1 due Homework 2 released |
4/17 Quicksort, Probability and Randomized Algorithms Read: Ch. 7, 5 (draft) (draft) | 4/19 Sorting Lower Bounds, Counting Sort Read: Ch. 8.1-2 --> (draft) (draft) | 4/21 Homework 2 due Homework 3 released |
4/24 Binary Search Trees Read: Ch. 12 --> (draft) (draft) | 4/26 Hashing Read: Ch. 11 --> (draft) (draft)
| 4/28 Homework 3 due Homework 4 released |
5/1 Graphs, DFS, BFS Read: Ch. 22 Additional Reading that might be helpful: (draft) (draft)
| 5/3 Strongly Connected Components Read: Ch. 22.5 (NOTE: this reading assignment was garbled before, it is fixed now!) (draft) (draft)
| 5/ Homework 4 due (NOTE the extension to Monday) |
5/8 Dijkstra's Algorithm Read: Ch. 24.1, 24.3 (draft) (draft)
| 5/10 MIDTERM In class (Hewlett 200, 3:00-4:20) | 5/12 Homework 5 released |
5/15 Dynamic Programming and shortest paths: Bellman-Ford, Floyd-Warshall Read: Ch. 25.2, 15.1 (draft) (draft)
| 5/17 Examples of dynamic programming: Longest common subsequence, Knapsack, Independent Set Read: Ch. 15.4 (draft) (draft)
| 5/19 Homework 5 due Homework 6 released |
5/22 Greedy Algorithms Read: Ch. 16.1,16.2,16.3 (draft) (draft)
| 5/24 Minimum Spanning Trees (MST) Read: Ch. 23 (draft) (draft)
| 5/26 Homework 6 due Homework 7 released |
5/29 Memorial Day (no class) | 5/31 Minimum Cut and Karger's algorithm (draft) Read: (draft)
| 6/2 Homework 7 due |
6/5 Maximum Flow and Ford-Fulkerson (draft). Read: Ch. 26.1-3 (draft)
| 6/7 Course recap; What's Next? | 6/9 FINAL EXAM |
Midterm and Final
Midterm: Wednesday, May 10, in class (Hewlett 200, 3:00 pm - 4:20 pm) - [ problems ] [ solutions ] Final: Friday, June 9, Hewlett 200, 3:30 pm - 6:30pm Final Problems and Solutions
Both the midterm and final are closed-book. In the midterm, you are allowed to bring one letter-sized double-sided page of notes, that you have prepared yourself . In the final, you are allowed to bring two letter-sized double-sided page of notes that you have prepared yourself .
The following practice exams are posted here as a resource; the material covered is similar to what we covered this quarter, but not identical.
Practice Midterm 1 Solutions to the Practice Midterm 1 Practice Midterm 2 Solutions to the Practice Midterm 2
Finals from Previous Years
The following final exams are taken from previous offerings of the class. They are posted here as a resource, but the material covered in them may differ what the material covered this quarter, and their structure may differ from this quarter's final exam.
Final Exam 2016 Final Exam 2016 Solutions
Homework Assignments
- Homework 1 (released 4/7, due 4/14 at 3pm). [ pdf ] [ raw LaTeX file ] [ solutions ]
- Homework 2 (released 4/14, due 4/21 at 3pm). [ pdf ] [ raw LaTeX file ] [ solutions ]
- Homework 3 (released 4/21, due 4/28 at 3pm). [ pdf ] [ raw LaTeX file ] [ solutions ]
- Homework 4 (released 4/28, due 5/8 at 3pm). [ pdf ] [ raw LaTeX file ] [ solutions ]
- Homework 5 (released 5/12, due 5/19 at 3pm). [ pdf ] [ raw LaTeX file ] [ solutions ]
- Homework 6 (released 5/19, due 5/26 at 3pm). [ pdf ] [ raw LaTeX file ] [ solutions ]
- Homework 7 (released 5/26, due 6/2 at 3pm). [ pdf ] [ raw LaTeX file ] [ solutions ]
- There is no Homework 8. However, if you want some practice on Minimum Cut and Maximum Flow, here are some practice problems (with solutions) from Kleinberg and Tardos: Solved exercise 1 here on randomized algorithms in graphs and Solved exercises 1 and 2 here on min-cut/max-flow .
- Homework 2 (released 10/7, due 10/14 at 3pm) Assignment Solutions
- Homework 3 (released 10/14, due 10/21 at 3pm) Assignment Solutions
- Homework 4 (released 10/21, due 10/28 at 3pm) Assignment Solutions
- Homework 5 (released 11/4, submission deadline extended - see Piazza) Assignment Solutions
- Homework 6 (released 11/12, due 11/19 at 11:59pm, late submission until 11/21 at 11:59pm) Assignment Solutions
- Homework 7 (released 11/19, due 12/2 at 3pm) Assignment Solutions
Submission Instructions and Policies
- All assignments are posted on Fridays, and are due the next Friday at 3pm.
- All assignments must be submitted electronically as a PDF file using Gradescope (access code: MWRJ89).
- All assignments should be typed using LaTeX, LyX, Microsoft Word, or a similar editor. For first time LaTeX users, see the resources section. Scanned handwritten assignments are not accepted.
- Each student is allowed to discuss the assignment (verbally) with any classmates enrolled in CS161. Each student should write and submit their own solution. Solutions must be written in your own words. When you submit the assignment, you should indicate with whom you have discussed the solutions.
- You are allowed to use textbooks and resources that are listed on this page. You may not google around hoping to find a similar problem worked out, but you may use other resources (like Wikipedia, other lecture notes, textbooks) that you find online. If you are using other resources, you must properly cite them, and you must prove any statement from them that you use.
- You are not allowed to look for the answers for any of the homework assignments (online or otherwise). If you accidentally find a solution for a question, do not read it (if it is not too late), and indicate that clearly on your assignment (including where you found the solution).
- Please follow the honor code .
- Late homeworks will not be accepted. However, we will consider your highest 6 (out of 7) homework grades when computing your final course grade.
- For each assignment, regrade requests will open on Gradescope on Wednesday (after the grades have been published) and close on Sunday.
- Please provide a detailed explanation for your regrade request.
- Note that we may regrade any part of the assignment, and the new grade may be greater than, equal to, or less than the original grade.
Recitations
- Section 1 : Loop and recursion invariants, weak and strong induction.
- Section 2 [ problems ] [ solutions ]: Selection, big-O, and recurrences.
- Section 3 : Randomized algorithms.
- Section 4 [ problems ] [ solutions ]: Universal hash functions, randomly built binary search trees.
- YouTube series on red-black trees: Introduction , Rotations , Insertions 1 , Insertions 2
- Section 5 : Midterm review.
- Section 6 [ problems ] [ solutions ]: Graphs.
- Section 7 : Dynamic programming.
- Section 8 [ problems ] [ solutions ]: Greedy algorithms.
- Recitation 1 (week 1) Solutions
- Recitation 2 (week 2) Solutions
- Recitation 4 (week 4) Solutions [Slides from David's Recitation]
- Recitation 5 (week 5) [Slides from David's Recitation]
- Recitation 6 (week of 3/7) Recitation Solutions
- Recitation 3 (10/14-10/19) Solutions
- Recitation 4 (10/21-10/26) Solutions
- Recitation 5 (11/4-11/9) Solutions
- Recitation 6 (11/11-11/16) Solutions
- Recitation 7 (11/18-11/30) Solutions
- Recitation 8 (12/2-12/7) Solutions
The main textbook we use is: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein, Introduction to Algorithms , 3rd Edition, MIT Press The book is available online through the Stanford library.
We will also occasionally use: Jon Kleinberg, Éva Tardos, Algorithm Design , Pearson/Addison-Wesley Sanjoy Dasgupta, Christos Papadimitriou, Umesh Vazirani, Algorithms , McGraw-Hill Education
Homework Resources
- Expected level of detail: Your homework solutions should make it clear that you understand what's going on. This means that they should have enough detail to convince the grader that your solution is correct; but they needn't have so much detail that it obfuscates the main points. This is a difficult balance to strike. To help you, here is an example of what we are looking for on the homework assignments.
- Read the submission instructions and policies above.
- Read the submission instructions and policies above. Seriously, do it.
- Look over the problems early. Algorithm design takes time, and even simple algorithms can be surprisingly tricky to develop. We suggest reading over all the problems as soon as the problem set goes out so that you will have the time to play around with them over the course of the week.
- Work on your own before working in a group or attending office hours. Although you are allowed to work in groups, we strongly recommend not doing so until you have already thought about each of the problems and tried out various solutions. The problem sets tend to have solutions that are not particularly complicated but which require some insight to discover. If you immediately start working on the problem sets in a group, you will miss out on the opportunity to come up with these insights on your own.
LaTeX Resources
We strongly recommend typesetting solutions to the homework assignments using LaTeX. LaTeX provides a convenient way to produce high-quality documents and it is the standard used for typesetting computer science papers.
Guide: An introduction to LaTeX can be found here . Other guides can be found at howtoTeX and!--> Wikibooks and NYU .
Online environments: If you do not wish to install LaTeX, ShareLaTeX and Overleaf are online environments that compile previews of your documents as you type and allow you to share documents with collaborators (this feature won't be useful in this course, though). As a Stanford student, you get a free Overleaf Pro account.
LyX: LyX is a version of LaTeX with graphical interface.
Finding mathematical symbols: The introduction mentioned above contains a table of mathematical symbols in LaTeX. Alternatively, consider Detexify .
Examples: homework1.tex homework2.tex homework3.tex homework4.tex homework5.tex homework6.tex homework7.tex --> LaTeX Homework Template: Here is an example of of a LaTeX document, including several elements (section numbering, pseudocode, tables, images, etc) that you might find helpful.
Provide details on what you need help with along with a budget and time limit. Questions are posted anonymously and can be made 100% private.
Studypool matches you to the best tutor to help you with your question. Our tutors are highly qualified and vetted.
Your matched tutor provides personalized help according to your question details. Payment is made only after you have completed your 1-on-1 session and are satisfied with your session.
- Homework Q&A
- Become a Tutor
All Subjects
Mathematics
Programming
Health & Medical
Engineering
Computer Science
Foreign Languages
Access over 35 million academic & study documents
Unit 6 algorithms homework 2 answers.
Sign up to view the full document!
24/7 Study Help
Stuck on a study question? Our verified tutors can answer all questions, from basic math to advanced rocket science !
Similar Documents
working on a study question?
Studypool is powered by Microtutoring TM
Copyright © 2024. Studypool Inc.
Studypool is not sponsored or endorsed by any college or university.
Ongoing Conversations
Access over 35 million study documents through the notebank
Get on-demand Q&A study help from verified tutors
Read 1000s of rich book guides covering popular titles
Sign up with Google
Sign up with Facebook
Already have an account? Login
Login with Google
Login with Facebook
Don't have an account? Sign Up
CS:3330:0001 (22C:31) Algorithms, Fall 2019
Instructor: | Hantao Zhang | | TA: Md Daniyal Dar |
Email: | | | |
Phone: | 319-353-2545 | |
Office: | 2-3:30, Tue., Wed., 201B MLH | | 1:30-3pm, Mon., 2:30-4pm, Thu., 101N MLH |
Syllabus , Announcements , Homeworks , Exams , Projects , Lecture Notes ,
Announcements
Computer projects, lecture notes, online resources.
- Java Tutorials
- Introduction to Java
- Eclipse Video Tutorials
- Eclipse Java Tutorials
- Cool animation of different sorting algorithms . Check out bubble sort vs quick sort.
Homework Two: Recursion, Searching, and Sorting Algorithms Solved
20.00 $
If Helpful Share:
Description
Exercise One (10pts) Design and implement and algorithm that compare two strings and check if they are reversed. For instance, if the two strings are google and elgoog, then the method returns 1. If the two strings are “data”, “ata” then the method returns 0. The algorithm should ignore white spaces, lower/upper cases.
Specify the running time of your algorithm in terms of Big-O notation. Attach Exercise One.doc that explains the running time.
- Exercise Two (10pts) Design and implement an algorithm that takes a set of strings. Then, for every three consecutive strings (assuming the list of strings is larger than 3 and the number of strings in your sentence is a multiple of 3) leave only the shortest of the three. In case two string among the three are of the same length then you leave the first one.
For instance, consider the following set of strings: “Other entries include a historic district in Charlottesville Virginia cut-flower greenhouse complex” à “Other a in complex”
Specify the running time of your algorithm in terms of Big-O notation. Attach Exercise Two.doc that explains the running time.
- Recursion (50pts)
- (10pts) Design and implement a binary recursive algorithm that finds the maximum number in array of size n.
- (20pts) Design and implement a recursive algorithm that returns the number of zeroes in the binary representation of N.
In this exercise the input to the algorithm must be an integer N. Your algorithm should not calculate the binary representation of N but recursively finds the number of zeroes in the binary representation of N. You are NOT allowed to use arrays.
- (20pts)Implement a recursive algorithm that checks if word is A palindrome.
A palindrom is a word or number that is identical when read both forwards and backwards. Please ignore all punctuation. Some simple palindromes include kayak radar dad
Sorting (60pts)
3.1. Provide your own implementation of the six algorithms mentioned bellow. You must provide your own code. Code copied form the internet or modified will be result into a Zero grade for the entire homework.
Provide a table (attached in a word document) where you compare the running time of the sorting algorithms mentioned bellow in terms of best case and worst case running time.
Bubble Sort Non-Recursive (5pts)
- Bubble Sort Recursive (5pts)
- Selection Sort (Non-recursive) (5pts)
- Insertion Sort (Non-recursive) (5pts)
- Merge Sort (Recursive) (5pts)
- Quick Sort (Recursive) (5pts)
3.2 Consider the array mentioned above, show a step by step illustration (either by hand or written in a word document) of applying the sorting algorithms mentioned to the array.
Include all your answers for this HW into a zip file.
Related products
Program #5 Solution
Solution Programming Problem Chapter 9-1 Pg. 447
Racket programming (part 2).
IMAGES
COMMENTS
Consider the search space depicted above for a hypothetical search problem. S is the initial state and T is the goal state. The cost of each edge has been labeled on the graph. A (4 points): Compute the shortest path and its cost using uniform cost search (Djikstra's algorithm). Solution: S - C - B - T, 14
NetId { Homework #2: Search Algorithms 3 6 points in the diagram below de ne a hypothetical TSP comprised of 6 cities, and shows one sample path that is a possible solution to this TSP. To solve such problems using hill climbing, states are an ordered list of cities specifying the order in which each city is visited.
Searching Algorithms. Searching algorithms are essential tools in computer science used to locate specific items within a collection of data. These algorithms are designed to efficiently navigate through data structures to find the desired information, making them fundamental in various applications such as databases, web search engines, and more.
In general, exponential-complexity search problems cannot be solved by uninformed search for any but the smallest instances. 3.4.2 Dijkstra's algorithm or uniform-cost search When actions have different costs, an obvious choice is to use best-first search where the evaluation function is the cost of the path from the root to the current node.
1. Linear Search: Linear Search, also known as Sequential Search, is one of the simplest and most straightforward searching algorithms. It works by sequentially examining each element in a collection of data (array or list) until a match is found or the entire collection has been traversed. Linear Search.
ALG 2.2 Search Algorithms. Binary Search: average case. Binary Search with Errors (homework) Interpolation Search. Unbounded Search. Main Reading Selections: CLR, Chapter 13 Auxillary Reading Selections: AHU-Design, 4.1 and 4.5 AHU-Data, Sections 5.1 and 5.1 BB, Sections 4.3 and 8.4.3 Handout: Algorithm Searching" "An Almost Optimal for Unbounded.
Linear or Sequential Search. This algorithm works by sequentially iterating through the whole array or list from one end until the target element is found. If the element is found, it returns its index, else -1. Now let's look at an example and try to understand how it works: arr = [2, 12, 15, 11, 7, 19, 45] Suppose the target element we want ...
Lesson 2 Searching algorithms; Lesson 3 Sorting algorithms; Lesson 4 Developing algorithms using flowcharts; Lesson 5 Developing algorithms using ... There are 6 worksheets, 5 homework tasks, and an assessment test, each with answers included in this unit. How to order. 1. Add individual units to a draft order or download a blank order form ...
7.5.1. Sequential Search ¶. Sequential or linear search can be used to find a value in unsorted data. It usually starts at the first element and walks through the array or list until it finds the value it is looking for and returns its index. If it reaches the end of the array or list without finding the value, the search method usually ...
3. (4 points.) Alice and Bob play the following number search game. N is fixed to be some large number. Alice picks an integer y in the range [1 N]. Bob's goal is to guess this number as quickly as possible through a series of questions. At step t Bob poses a question x t, also an integer in the range [1 N]. For t 2, Alice
The section will dedicate itself to introducing the sequential and binary types of search. 22.2: Activity 2 - Sorting Algorithm This activity involves studying the sorting process and how to write algorithms that can order particular items in a list to be in given order. The activity of sorting ensures items in a given list are arranged in a ...
CSCI-261, Spring 2020, Homework 2 due Feb 27, 11:59 PM Material Covered. Search Sorting Binary Search Trees and AVL Trees Divide and Conquer. Submission: For questions 1 to 4, as well as the pseudocode and proof of time complexity in question 5, submit ONE single PDF file named a2 to myCourse.
Initialize i to 1. While i is less than the length of the collection and the element at index i is less than or equal to the element we are searching for, set i to i * 2. Do a binary search on the range from i / 2 to Math.min(i, n - 1), where n is the length of the collection. If the element is found, return its index.
Write a program to implement two searching algorithms. (1) a linear search algorithm and (2) a binary search algorithm. If the algorithm finds the searched key value, print out how many comparisons this algorithm made before finding the correct key in the array. The output messages should be as follows. cout<<"The value of"<<key<< "was found!
Algorithms part 2 - Searching and sorting. Curriculum > KS4 > Unit. The main focus of this unit is on searching and sorting algorithms, though other topics are covered such as computational thinking, flowcharts and tracing algorithms. Students will have opportunities to analyse, interpret, modify and implement a range of algorithms.
Course Description This course will cover the basic approaches and mindsets for analyzing and designing algorithms and data structures. Topics include the following: Worst and average case analysis. Recurrences and asymptotics. Efficient algorithms for sorting, searching, and selection. Data structures: binary search trees, heaps, hash tables.
Homework 2 Searching algorithms Unit 6 Algorithms Answers 1. A list contains the following items: Antelope Baboon Cheetah Emu Giraffe Hippo Jackal Lion Okapi Warthog (a) A binary search is performed to find the item Okapi. State the items which will be examined. [3] Giraffe, Lion, Okapi ... User generated content is uploaded by users for the ...
Homework 2 is due on 9/12/19 (30 points) (p. 47) C-1.24, C-1.29; ... (show the content of max-heap after each removeMax operation), R-5.11, C-5.1, C-5.2, C-5.6, C-5.9 (one algorithm for min-heap and one for max-heap). Homework 6 is due on 10/24/19 (30 points) (p.236-237) R-7.3, R-7.7, C-7.6, C-7.8. ... Balanced Search Trees PDF; Chapter 5 ...
Arrays (20pts) Exercise One (10pts) Design and implement and algorithm that compare two strings and check if they are reversed. For instance, if the two strings are google and elgoog, then the method returns 1. If the two strings are "data", "ata" then the method returns 0. The algorithm should ignore white spaces, lower/upper […]
Computer Science questions and answers. ObjectivesAssignment 2 - Searching and Sorting Algorithms Total Marks: 20• Investigate sorting and searching algorithms and watch them work.•. Learn how to use Palgo, an app that Paints ALGOrithmically.Software NeededThe following included software is needed to complete this assignment:a) Palgo app.