Having presented the general framework for describing and analyzing algorithms,
we now present a case study in algorithm analysis to make this discussion more
concrete. Specifically, we show how to use the big-Oh notation to analyze three
algorithms that solve the same problem but have different running times.
The problem we focus on is one that is reportedly often used as a job interview
question by major software and Internet companies—the maximum subarray
problem. In this problem, we are given an array of positive and negative integers
and asked to find the subarray whose elements have the largest sum. That is, given
A = [a1, a2, . . . , an],
find the indices j and k that maximize the sum
sj,k = aj + aj+1 + · · · + ak =
Xk
i=j
ai.
Or, to put it another way, if we use A[j : k] to denote the subarray of A from index j
to index k, then the maximum subarray problem is to find the subarray A[j : k] that
maximizes the sum of its values. In addition to being considered a good problem
for testing the thinking skills of prospective employees, the maximum subarray
problem also has applications in pattern analysis in digitized images. An example
of this problem is shown in Figure 1.13.
Figure
มีการเสนอกรอบทั่วไปสำหรับการอธิบายและวิเคราะห์ขั้นตอนวิธีตอนนี้เรานำเสนอกรณีศึกษาในการวิเคราะห์ขั้นตอนวิธีที่จะทำให้การสนทนานี้มากขึ้นคอนกรีต โดยเฉพาะ เราแสดงวิธีการใช้สัญกรณ์วิเคราะห์สามบิ๊กโอขั้นตอนวิธีแก้ปัญหาเหมือนกันแต่เวลาวิ่งที่แตกต่างกันปัญหาที่เราเน้นเป็นหนึ่งที่เป็นข่าวบ่อยที่การสัมภาษณ์งานคำถามโดยสาขาซอฟต์แวร์และอินเทอร์เน็ต บริษัท subarray สูงสุดปัญหา ในปัญหานี้เราจะได้รับอาเรย์ของจํานวนเต็มบวกและลบและขอให้หา subarray ที่มีองค์ประกอบได้ผลรวมที่ใหญ่ที่สุด นั่นคือให้= [ A1 , A2 , . . . . . . . . , ] ,ค้นหาดัชนี J และ K ที่เพิ่มผลรวมเอสเจ , K = AJ + AJ + 1 + · · · = + และXKผม = เจAiหรือ ใส่ไว้อีกวิธี ถ้าเราใช้ [ J : k ] ไปจนถึง subarray ของดัชนี J จากดัชนี K แล้ว ปัญหา subarray สูงสุดคือหา subarray [ J : k ] ที่เพิ่มผลรวมของค่าของมัน นอกจากจะได้รับการพิจารณาเป็นปัญหาที่ดีเพื่อทดสอบทักษะการคิดของพนักงานในอนาคต , subarray สูงสุดปัญหายังมีการใช้งานในรูปแบบดิจิทัล การวิเคราะห์ภาพ ตัวอย่างปัญหานี้จะแสดงในรูปที่ 1.13 .รูป
การแปล กรุณารอสักครู่..
