Skip to primary content
Skip to secondary content

Knowledge Database

Knowledge Database

Main menu

  • Home
  • Coding Questions
    • Cracking the Coding Interview
    • CodeEval
    • LeetCode
    • UVa (ACM)
  • Online Courses
    • ALPHA Camp
      • 不只是刷題的 Leetcode 訓練營
    • Coursera
    • Udemy
      • Web Development
      • Programming Languages
    • Udacity
  • Project
    • Course Projects
    • Other Projects
  • About

Category Archives: Chapter 11. Sorting and Searching

Sorting – Quick Sort

Posted on August 8, 2013 by Carlos
Reply

Time complexity:

Worst-case: \(O(n^2)\)

Best-case: \(O(nlog(n))\)

Average-case: \(O(nlog(n))\)

Pick a random element (pivot) and partition the array.
[all numbers that are less than the pivot] pivot [all numbers that are greater than the pivot]

 

Continue reading →

Posted in Chapter 11. Sorting and Searching, Data Structures and Algorithms | Leave a reply

Sorting – Merge Sort

Posted on August 7, 2013 by Carlos
Reply

Time complexity:

Worst-case: \(O(nlog(n))\)

Best-case: \(O(nlog(n))\)

Average-case: \(O(nlog(n))\)

Merge sort divides the array in half, sorts each of those halves, and them merges them back together.

 

Continue reading →

Posted in Chapter 11. Sorting and Searching, Data Structures and Algorithms | Leave a reply

Sorting – Selection Sort

Posted on August 7, 2013 by Carlos
Reply

Time complexity:

Worst-case: \(O(n^2)\)

Best-case: \(O(n^2)\)

Average-case: \(O(n^2)\)

Find the smallest element and move it to the front. Then, find the second smallest and move it.

Continue reading →

Posted in Chapter 11. Sorting and Searching, Data Structures and Algorithms | Leave a reply

Sorting – Bubble Sort

Posted on August 7, 2013 by Carlos
Reply

Time complexity:

Worst-case: \(O(n^2)\)

Best-case: \(O(n)\)

Average-case: \(O(n^2)\)

Sort array elements in ascending order. If the first element is greater than the second element, swap the first two elements.

Then, we go to the “next pair” and so on.

Continue reading →

Posted in Chapter 11. Sorting and Searching, Data Structures and Algorithms | Leave a reply

Recent Posts

  • Change the order of Prism’s supported languages
  • [Android Study Jam] Unit 2: Kotlin basics for Android (Notes)
  • 704. Binary Search
  • 167. Two Sum II – Input array is sorted
  • 66. Plus One

Recent Comments

  • cywang on CTCI: Ch. 1-4
  • cywang on CTCI: Ch. 1-4
  • cywang on CTCI: Ch. 1-4
  • cywang on CTCI: Ch. 1-1

Archives

  • May 2021
  • April 2021
  • May 2020
  • October 2018
  • June 2018
  • May 2018
  • April 2015
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • December 2012
  • September 2012
  • June 2012
  • May 2012
  • March 2011
  • December 2010
  • September 2010
  • May 2010
  • March 2010
  • June 2008
  • January 2008
  • April 2000

Categories

  • 8051
  • Android Development
  • Android Study Jam
  • C/C++
  • C#
  • Chapter 1. Arrays and Strings
  • Chapter 11. Sorting and Searching
  • Chapter 2. Linked Lists
  • Chapter 5. Bit Manipulation
  • Cracking the Coding Interview
  • Data Structures and Algorithms
  • iOS Development
  • Leetcode
  • Linux
  • Ojbective-C & Xcode
  • Programming
  • Projects
  • Raspberry Pi
  • Ruby on Rails
  • Smart Home
  • Uncategorized

Recent Comments

  • cywang on CTCI: Ch. 1-4
  • cywang on CTCI: Ch. 1-4
  • cywang on CTCI: Ch. 1-4
  • cywang on CTCI: Ch. 1-1

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

My Link

  • cywang's homepage
  • LinkedIn
Proudly powered by WordPress